Mercurial > libervia-backend
changeset 513:8ee9113d307b
core, quick_frontend, primitivus, wixi, bridge: fixed delayed message timestamp:
- new "extra" parameter in newMessage signal
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 20 Oct 2012 17:23:56 +0200 (2012-10-20) |
parents | 862c0d6ab974 |
children | fe79a724e6fa |
files | frontends/src/primitivus/primitivus frontends/src/quick_frontend/quick_app.py frontends/src/quick_frontend/quick_chat.py frontends/src/wix/main_window.py src/bridge/DBus.py src/bridge/bridge_constructor/bridge_template.ini src/core/sat_main.py src/core/xmpp.py |
diffstat | 8 files changed, 39 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/primitivus/primitivus Wed Oct 17 00:35:48 2012 +0200 +++ b/frontends/src/primitivus/primitivus Sat Oct 20 17:23:56 2012 +0200 @@ -303,8 +303,8 @@ self.notify(_("Error while sending message")) editBar.set_edit_text('') - def newMessage(self, from_jid, to_jid, msg, _type, profile): - QuickApp.newMessage(self, from_jid, to_jid, msg, _type, profile) + def newMessage(self, from_jid, to_jid, msg, _type, extra, profile): + QuickApp.newMessage(self, from_jid, to_jid, msg, _type, extra, profile) if not from_jid in self.contact_list and from_jid.short != self.profiles[profile]['whoami'].short: #XXX: needed to show entities which haven't sent any
--- a/frontends/src/quick_frontend/quick_app.py Wed Oct 17 00:35:48 2012 +0200 +++ b/frontends/src/quick_frontend/quick_app.py Sat Oct 20 17:23:56 2012 +0200 @@ -235,7 +235,7 @@ _groups = list(groups) self.contact_list.replace(entity, _groups, attributes) - def _newMessage(self, from_jid_s, msg, _type, to_jid_s, profile): + def _newMessage(self, from_jid_s, msg, _type, to_jid_s, extra, profile): """newMessage premanagement: a dirty hack to manage private messages if a private MUC message is detected, from_jid or to_jid is prefixed and resource is escaped""" if not self.check_profile(profile): @@ -259,16 +259,17 @@ if new_jid not in self.contact_list: self.contact_list.add(new_jid) - self.newMessage(from_jid, to_jid, msg, _type, profile) + self.newMessage(from_jid, to_jid, msg, _type, extra, profile) - def newMessage(self, from_jid, to_jid, msg, _type, profile): + def newMessage(self, from_jid, to_jid, msg, _type, extra, profile): from_me = from_jid.short == self.profiles[profile]['whoami'].short win = to_jid if from_me else from_jid self.current_action_ids = set() self.current_action_ids_cb = {} - self.chat_wins[win.short].printMessage(from_jid, msg, profile) + timestamp = extra.get('archive') + self.chat_wins[win.short].printMessage(from_jid, msg, profile, float(timestamp) if timestamp else '') def sendMessage(self, to_jid, message, subject='', mess_type="auto", profile_key="@DEFAULT@"): if to_jid.startswith(const_PRIVATE_PREFIX):
--- a/frontends/src/quick_frontend/quick_chat.py Wed Oct 17 00:35:48 2012 +0200 +++ b/frontends/src/quick_frontend/quick_chat.py Sat Oct 20 17:23:56 2012 +0200 @@ -124,7 +124,7 @@ return unescaped.resource return jid.resource if self.type == "group" else (self.host.contact_list.getCache(jid,'nick') or self.host.contact_list.getCache(jid,'name') or jid.node) - def printMessage(self, from_jid, msg, profile, timestamp): + def printMessage(self, from_jid, msg, profile, timestamp = ''): """Print message in chat window. Must be implemented by child class""" jid=JID(from_jid) nick = self._get_nick(jid)
--- a/frontends/src/wix/main_window.py Wed Oct 17 00:35:48 2012 +0200 +++ b/frontends/src/wix/main_window.py Sat Oct 20 17:23:56 2012 +0200 @@ -180,8 +180,8 @@ wx.EVT_MENU(self, idFIND_GATEWAYS, self.onFindGateways) - def newMessage(self, from_jid, to_jid, msg, _type, profile): - QuickApp.newMessage(self, from_jid, to_jid, msg, _type, profile) + def newMessage(self, from_jid, to_jid, msg, _type, extra, profile): + QuickApp.newMessage(self, from_jid, to_jid, msg, _type, extra, profile) def showAlert(self, message): # TODO: place this in a separate class
--- a/src/bridge/DBus.py Wed Oct 17 00:35:48 2012 +0200 +++ b/src/bridge/DBus.py Sat Oct 20 17:23:56 2012 +0200 @@ -155,8 +155,8 @@ pass @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX, - signature='sssss') - def newMessage(self, from_jid, message, mess_type, to_jid, profile): + signature='ssssa{ss}s') + def newMessage(self, from_jid, message, mess_type, to_jid, extra, profile): pass @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX, @@ -533,8 +533,8 @@ def newContact(self, contact_jid, attributes, groups, profile): self.dbus_bridge.newContact(contact_jid, attributes, groups, profile) - def newMessage(self, from_jid, message, mess_type, to_jid, profile): - self.dbus_bridge.newMessage(from_jid, message, mess_type, to_jid, profile) + def newMessage(self, from_jid, message, mess_type, to_jid, extra, profile): + self.dbus_bridge.newMessage(from_jid, message, mess_type, to_jid, extra, profile) def paramUpdate(self, name, value, category, profile): self.dbus_bridge.paramUpdate(name, value, category, profile)
--- a/src/bridge/bridge_constructor/bridge_template.ini Wed Oct 17 00:35:48 2012 +0200 +++ b/src/bridge/bridge_constructor/bridge_template.ini Sat Oct 20 17:23:56 2012 +0200 @@ -44,13 +44,14 @@ [newMessage] type=signal category=core -sig_in=sssss +sig_in=ssssa{ss}s doc=A message has been received doc_param_0=from_jid: JID where the message is comming from doc_param_1=message: Message itself doc_param_2=mess_type: Type of the message (cf RFC 3921 #2.1.1) doc_param_3=to_jid: JID where the message must be sent -doc_param_4=%(doc_profile)s +doc_param_4=extra: extra message information +doc_param_5=%(doc_profile)s [newAlert] type=signal
--- a/src/core/sat_main.py Wed Oct 17 00:35:48 2012 +0200 +++ b/src/core/sat_main.py Sat Oct 20 17:23:56 2012 +0200 @@ -501,7 +501,7 @@ if mess_data["type"]!="groupchat": self.memory.addToHistory(current_jid, jid.JID(to), unicode(mess_data["message"]), unicode(mess_data["type"]), profile=profile) #we don't add groupchat message to history, as we get them back #and they will be added then - self.bridge.newMessage(message['from'], unicode(mess_data["message"]), mess_type=mess_data["type"], to_jid=message['to'], profile=profile) #We send back the message, so all clients are aware of it + self.bridge.newMessage(message['from'], unicode(mess_data["message"]), mess_type=mess_data["type"], to_jid=message['to'], extra={}, profile=profile) #We send back the message, so all clients are aware of it def setPresence(self, to="", show="", priority = 0, statuses={}, profile_key='@DEFAULT@'):
--- a/src/core/xmpp.py Wed Oct 17 00:35:48 2012 +0200 +++ b/src/core/xmpp.py Sat Oct 20 17:23:56 2012 +0200 @@ -21,9 +21,10 @@ from twisted.internet import task, defer from twisted.words.protocols.jabber import jid, xmlstream -from wokkel import client, disco, xmppim, generic, compat +from wokkel import client, disco, xmppim, generic, compat, delay from logging import debug, info, error from sat.core import exceptions +from calendar import timegm class SatXMPPClient(client.XMPPClient): @@ -104,17 +105,25 @@ self.host = host def onMessage(self, message): - debug (_(u"got message from: %s"), message["from"]) - if not self.host.trigger.point("MessageReceived",message, profile=self.parent.profile): - return - for e in message.elements(): - if e.name == "body": - mess_type = message['type'] if message.hasAttribute('type') else 'normal' - mess_body = e.children[0] if e.children else "" - self.host.bridge.newMessage(message["from"], mess_body, mess_type, message['to'], profile=self.parent.profile) - if not u"delay" in [elem.name for elem in message.elements()]: #we don't save delayed messages in history - self.host.memory.addToHistory(jid.JID(message["from"]), jid.JID(message["to"]), mess_body, mess_type, profile=self.parent.profile) - break + debug (_(u"got message from: %s"), message["from"]) + if not self.host.trigger.point("MessageReceived",message, profile=self.parent.profile): + return + for e in message.elements(): + if e.name == "body": + mess_type = message['type'] if message.hasAttribute('type') else 'normal' + mess_body = e.children[0] if e.children else "" + try: + _delay = delay.Delay.fromElement(filter(lambda elm: elm.name == 'delay', message.elements())[0]) + timestamp = timegm(_delay.stamp.utctimetuple()) + extra = {"archive": str(timestamp)} + if mess_type != 'groupchat': #XXX: we don't save delayed messages in history for groupchats + #TODO: add delayed messages to history if they aren't already in it + self.host.memory.addToHistory(jid.JID(message["from"]), jid.JID(message["to"]), mess_body, mess_type, timestamp, profile=self.parent.profile) + except IndexError: + extra = {} + self.host.memory.addToHistory(jid.JID(message["from"]), jid.JID(message["to"]), mess_body, mess_type, profile=self.parent.profile) + self.host.bridge.newMessage(message["from"], mess_body, mess_type, message['to'], extra, profile=self.parent.profile) + break class SatRosterProtocol(xmppim.RosterClientProtocol):