quick_frontend(chat): better handling of cached signals when initialising widget
This commit is contained in:
parent
9f853cd774
commit
60c8f2fc3d
2 changed files with 10 additions and 5 deletions
|
|
@ -155,7 +155,7 @@ class QuickChat(quick_widgets.QuickWidget):
|
||||||
quick_widgets.QuickWidget.__init__(self, host, target, profiles=profiles)
|
quick_widgets.QuickWidget.__init__(self, host, target, profiles=profiles)
|
||||||
self._locked = True # True when we are waiting for history/search
|
self._locked = True # True when we are waiting for history/search
|
||||||
# messageNew signals are cached when locked
|
# messageNew signals are cached when locked
|
||||||
self._cache = []
|
self._cache = OrderedDict()
|
||||||
assert type_ in (C.CHAT_ONE2ONE, C.CHAT_GROUP)
|
assert type_ in (C.CHAT_ONE2ONE, C.CHAT_GROUP)
|
||||||
self.current_target = target
|
self.current_target = target
|
||||||
self.type = type_
|
self.type = type_
|
||||||
|
|
@ -288,6 +288,7 @@ class QuickChat(quick_widgets.QuickWidget):
|
||||||
@param profile (str): %(doc_profile)s
|
@param profile (str): %(doc_profile)s
|
||||||
"""
|
"""
|
||||||
self._locked = True
|
self._locked = True
|
||||||
|
self._cache = OrderedDict()
|
||||||
self.messages.clear()
|
self.messages.clear()
|
||||||
self.historyPrint(size, filters, profile)
|
self.historyPrint(size, filters, profile)
|
||||||
|
|
||||||
|
|
@ -298,8 +299,9 @@ class QuickChat(quick_widgets.QuickWidget):
|
||||||
the focus after the history is printed
|
the focus after the history is printed
|
||||||
"""
|
"""
|
||||||
self._locked = False
|
self._locked = False
|
||||||
for data in self._cache:
|
for data in self._cache.itervalues():
|
||||||
self.messageNew(*data)
|
self.messageNew(*data)
|
||||||
|
del self._cache
|
||||||
|
|
||||||
def historyPrint(self, size=C.HISTORY_LIMIT_DEFAULT, filters=None, profile='@NONE@'):
|
def historyPrint(self, size=C.HISTORY_LIMIT_DEFAULT, filters=None, profile='@NONE@'):
|
||||||
"""Print the current history
|
"""Print the current history
|
||||||
|
|
@ -330,6 +332,10 @@ class QuickChat(quick_widgets.QuickWidget):
|
||||||
# previous_day = message_day
|
# previous_day = message_day
|
||||||
for data in history:
|
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 = 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)
|
from_jid = jid.JID(from_jid)
|
||||||
to_jid = jid.JID(to_jid)
|
to_jid = jid.JID(to_jid)
|
||||||
# if ((self.type == C.CHAT_GROUP and type_ != C.MESS_TYPE_GROUPCHAT) or
|
# if ((self.type == C.CHAT_GROUP and type_ != C.MESS_TYPE_GROUPCHAT) or
|
||||||
|
|
@ -345,9 +351,8 @@ class QuickChat(quick_widgets.QuickWidget):
|
||||||
self.host.bridge.historyGet(unicode(self.host.profiles[profile].whoami.bare), unicode(target), size, True, filters, profile, callback=_historyGetCb, errback=_historyGetEb)
|
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):
|
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:
|
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
|
return
|
||||||
if self.type == C.CHAT_GROUP:
|
if self.type == C.CHAT_GROUP:
|
||||||
if to_jid.resource and type_ != C.MESS_TYPE_GROUPCHAT:
|
if to_jid.resource and type_ != C.MESS_TYPE_GROUPCHAT:
|
||||||
|
|
|
||||||
|
|
@ -457,7 +457,7 @@ doc_param_0=to_jid: JID of the recipient
|
||||||
doc_param_1=message: body of the message:
|
doc_param_1=message: body of the message:
|
||||||
key is the language of the body, use '' when unknown
|
key is the language of the body, use '' when unknown
|
||||||
doc_param_2=subject: Subject of the message
|
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_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_4=extra: optional data that can be used by a plugin to build more specific messages
|
||||||
doc_param_5=%(doc_profile_key)s
|
doc_param_5=%(doc_profile_key)s
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue