From e236382f3dc99bb6115c46f548220c6b4be39309 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Fri, 26 Sep 2008 11:11:38 +0000 Subject: [PATCH] handle XEP-0203 (Delayed Delivery) and use it when forwarding unread messages via adhoc commands. Fixes #4347 --- src/common/commands.py | 2 +- src/common/connection.py | 11 ++++++++++- src/common/connection_handlers.py | 8 +++++++- src/common/xmpp/protocol.py | 14 ++++++++++++-- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/common/commands.py b/src/common/commands.py index 73dbd5b72..1269f4963 100644 --- a/src/common/commands.py +++ b/src/common/commands.py @@ -266,7 +266,7 @@ class ForwardMessagesCommand(AdHocCommand): for event in events[jid]: self.connection.send_message(j, event.parameters[0], '', type=event.type_, subject=event.parameters[1], - resource=resource, forward_from=jid) + resource=resource, forward_from=jid, delayed=event.time_) # Inform other client of completion response, cmd = self.buildResponse(request, status = 'completed') diff --git a/src/common/connection.py b/src/common/connection.py index 2fa9c4c01..eae94c2f9 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -1073,7 +1073,8 @@ class Connection(ConnectionHandlers): def send_message(self, jid, msg, keyID, type='chat', subject='', chatstate=None, msg_id=None, composing_xep=None, resource=None, - user_nick=None, xhtml=None, session=None, forward_from=None, form_node=None, original_message=None): + user_nick=None, xhtml=None, session=None, forward_from=None, form_node=None, + original_message=None, delayed=None): if not self.connection: return 1 if msg and not xhtml and gajim.config.get('rst_formatting_outgoing_messages'): @@ -1174,6 +1175,14 @@ class Connection(ConnectionHandlers): addresses.addChild('address', attrs = {'type': 'ofrom', 'jid': forward_from}) + # XEP-0203 + if delayed: + our_jid = gajim.get_jid_from_account(self.name) + '/' + \ + self.server_resource + timestamp = time.strftime('%Y-%m-%dT%TZ', time.gmtime(delayed)) + msg_iq.addChild('delay', namespace=common.xmpp.NS_DELAY2, + attrs={'from': our_jid, 'stamp': timestamp}) + # XEP-0184 if msgtxt and gajim.config.get_per('accounts', self.name, 'request_receipt') and gajim.capscache.is_supported(contact, diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 279e598d1..68f3927ea 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -1956,6 +1956,12 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, user_nick = '' contact_nickname = None transport_auto_auth = False + # XEP-0203 + delay_tag = prs.getTag('delay', namespace=common.xmpp.NS_DELAY2) + if delay_tag: + tim = prs.getTimestamp2() + tim = helpers.datetime_tuple(tim) + timestamp = localtime(timegm(tim)) xtags = prs.getTags('x') for x in xtags: namespace = x.getNamespace() @@ -1968,7 +1974,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, elif namespace == common.xmpp.NS_VCARD_UPDATE: avatar_sha = x.getTagData('photo') contact_nickname = x.getTagData('nickname') - elif namespace == common.xmpp.NS_DELAY: + elif namespace == common.xmpp.NS_DELAY and not timestamp: # XEP-0091 tim = prs.getTimestamp() tim = helpers.datetime_tuple(tim) diff --git a/src/common/xmpp/protocol.py b/src/common/xmpp/protocol.py index 083d8f485..720781f68 100644 --- a/src/common/xmpp/protocol.py +++ b/src/common/xmpp/protocol.py @@ -43,6 +43,7 @@ NS_COMPRESS ='http://jabber.org/protocol/compress' # XEP-01 NS_CONFERENCE ='jabber:x:conference' NS_DATA ='jabber:x:data' # XEP-0004 NS_DELAY ='jabber:x:delay' +NS_DELAY2 ='urn:xmpp:delay' NS_DIALBACK ='jabber:server:dialback' NS_DISCO ='http://jabber.org/protocol/disco' NS_DISCO_INFO =NS_DISCO+'#info' @@ -322,10 +323,15 @@ class Protocol(Node): if self['from']: self.setFrom(self['from']) if node and type(self)==type(node) and self.__class__==node.__class__ and self.attrs.has_key('id'): del self.attrs['id'] self.timestamp=None - for x in self.getTags('x',namespace=NS_DELAY): + for d in self.getTags('delay',namespace=NS_DELAY2): try: - if x.getAttr('stamp')