core (memory): updateEntityData now accept a "silent" argument to avoid sending signal to frontends when updating an attribute with "signalOnUpdate" flag.
This commit is contained in:
parent
ec25ba82e1
commit
cdfb2c4dc6
8 changed files with 17 additions and 20 deletions
|
|
@ -319,10 +319,6 @@ class SatPresenceProtocol(xmppim.PresenceClientProtocol):
|
|||
int(priority), statuses,
|
||||
self.parent.profile)
|
||||
|
||||
# uncomment these two lines if you need the trigger
|
||||
#if not self.host.trigger.point("presenceReceived", entity, "unavailable", 0, statuses, self.parent.profile):
|
||||
# return
|
||||
|
||||
# now it's time to notify frontends
|
||||
self.host.bridge.presenceUpdate(entity.full(), show or "",
|
||||
int(priority), statuses,
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ class Discovery(object):
|
|||
def infosCb(disco_infos):
|
||||
cap_hash = self.generateHash(disco_infos)
|
||||
self.hashes[cap_hash] = disco_infos
|
||||
self.host.memory.updateEntityData(jid_, C.ENTITY_CAP_HASH, cap_hash, client.profile)
|
||||
self.host.memory.updateEntityData(jid_, C.ENTITY_CAP_HASH, cap_hash, profile_key=client.profile)
|
||||
return disco_infos
|
||||
d = client.disco.requestInfo(jid_)
|
||||
d.addCallback(infosCb)
|
||||
|
|
@ -135,7 +135,7 @@ class Discovery(object):
|
|||
except (KeyError, exceptions.UnknownEntityError):
|
||||
log.debug("Caching [%s] disco items" % jid_.full())
|
||||
items = yield client.disco.requestItems(jid_, nodeIdentifier)
|
||||
self.host.memory.updateEntityData(jid_, "DISCO_ITEMS", items, client.profile)
|
||||
self.host.memory.updateEntityData(jid_, "DISCO_ITEMS", items, profile_key=client.profile)
|
||||
else:
|
||||
items = yield client.disco.requestItems(jid_, nodeIdentifier)
|
||||
|
||||
|
|
|
|||
|
|
@ -444,7 +444,7 @@ class Memory(object):
|
|||
@param profile_key: %(doc_profile_key)s
|
||||
"""
|
||||
presence_data = PresenceTuple(show, priority, statuses)
|
||||
self.updateEntityData(entity_jid, "presence", presence_data, profile_key)
|
||||
self.updateEntityData(entity_jid, "presence", presence_data, profile_key=profile_key)
|
||||
if entity_jid.resource and show != C.PRESENCE_UNAVAILABLE:
|
||||
# If a resource is available, bare jid should not have presence information
|
||||
try:
|
||||
|
|
@ -580,7 +580,7 @@ class Memory(object):
|
|||
full_jid.resource = resource
|
||||
yield full_jid
|
||||
|
||||
def updateEntityData(self, entity_jid, key, value, profile_key):
|
||||
def updateEntityData(self, entity_jid, key, value, silent=False, profile_key=C.PROF_KEY_NONE):
|
||||
"""Set a misc data for an entity
|
||||
|
||||
If key was registered with setSignalOnUpdate, a signal will be sent to frontends
|
||||
|
|
@ -588,6 +588,7 @@ class Memory(object):
|
|||
C.ENTITY_ALL for all entities (all resources + bare jids)
|
||||
@param key: key to set (eg: "type")
|
||||
@param value: value for this key (eg: "chatroom")
|
||||
@param silent(bool): if True, doesn't send signal to frontend, even there is a signal flag (see setSignalOnUpdate)
|
||||
@param profile_key: %(doc_profile_key)s
|
||||
"""
|
||||
profile_cache = self._getProfileCache(profile_key)
|
||||
|
|
@ -600,7 +601,7 @@ class Memory(object):
|
|||
entity_data = profile_cache.setdefault(jid_.userhostJID(),{}).setdefault(jid_.resource, {})
|
||||
|
||||
entity_data[key] = value
|
||||
if key in self._key_signals:
|
||||
if key in self._key_signals and not silent:
|
||||
if not isinstance(value, basestring):
|
||||
log.error(u"Setting a non string value ({}) for a key ({}) which has a signal flag".format(value, key))
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -696,7 +696,7 @@ class SatMUCClient (muc.MUCClient):
|
|||
self.userLeftRoom(room, user)
|
||||
|
||||
def userJoinedRoom(self, room, user):
|
||||
self.host.memory.updateEntityData(room.roomJID, "type", "chatroom", self.parent.profile)
|
||||
self.host.memory.updateEntityData(room.roomJID, "type", "chatroom", profile_key=self.parent.profile)
|
||||
if user.nick in self.__changing_nicks:
|
||||
self.__changing_nicks.remove(user.nick)
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ class XEP_0054(object):
|
|||
# hashs in memory. Hashed should be shared between profiles
|
||||
for jid_s, avatar_hash in self.avatars_cache.iteritems():
|
||||
jid_ = jid.JID(jid_s)
|
||||
self.host.memory.updateEntityData(jid_, "avatar", avatar_hash, profile)
|
||||
self.host.memory.updateEntityData(jid_, "avatar", avatar_hash, silent=True, profile_key=profile)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def profileConnected(self, profile):
|
||||
|
|
@ -122,7 +122,7 @@ class XEP_0054(object):
|
|||
@param profile: profile which received the update
|
||||
"""
|
||||
assert not jid_.resource # VCard are retrieved with bare jid
|
||||
self.host.memory.updateEntityData(jid_, name, value, profile)
|
||||
self.host.memory.updateEntityData(jid_, name, value, profile_key=profile)
|
||||
if name == "avatar":
|
||||
self.avatars_cache[jid_.userhost()] = value
|
||||
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ class XEP_0085(object):
|
|||
if value == DELETE_VALUE:
|
||||
self.host.memory.delEntityData(entity_jid, ENTITY_KEY, profile)
|
||||
else:
|
||||
self.host.memory.updateEntityData(entity_jid, ENTITY_KEY, value, profile)
|
||||
self.host.memory.updateEntityData(entity_jid, ENTITY_KEY, value, profile_key=profile)
|
||||
if not value or value == DELETE_VALUE:
|
||||
# reinit chat state UI for this or these contact(s)
|
||||
self.host.bridge.chatStateReceived(entity_jid.full(), "", profile)
|
||||
|
|
@ -151,7 +151,7 @@ class XEP_0085(object):
|
|||
@param type_: parameter type
|
||||
"""
|
||||
if (category, name) == (PARAM_KEY, PARAM_NAME):
|
||||
self.updateEntityData(C.ENTITY_ALL, True if bool("true") else DELETE_VALUE, profile)
|
||||
self.updateEntityData(C.ENTITY_ALL, True if bool("true") else DELETE_VALUE, profile_key=profile)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
@ -173,11 +173,11 @@ class XEP_0085(object):
|
|||
try:
|
||||
domish.generateElementsNamed(message.elements(), name="active").next()
|
||||
# contact enabled Chat State Notifications
|
||||
self.updateEntityData(from_jid, True, profile)
|
||||
self.updateEntityData(from_jid, True, profile_key=profile)
|
||||
except StopIteration:
|
||||
if message.getAttribute('type') == 'chat':
|
||||
# contact didn't enable Chat State Notifications
|
||||
self.updateEntityData(from_jid, False, profile)
|
||||
self.updateEntityData(from_jid, False, profile_key=profile)
|
||||
return True
|
||||
except StopIteration:
|
||||
pass
|
||||
|
|
@ -260,7 +260,7 @@ class XEP_0085(object):
|
|||
except (exceptions.UnknownEntityError, KeyError):
|
||||
if forceEntityData:
|
||||
# enable it for the first time
|
||||
self.updateEntityData(to_jid, True, profile)
|
||||
self.updateEntityData(to_jid, True, profile_key=profile)
|
||||
return True
|
||||
# wait for the first message before sending states
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ class XEP_0115(object):
|
|||
client.caps_sent = False
|
||||
if cap_hash not in self.host.memory.disco.hashes:
|
||||
self.host.memory.disco.hashes[cap_hash] = disco_infos
|
||||
self.host.memory.updateEntityData(client.jid, C.ENTITY_CAP_HASH, cap_hash, profile)
|
||||
self.host.memory.updateEntityData(client.jid, C.ENTITY_CAP_HASH, cap_hash, profile_key=profile)
|
||||
|
||||
|
||||
class XEP_0115_handler(XMPPHandler):
|
||||
|
|
@ -146,7 +146,7 @@ class XEP_0115_handler(XMPPHandler):
|
|||
if c_ver in self.host.memory.disco.hashes:
|
||||
# we already know the hash, we update the jid entity
|
||||
log.debug ("hash [%(hash)s] already in cache, updating entity [%(jid)s]" % {'hash': c_ver, 'jid': from_jid.full()})
|
||||
self.host.memory.updateEntityData(from_jid, C.ENTITY_CAP_HASH, c_ver, self.profile)
|
||||
self.host.memory.updateEntityData(from_jid, C.ENTITY_CAP_HASH, c_ver, profile_key=self.profile)
|
||||
return
|
||||
|
||||
if c_hash != 'sha-1': # unknown hash method
|
||||
|
|
|
|||
|
|
@ -286,7 +286,7 @@ class FakeMemory(Memory):
|
|||
def delWaitingSub(self, contact_jid, profile_key):
|
||||
pass
|
||||
|
||||
def updateEntityData(self, entity_jid, key, value, profile_key):
|
||||
def updateEntityData(self, entity_jid, key, value, silent=False, profile_key="@NONE@"):
|
||||
self.entities_data.setdefault(entity_jid, {})
|
||||
self.entities_data[entity_jid][key] = value
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue