Mercurial > libervia-backend
diff src/plugins/plugin_xep_0203.py @ 1743:4c48468ead4c
plugin XEP-0203, core (xmpp): leave the management of delay element to XEP-0203 (fix bug 59):
- this patch reveals a bug in primitivus Chat.printMessage relative to MUC history (the test to discard duplicates is wrong)
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 11 Dec 2015 11:25:29 +0100 |
parents | 069ad98b360d |
children | d17772b0fe22 |
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0203.py Tue Dec 15 13:30:47 2015 +0100 +++ b/src/plugins/plugin_xep_0203.py Fri Dec 11 11:25:29 2015 +0100 @@ -22,6 +22,7 @@ from sat.core.log import getLogger log = getLogger(__name__) +from calendar import timegm from wokkel import disco, iwokkel, delay try: from twisted.words.protocols.xmlstream import XMPPHandler @@ -48,6 +49,8 @@ def __init__(self, host): log.info(_("Delayed Delivery plugin initialization")) self.host = host + host.trigger.add("MessageReceived", self.messageReceivedTrigger) + def getHandler(self, profile): return XEP_0203_handler(self, profile) @@ -68,6 +71,30 @@ parent.addChild(elt) return elt + def messagePostTreat(self, data, timestamp): + """Set the timestamp of a received message. + + @param data (dict): data send by MessageReceived trigger through post_treat deferred + @param timestamp (int): original timestamp of a delayed message + @return: dict + """ + data['extra']['timestamp'] = unicode(timestamp) + return data + + def messageReceivedTrigger(self, message, post_treat, profile): + """Process a delay element from incoming message. + + @param message (domish.Element): message element + @param post_treat (Deferred): deferred instance to add post treatments + """ + try: + delay_ = delay.Delay.fromElement([elm for elm in message.elements() if elm.name == 'delay'][0]) + except IndexError: + return True + else: + timestamp = timegm(delay_.stamp.utctimetuple()) + post_treat.addCallback(self.messagePostTreat, timestamp) + return True class XEP_0203_handler(XMPPHandler): implements(iwokkel.IDisco)