From da46bdda1f21431a563c2e5e4a451940b040f764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Mon, 11 Mar 2019 22:57:06 +0100 Subject: [PATCH] Remove delay parsing from Gajim Use nbxmpp's delay parsing --- gajim/common/modules/chatstates.py | 3 +- gajim/common/modules/misc.py | 44 ------------------------------ test/no_gui/unit/test_helpers.py | 30 -------------------- 3 files changed, 1 insertion(+), 76 deletions(-) delete mode 100644 test/no_gui/unit/test_helpers.py diff --git a/gajim/common/modules/chatstates.py b/gajim/common/modules/chatstates.py index 1c3366e4b..561bd51b3 100644 --- a/gajim/common/modules/chatstates.py +++ b/gajim/common/modules/chatstates.py @@ -30,7 +30,6 @@ from gi.repository import GLib from gajim.common import app from gajim.common.nec import NetworkEvent from gajim.common.const import Chatstate as State -from gajim.common.modules.misc import parse_delay from gajim.common.modules.base import BaseModule from gajim.common.connection_handlers_events import MessageOutgoingEvent from gajim.common.connection_handlers_events import GcMessageOutgoingEvent @@ -53,7 +52,7 @@ def ensure_enabled(func): def parse_chatstate(stanza: nbxmpp.Message) -> Optional[str]: - if parse_delay(stanza) is not None: + if stanza.getTag('delay', namespace=nbxmpp.NS_DELAY2) is not None: return None children = stanza.getChildren() diff --git a/gajim/common/modules/misc.py b/gajim/common/modules/misc.py index c70cf7ed7..9c4c70109 100644 --- a/gajim/common/modules/misc.py +++ b/gajim/common/modules/misc.py @@ -19,54 +19,10 @@ import logging import nbxmpp from gajim.common import app -from gajim.common.modules.date_and_time import parse_datetime log = logging.getLogger('gajim.c.m.misc') -# XEP-0203: Delayed Delivery - -def parse_delay(stanza, epoch=True, convert='utc', from_=None, not_from=None): - ''' - Returns the first valid delay timestamp that matches - - :param epoch: Returns the timestamp as epoch - - :param convert: Converts the timestamp to either utc or local - - :param from_: Matches only delays that have the according - from attr set - - :param not_from: Matches only delays that have the according - from attr not set - ''' - delays = stanza.getTags('delay', namespace=nbxmpp.NS_DELAY2) - - for delay in delays: - stamp = delay.getAttr('stamp') - if stamp is None: - log.warning('Invalid timestamp received: %s', stamp) - log.warning(stanza) - continue - - delay_from = delay.getAttr('from') - if from_ is not None: - if delay_from != from_: - continue - if not_from is not None: - if delay_from in not_from: - continue - - timestamp = parse_datetime(stamp, check_utc=True, - epoch=epoch, convert=convert) - if timestamp is None: - log.warning('Invalid timestamp received: %s', stamp) - log.warning(stanza) - continue - - return timestamp - - # XEP-0066: Out of Band Data def parse_oob(event): diff --git a/test/no_gui/unit/test_helpers.py b/test/no_gui/unit/test_helpers.py deleted file mode 100644 index fa90fd8ae..000000000 --- a/test/no_gui/unit/test_helpers.py +++ /dev/null @@ -1,30 +0,0 @@ -import unittest - -import nbxmpp - -from gajim.common.modules.misc import parse_delay - -class TestHelpers(unittest.TestCase): - - def test_parse_delay(self): - - node = """ - - - - - - """ - message = nbxmpp.Node(node=node) - - timestamp = parse_delay(message) - self.assertEqual(timestamp, 1031699305.0) - - timestamp = parse_delay(message, from_='capulet.com') - self.assertEqual(timestamp, 1031699305.0) - - timestamp = parse_delay(message, from_='romeo.com') - self.assertEqual(timestamp, 1284160105.0) - - timestamp = parse_delay(message, not_from=['romeo.com']) - self.assertEqual(timestamp, 1031699305.0) \ No newline at end of file