Remove delay parsing from Gajim
Use nbxmpp's delay parsing
This commit is contained in:
parent
f5fe4fd8de
commit
da46bdda1f
3 changed files with 1 additions and 76 deletions
|
@ -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()
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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>
|
||||
<delay xmlns='urn:xmpp:delay' from='capulet.com' stamp='2002-09-10T23:08:25Z' />
|
||||
<delay xmlns='urn:xmpp:delay' from='romeo.com' stamp='2010-09-10T23:08:25Z' />
|
||||
<delay xmlns='urn:xmpp:delay' stamp='2015-09-10T23:08:25Z' />
|
||||
</message>
|
||||
"""
|
||||
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)
|
Loading…
Add table
Reference in a new issue