core: use serialised dict for extra in messageNew and historyGet

This commit is contained in:
Goffi 2020-02-18 18:13:17 +01:00
commit 6a7d247754
7 changed files with 33 additions and 19 deletions

View file

@ -37,7 +37,7 @@ doc_param_3=%(doc_profile)s
[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 @@ async=
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@"

View file

@ -175,7 +175,7 @@ class DbusObject(dbus.service.Object):
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 @@ class DbusObject(dbus.service.Object):
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)

View file

@ -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.core import exceptions
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 @@ class SatXMPPEntity:
"""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 @@ class SatXMPPClient(SatXMPPEntity, wokkel_client.XMPPClient):
message={"": message},
subject={},
mess_type=C.MESS_TYPE_INFO,
extra=extra,
extra=data_format.serialise(extra),
profile=self.profile,
)
@ -1147,7 +1147,7 @@ class SatMessageProtocol(xmppim.MessageProtocol):
data["message"],
data["subject"],
data["type"],
data["extra"],
data_format.serialise(data["extra"]),
profile=self.parent.profile,
)
else:

View file

@ -590,10 +590,19 @@ class Memory(object):
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):

View file

@ -262,7 +262,7 @@ class Message(object):
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

View file

@ -759,10 +759,12 @@ class QuickApp(object):
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,):

View file

@ -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 sat_frontends.quick_frontend.constants import Const as C
from collections import OrderedDict
from sat_frontends.tools import jid
import time
log = getLogger(__name__)
try:
@ -44,11 +45,12 @@ ROOM_USER_MOVED = (ROOM_USER_JOINED, ROOM_USER_LEFT)
# 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 @@ class QuickChat(quick_widgets.QuickWidget):
# 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