plugin XEP-0085: improvement for sending "composing" state

This commit is contained in:
souliane 2013-09-26 10:44:57 +02:00
commit e0ecb6158b

View file

@ -99,7 +99,7 @@ class XEP_0085(object):
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 @@ class XEP_0085(object):
"""
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 @@ class XEP_0085(object):
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: