handle XEP-0203 (Delayed Delivery) and use it when forwarding unread messages via adhoc commands. Fixes #4347

This commit is contained in:
Yann Leboulanger 2008-09-26 11:11:38 +00:00
parent 941b7cf974
commit e236382f3d
4 changed files with 30 additions and 5 deletions

View File

@ -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')

View File

@ -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,

View File

@ -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)

View File

@ -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')<self.getTimestamp(): self.setTimestamp(x.getAttr('stamp'))
if d.getAttr('stamp')<self.getTimestamp2(): self.setTimestamp(d.getAttr('stamp'))
except: pass
if not self.timestamp:
for x in self.getTags('x',namespace=NS_DELAY):
try:
if x.getAttr('stamp')<self.getTimestamp(): self.setTimestamp(x.getAttr('stamp'))
except: pass
if timestamp is not None: self.setTimestamp(timestamp) # To auto-timestamp stanza just pass timestamp=''
def getTo(self):
""" Return value of the 'to' attribute. """
@ -339,6 +345,10 @@ class Protocol(Node):
""" Return the timestamp in the 'yyyymmddThhmmss' format. """
if self.timestamp: return self.timestamp
return time.strftime('%Y%m%dT%H:%M:%S', time.gmtime())
def getTimestamp2(self):
""" Return the timestamp in the 'yyyymmddThhmmss' format. """
if self.timestamp: return self.timestamp
return time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
def getID(self):
""" Return the value of the 'id' attribute. """
return self.getAttr('id')