plugin XEP-0085: fixes the calls to memory.deleteEntityDatum and self.updateCache (was self.updateEntityData, has been renamed to avoid confusion with the memory method)

This commit is contained in:
souliane 2015-02-22 11:43:11 +01:00
commit d70f08d524

View file

@ -126,16 +126,16 @@ class XEP_0085(object):
self.map[profile][to_jid]._onEvent('gone') self.map[profile][to_jid]._onEvent('gone')
del self.map[profile] del self.map[profile]
def updateEntityData(self, entity_jid, value, profile): def updateCache(self, entity_jid, value, profile):
"""Update the entity data of the given profile for one or all contacts. """Update the entity data of the given profile for one or all contacts.
Reset the chat state(s) display if the notification has been disabled. Reset the chat state(s) display if the notification has been disabled.
@param entity_jid: contact's JID, or C.ENTITY_ALL to update all contacts. @param entity_jid: contact's JID, or C.ENTITY_ALL to update all contacts.
@param value: True, False or DELETE_VALUE to delete the entity data @param value: True, False or DELETE_VALUE to delete the entity data
@param profile: current profile @param profile: current profile
""" """
if value == DELETE_VALUE: if value == DELETE_VALUE:
self.host.memory.delEntityData(entity_jid, ENTITY_KEY, profile) self.host.memory.delEntityDatum(entity_jid, ENTITY_KEY, profile)
else: else:
self.host.memory.updateEntityData(entity_jid, ENTITY_KEY, value, profile_key=profile) self.host.memory.updateEntityData(entity_jid, ENTITY_KEY, value, profile_key=profile)
if not value or value == DELETE_VALUE: if not value or value == DELETE_VALUE:
@ -151,7 +151,7 @@ class XEP_0085(object):
@param type_: parameter type @param type_: parameter type
""" """
if (category, name) == (PARAM_KEY, PARAM_NAME): if (category, name) == (PARAM_KEY, PARAM_NAME):
self.updateEntityData(C.ENTITY_ALL, True if bool("true") else DELETE_VALUE, profile_key=profile) self.updateCache(C.ENTITY_ALL, True if bool("true") else DELETE_VALUE, profile=profile)
return False return False
return True return True
@ -173,11 +173,11 @@ class XEP_0085(object):
try: try:
domish.generateElementsNamed(message.elements(), name="active").next() domish.generateElementsNamed(message.elements(), name="active").next()
# contact enabled Chat State Notifications # contact enabled Chat State Notifications
self.updateEntityData(from_jid, True, profile_key=profile) self.updateCache(from_jid, True, profile=profile)
except StopIteration: except StopIteration:
if message.getAttribute('type') == 'chat': if message.getAttribute('type') == 'chat':
# contact didn't enable Chat State Notifications # contact didn't enable Chat State Notifications
self.updateEntityData(from_jid, False, profile_key=profile) self.updateCache(from_jid, False, profile=profile)
return True return True
except StopIteration: except StopIteration:
pass pass
@ -260,7 +260,7 @@ class XEP_0085(object):
except (exceptions.UnknownEntityError, KeyError): except (exceptions.UnknownEntityError, KeyError):
if forceEntityData: if forceEntityData:
# enable it for the first time # enable it for the first time
self.updateEntityData(to_jid, True, profile_key=profile) self.updateCache(to_jid, True, profile=profile)
return True return True
# wait for the first message before sending states # wait for the first message before sending states
return False return False