# HG changeset patch # User Goffi # Date 1469376154 -7200 # Node ID c0ff8424365078108e41e595f7f36afdcdbebe3a # Parent 7199e6bdb94e2679a6b762a24bf1e86ee0e2272f quick_frontend(chat): better handling of cached signals when initialising widget diff -r 7199e6bdb94e -r c0ff84243650 frontends/src/quick_frontend/quick_chat.py --- a/frontends/src/quick_frontend/quick_chat.py Sun Jul 24 17:59:24 2016 +0200 +++ b/frontends/src/quick_frontend/quick_chat.py Sun Jul 24 18:02:34 2016 +0200 @@ -155,7 +155,7 @@ quick_widgets.QuickWidget.__init__(self, host, target, profiles=profiles) self._locked = True # True when we are waiting for history/search # messageNew signals are cached when locked - self._cache = [] + self._cache = OrderedDict() assert type_ in (C.CHAT_ONE2ONE, C.CHAT_GROUP) self.current_target = target self.type = type_ @@ -288,6 +288,7 @@ @param profile (str): %(doc_profile)s """ self._locked = True + self._cache = OrderedDict() self.messages.clear() self.historyPrint(size, filters, profile) @@ -298,8 +299,9 @@ the focus after the history is printed """ self._locked = False - for data in self._cache: + for data in self._cache.itervalues(): self.messageNew(*data) + del self._cache def historyPrint(self, size=C.HISTORY_LIMIT_DEFAULT, filters=None, profile='@NONE@'): """Print the current history @@ -330,6 +332,10 @@ # previous_day = message_day for data in history: uid, timestamp, from_jid, to_jid, message, subject, type_, extra = data + # cached messages may already be in history + # so we check it to avoid duplicates, they'll be added later + if uid in self._cache: + continue from_jid = jid.JID(from_jid) to_jid = jid.JID(to_jid) # if ((self.type == C.CHAT_GROUP and type_ != C.MESS_TYPE_GROUPCHAT) or @@ -345,9 +351,8 @@ self.host.bridge.historyGet(unicode(self.host.profiles[profile].whoami.bare), unicode(target), size, True, filters, profile, callback=_historyGetCb, errback=_historyGetEb) def messageNew(self, uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, profile): - log.debug(u"messageNew ==> {}".format((uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, profile))) if self._locked: - self._cache.append(uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, profile) + self._cache[uid] = (uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, profile) return if self.type == C.CHAT_GROUP: if to_jid.resource and type_ != C.MESS_TYPE_GROUPCHAT: diff -r 7199e6bdb94e -r c0ff84243650 src/bridge/bridge_constructor/bridge_template.ini --- a/src/bridge/bridge_constructor/bridge_template.ini Sun Jul 24 17:59:24 2016 +0200 +++ b/src/bridge/bridge_constructor/bridge_template.ini Sun Jul 24 18:02:34 2016 +0200 @@ -457,7 +457,7 @@ doc_param_1=message: body of the message: key is the language of the body, use '' when unknown doc_param_2=subject: Subject of the message - key is the language of the subkect, use '' when unknown + key is the language of the subject, use '' when unknown doc_param_3=mess_type: Type of the message (cf RFC 6121 ยง5.2.2) or "auto" for automatic type detection doc_param_4=extra: optional data that can be used by a plugin to build more specific messages doc_param_5=%(doc_profile_key)s