handle XEP-0203 (Delayed Delivery) and use it when forwarding unread messages via adhoc commands. Fixes #4347
This commit is contained in:
parent
941b7cf974
commit
e236382f3d
4 changed files with 30 additions and 5 deletions
|
@ -266,7 +266,7 @@ class ForwardMessagesCommand(AdHocCommand):
|
||||||
for event in events[jid]:
|
for event in events[jid]:
|
||||||
self.connection.send_message(j, event.parameters[0], '',
|
self.connection.send_message(j, event.parameters[0], '',
|
||||||
type=event.type_, subject=event.parameters[1],
|
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
|
# Inform other client of completion
|
||||||
response, cmd = self.buildResponse(request, status = 'completed')
|
response, cmd = self.buildResponse(request, status = 'completed')
|
||||||
|
|
|
@ -1073,7 +1073,8 @@ class Connection(ConnectionHandlers):
|
||||||
|
|
||||||
def send_message(self, jid, msg, keyID, type='chat', subject='',
|
def send_message(self, jid, msg, keyID, type='chat', subject='',
|
||||||
chatstate=None, msg_id=None, composing_xep=None, resource=None,
|
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:
|
if not self.connection:
|
||||||
return 1
|
return 1
|
||||||
if msg and not xhtml and gajim.config.get('rst_formatting_outgoing_messages'):
|
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',
|
addresses.addChild('address', attrs = {'type': 'ofrom',
|
||||||
'jid': forward_from})
|
'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
|
# XEP-0184
|
||||||
if msgtxt and gajim.config.get_per('accounts', self.name,
|
if msgtxt and gajim.config.get_per('accounts', self.name,
|
||||||
'request_receipt') and gajim.capscache.is_supported(contact,
|
'request_receipt') and gajim.capscache.is_supported(contact,
|
||||||
|
|
|
@ -1956,6 +1956,12 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
|
||||||
user_nick = ''
|
user_nick = ''
|
||||||
contact_nickname = None
|
contact_nickname = None
|
||||||
transport_auto_auth = False
|
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')
|
xtags = prs.getTags('x')
|
||||||
for x in xtags:
|
for x in xtags:
|
||||||
namespace = x.getNamespace()
|
namespace = x.getNamespace()
|
||||||
|
@ -1968,7 +1974,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
|
||||||
elif namespace == common.xmpp.NS_VCARD_UPDATE:
|
elif namespace == common.xmpp.NS_VCARD_UPDATE:
|
||||||
avatar_sha = x.getTagData('photo')
|
avatar_sha = x.getTagData('photo')
|
||||||
contact_nickname = x.getTagData('nickname')
|
contact_nickname = x.getTagData('nickname')
|
||||||
elif namespace == common.xmpp.NS_DELAY:
|
elif namespace == common.xmpp.NS_DELAY and not timestamp:
|
||||||
# XEP-0091
|
# XEP-0091
|
||||||
tim = prs.getTimestamp()
|
tim = prs.getTimestamp()
|
||||||
tim = helpers.datetime_tuple(tim)
|
tim = helpers.datetime_tuple(tim)
|
||||||
|
|
|
@ -43,6 +43,7 @@ NS_COMPRESS ='http://jabber.org/protocol/compress' # XEP-01
|
||||||
NS_CONFERENCE ='jabber:x:conference'
|
NS_CONFERENCE ='jabber:x:conference'
|
||||||
NS_DATA ='jabber:x:data' # XEP-0004
|
NS_DATA ='jabber:x:data' # XEP-0004
|
||||||
NS_DELAY ='jabber:x:delay'
|
NS_DELAY ='jabber:x:delay'
|
||||||
|
NS_DELAY2 ='urn:xmpp:delay'
|
||||||
NS_DIALBACK ='jabber:server:dialback'
|
NS_DIALBACK ='jabber:server:dialback'
|
||||||
NS_DISCO ='http://jabber.org/protocol/disco'
|
NS_DISCO ='http://jabber.org/protocol/disco'
|
||||||
NS_DISCO_INFO =NS_DISCO+'#info'
|
NS_DISCO_INFO =NS_DISCO+'#info'
|
||||||
|
@ -322,6 +323,11 @@ class Protocol(Node):
|
||||||
if self['from']: self.setFrom(self['from'])
|
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']
|
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
|
self.timestamp=None
|
||||||
|
for d in self.getTags('delay',namespace=NS_DELAY2):
|
||||||
|
try:
|
||||||
|
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):
|
for x in self.getTags('x',namespace=NS_DELAY):
|
||||||
try:
|
try:
|
||||||
if x.getAttr('stamp')<self.getTimestamp(): self.setTimestamp(x.getAttr('stamp'))
|
if x.getAttr('stamp')<self.getTimestamp(): self.setTimestamp(x.getAttr('stamp'))
|
||||||
|
@ -339,6 +345,10 @@ class Protocol(Node):
|
||||||
""" Return the timestamp in the 'yyyymmddThhmmss' format. """
|
""" Return the timestamp in the 'yyyymmddThhmmss' format. """
|
||||||
if self.timestamp: return self.timestamp
|
if self.timestamp: return self.timestamp
|
||||||
return time.strftime('%Y%m%dT%H:%M:%S', time.gmtime())
|
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):
|
def getID(self):
|
||||||
""" Return the value of the 'id' attribute. """
|
""" Return the value of the 'id' attribute. """
|
||||||
return self.getAttr('id')
|
return self.getAttr('id')
|
||||||
|
|
Loading…
Add table
Reference in a new issue