Mercurial > libervia-backend
changeset 654:5c5cf5bca240
plugin XEP-0085: improvement for sending "composing" state
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 26 Sep 2013 10:44:57 +0200 (2013-09-26) |
parents | e2eff3c7ad02 |
children | 56f8a9c99194 |
files | src/plugins/plugin_xep_0085.py |
diffstat | 1 files changed, 22 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0085.py Thu Sep 26 10:14:23 2013 +0200 +++ b/src/plugins/plugin_xep_0085.py Thu Sep 26 10:44:57 2013 +0200 @@ -99,7 +99,7 @@ host.trigger.add("MessageReceived", self.messageReceivedTrigger) host.trigger.add("sendMessageXml", self.sendMessageXmlTrigger) host.trigger.add("paramUpdateTrigger", self.paramUpdateTrigger) - #TODO: handle profile disconnexion (free memory in entity data) + # TODO: handle profile disconnexion (free memory in entity data) # args: to_s (jid as string), profile host.bridge.addMethod("chatStateComposing", ".plugin", in_sign='ss', @@ -217,7 +217,7 @@ """ Launch the chat state machine on "active" state. """ - # TODO: use also the resource in map key + # TODO: use also the JID resource in the map key to_jid = to_jid.userhostJID() profile = self.host.memory.getProfileName(profile_key) if profile is None: @@ -227,18 +227,32 @@ def chatStateComposing(self, to_jid_s, profile_key): """ - Move to the "composing" state. + Move to the "composing" state. Since this method is called + from the front-end, it needs to check the values of the + parameter "Send chat state notifications" and the entity + data associated to the target JID. + TODO: try to optimize this method which is called often """ - # TODO: use also the resource in map key + # check if the parameter is active + if not self.host.memory.getParamA(PARAM_NAME, PARAM_KEY, profile_key=profile_key): + return + # TODO: use also the JID resource in the map key to_jid = JID(to_jid_s).userhostJID() profile = self.host.memory.getProfileName(profile_key) if profile is None: raise exceptions.ProfileUnknownError + # check if notifications should be sent to this contact + contact_enabled = True try: - self.map[profile][to_jid]._onEvent("composing") - except: - # it just means that no first message has been sent already - return + contact_enabled = self.host.memory.getEntityData( + to_jid, [ENTITY_KEY], profile)[ENTITY_KEY] + except (exceptions.UnknownEntityError, KeyError): + # wait for the first message before sending states + pass + if not contact_enabled: + return True + # now we are sure that the state should be sent + self.map[profile][to_jid]._onEvent("composing") class ChatStateMachine: