core: memory's updateEntityData improvments.

- passing @ALL@ to updateEntityData updates the specified key for all entities
    - passing @NONE@ to updateEntityData deletes the specified key
This commit is contained in:
souliane 2013-09-08 19:12:59 +02:00
commit 174a0d9862

View file

@ -563,6 +563,7 @@ class Params(object):
for profile in self.storage.getProfilesList():
if self.host.isConnected(profile):
self.host.bridge.paramUpdate(name, value, category, profile)
self.host.trigger.point("paramUpdateTrigger", name, value, category, node[0], profile)
return
assert (node[0] == 'individual')
@ -575,6 +576,7 @@ class Params(object):
if self.host.isConnected(profile): # key can not exists if profile is not connected
self.params[profile][(category, name)] = value
self.host.bridge.paramUpdate(name, value, category, profile)
self.host.trigger.point("paramUpdateTrigger", name, value, category, node[0], profile)
self.storage.setIndParam(category, name, value, profile)
@ -804,9 +806,9 @@ class Memory(object):
def updateEntityData(self, entity_jid, key, value, profile_key):
"""Set a misc data for an entity
@param entity_jid: JID of the entity
@param entity_jid: JID of the entity, or '@ALL@' to update all entities)
@param key: key to set (eg: "type")
@param value: value for this key (eg: "chatroom")
@param value: value for this key (eg: "chatroom"), or '@NONE@' to delete
@param profile_key: %(doc_profile_key)s
"""
profile = self.getProfileName(profile_key)
@ -814,10 +816,20 @@ class Memory(object):
raise exceptions.UnknownProfileError(_('Trying to get entity data for a non-existant profile'))
if not profile in self.entitiesCache:
raise exceptions.ProfileNotInCacheError
entity_data = self.entitiesCache[profile].setdefault(entity_jid.userhost(), {})
entity_data[key] = value
if isinstance(value, basestring):
self.host.bridge.entityDataUpdated(entity_jid.userhost(), key, value, profile)
if entity_jid == "@ALL@":
entities_map = self.entitiesCache[profile]
else:
entity = entity_jid.userhost()
self.entitiesCache[profile].setdefault(entity, {})
entities_map = {entity: self.entitiesCache[profile][entity]}
for entity in entities_map:
entity_map = entities_map[entity]
if value == "@NONE@" and key in entity_map:
del entity_map[key]
else:
entity_map[key] = value
if isinstance(value, basestring):
self.host.bridge.entityDataUpdated(entity, key, value, profile)
def getEntityData(self, entity_jid, keys_list, profile_key):
"""Get a list of cached values for entity