# HG changeset patch # User Goffi # Date 1582045997 -3600 # Node ID 39d7327583e1460c37706e1ee6a0c133b1791c3f # Parent 560642ab1c103d7f9db906d14aa1d3835b9e2c98 core: use serialised dict for `extra` in messageNew and historyGet diff -r 560642ab1c10 -r 39d7327583e1 sat/bridge/bridge_constructor/bridge_template.ini --- a/sat/bridge/bridge_constructor/bridge_template.ini Fri Feb 14 15:18:52 2020 +0100 +++ b/sat/bridge/bridge_constructor/bridge_template.ini Tue Feb 18 18:13:17 2020 +0100 @@ -37,7 +37,7 @@ [messageNew] type=signal category=core -sig_in=sdssa{ss}a{ss}sa{ss}s +sig_in=sdssa{ss}a{ss}sss doc=A message has been received doc_param_0=uid: unique ID of the message (id specific to SàT, this it *NOT* an XMPP id) doc_param_1=timestamp: when the message was sent (or declared sent for delayed messages) @@ -682,7 +682,7 @@ type=method category=core sig_in=ssiba{ss}s -sig_out=a(sdssa{ss}a{ss}sa{ss}) +sig_out=a(sdssa{ss}a{ss}ss) param_3_default=True param_4_default='' param_5_default="@NONE@" diff -r 560642ab1c10 -r 39d7327583e1 sat/bridge/dbus_bridge.py --- a/sat/bridge/dbus_bridge.py Fri Feb 14 15:18:52 2020 +0100 +++ b/sat/bridge/dbus_bridge.py Tue Feb 18 18:13:17 2020 +0100 @@ -175,7 +175,7 @@ pass @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX, - signature='sdssa{ss}a{ss}sa{ss}s') + signature='sdssa{ss}a{ss}sss') def messageNew(self, uid, timestamp, from_jid, to_jid, message, subject, mess_type, extra, profile): pass @@ -385,7 +385,7 @@ return self._callback("getWaitingSub", str(profile_key)) @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, - in_signature='ssiba{ss}s', out_signature='a(sdssa{ss}a{ss}sa{ss})', + in_signature='ssiba{ss}s', out_signature='a(sdssa{ss}a{ss}ss)', async_callbacks=('callback', 'errback')) def historyGet(self, from_jid, to_jid, limit, between=True, filters='', profile="@NONE@", callback=None, errback=None): return self._callback("historyGet", str(from_jid), str(to_jid), limit, between, filters, str(profile), callback=callback, errback=errback) diff -r 560642ab1c10 -r 39d7327583e1 sat/core/xmpp.py --- a/sat/core/xmpp.py Fri Feb 14 15:18:52 2020 +0100 +++ b/sat/core/xmpp.py Tue Feb 18 18:13:17 2020 +0100 @@ -1,7 +1,6 @@ #!/usr/bin/env python3 - -# SAT: a jabber client +# SàT: a XMPP client # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org) # This program is free software: you can redistribute it and/or modify @@ -42,6 +41,7 @@ from sat.memory import encryption from sat.memory import persistent from sat.tools import xml_tools +from sat.tools.common import data_format from zope.interface import implementer log = getLogger(__name__) @@ -677,7 +677,7 @@ """Generate args to use with bridge from data dict""" return (data["uid"], data["timestamp"], data["from"].full(), data["to"].full(), data["message"], data["subject"], - data["type"], data["extra"]) + data["type"], data_format.serialise(data["extra"])) def messageSendToBridge(self, data): @@ -860,7 +860,7 @@ message={"": message}, subject={}, mess_type=C.MESS_TYPE_INFO, - extra=extra, + extra=data_format.serialise(extra), profile=self.profile, ) @@ -1147,7 +1147,7 @@ data["message"], data["subject"], data["type"], - data["extra"], + data_format.serialise(data["extra"]), profile=self.parent.profile, ) else: diff -r 560642ab1c10 -r 39d7327583e1 sat/memory/memory.py --- a/sat/memory/memory.py Fri Feb 14 15:18:52 2020 +0100 +++ b/sat/memory/memory.py Tue Feb 18 18:13:17 2020 +0100 @@ -590,10 +590,19 @@ def addToHistory(self, client, data): return self.storage.addToHistory(data, client.profile) + def _historyGetSerialise(self, history_data): + return [ + (uid, timestamp, from_jid, to_jid, message, subject, mess_type, + data_format.serialise(extra)) for uid, timestamp, from_jid, to_jid, message, + subject, mess_type, extra in history_data + ] + def _historyGet(self, from_jid_s, to_jid_s, limit=C.HISTORY_LIMIT_NONE, between=True, filters=None, profile=C.PROF_KEY_NONE): - return self.historyGet(jid.JID(from_jid_s), jid.JID(to_jid_s), limit, between, + d = self.historyGet(jid.JID(from_jid_s), jid.JID(to_jid_s), limit, between, filters, profile) + d.addCallback(self._historyGetSerialise) + return d def historyGet(self, from_jid, to_jid, limit=C.HISTORY_LIMIT_NONE, between=True, filters=None, profile=C.PROF_KEY_NONE): diff -r 560642ab1c10 -r 39d7327583e1 sat/tools/common/data_objects.py --- a/sat/tools/common/data_objects.py Fri Feb 14 15:18:52 2020 +0100 +++ b/sat/tools/common/data_objects.py Tue Feb 18 18:13:17 2020 +0100 @@ -262,7 +262,7 @@ self._message_data = msg_data[4] self._subject_data = msg_data[5] self._type = msg_data[6] - self._extra = msg_data[7] + self._extra = data_format.deserialise(msg_data[7]) self._html = dict(data_format.getSubDict("xhtml", self._extra)) @property diff -r 560642ab1c10 -r 39d7327583e1 sat_frontends/quick_frontend/quick_app.py --- a/sat_frontends/quick_frontend/quick_app.py Fri Feb 14 15:18:52 2020 +0100 +++ b/sat_frontends/quick_frontend/quick_app.py Tue Feb 18 18:13:17 2020 +0100 @@ -759,10 +759,12 @@ groups = list(groups) self.contact_lists[profile].setContact(entity, groups, attributes, in_roster=True) - def messageNewHandler(self, uid, timestamp, from_jid_s, to_jid_s, msg, subject, type_, - extra, profile): + def messageNewHandler( + self, uid, timestamp, from_jid_s, to_jid_s, msg, subject, type_, extra_s, + profile): from_jid = jid.JID(from_jid_s) to_jid = jid.JID(to_jid_s) + extra = data_format.deserialise(extra_s) if not self.trigger.point( "messageNewTrigger", uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, profile=profile,): diff -r 560642ab1c10 -r 39d7327583e1 sat_frontends/quick_frontend/quick_chat.py --- a/sat_frontends/quick_frontend/quick_chat.py Fri Feb 14 15:18:52 2020 +0100 +++ b/sat_frontends/quick_frontend/quick_chat.py Tue Feb 18 18:13:17 2020 +0100 @@ -1,7 +1,6 @@ #!/usr/bin/env python3 - -# helper class for making a SAT frontend +# helper class for making a SàT frontend # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org) # This program is free software: you can redistribute it and/or modify @@ -26,6 +25,8 @@ from collections import OrderedDict from sat_frontends.tools import jid import time + + log = getLogger(__name__) try: @@ -44,11 +45,12 @@ # FIXME: day_format need to be settable (i18n) -class Message(object): +class Message: """Message metadata""" - def __init__(self, parent, uid, timestamp, from_jid, to_jid, msg, subject, type_, - extra, profile): + def __init__( + self, parent, uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, + profile): self.parent = parent self.profile = profile self.uid = uid @@ -628,9 +630,10 @@ # self.printDayChange(message_day) # previous_day = message_day for data in history: - uid, timestamp, from_jid, to_jid, message, subject, type_, extra = data + uid, timestamp, from_jid, to_jid, message, subject, type_, extra_s = data from_jid = jid.JID(from_jid) to_jid = jid.JID(to_jid) + extra = data_format.deserialise(extra_s) # if ((self.type == C.CHAT_GROUP and type_ != C.MESS_TYPE_GROUPCHAT) or # (self.type == C.CHAT_ONE2ONE and type_ == C.MESS_TYPE_GROUPCHAT)): # continue