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,
|
int(priority), statuses,
|
||||||
self.parent.profile)
|
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
|
# now it's time to notify frontends
|
||||||
self.host.bridge.presenceUpdate(entity.full(), show or "",
|
self.host.bridge.presenceUpdate(entity.full(), show or "",
|
||||||
int(priority), statuses,
|
int(priority), statuses,
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ class Discovery(object):
|
||||||
def infosCb(disco_infos):
|
def infosCb(disco_infos):
|
||||||
cap_hash = self.generateHash(disco_infos)
|
cap_hash = self.generateHash(disco_infos)
|
||||||
self.hashes[cap_hash] = 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
|
return disco_infos
|
||||||
d = client.disco.requestInfo(jid_)
|
d = client.disco.requestInfo(jid_)
|
||||||
d.addCallback(infosCb)
|
d.addCallback(infosCb)
|
||||||
|
|
@ -135,7 +135,7 @@ class Discovery(object):
|
||||||
except (KeyError, exceptions.UnknownEntityError):
|
except (KeyError, exceptions.UnknownEntityError):
|
||||||
log.debug("Caching [%s] disco items" % jid_.full())
|
log.debug("Caching [%s] disco items" % jid_.full())
|
||||||
items = yield client.disco.requestItems(jid_, nodeIdentifier)
|
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:
|
else:
|
||||||
items = yield client.disco.requestItems(jid_, nodeIdentifier)
|
items = yield client.disco.requestItems(jid_, nodeIdentifier)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -444,7 +444,7 @@ class Memory(object):
|
||||||
@param profile_key: %(doc_profile_key)s
|
@param profile_key: %(doc_profile_key)s
|
||||||
"""
|
"""
|
||||||
presence_data = PresenceTuple(show, priority, statuses)
|
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 entity_jid.resource and show != C.PRESENCE_UNAVAILABLE:
|
||||||
# If a resource is available, bare jid should not have presence information
|
# If a resource is available, bare jid should not have presence information
|
||||||
try:
|
try:
|
||||||
|
|
@ -580,7 +580,7 @@ class Memory(object):
|
||||||
full_jid.resource = resource
|
full_jid.resource = resource
|
||||||
yield full_jid
|
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
|
"""Set a misc data for an entity
|
||||||
|
|
||||||
If key was registered with setSignalOnUpdate, a signal will be sent to frontends
|
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)
|
C.ENTITY_ALL for all entities (all resources + bare jids)
|
||||||
@param key: key to set (eg: "type")
|
@param key: key to set (eg: "type")
|
||||||
@param value: value for this key (eg: "chatroom")
|
@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
|
@param profile_key: %(doc_profile_key)s
|
||||||
"""
|
"""
|
||||||
profile_cache = self._getProfileCache(profile_key)
|
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 = profile_cache.setdefault(jid_.userhostJID(),{}).setdefault(jid_.resource, {})
|
||||||
|
|
||||||
entity_data[key] = value
|
entity_data[key] = value
|
||||||
if key in self._key_signals:
|
if key in self._key_signals and not silent:
|
||||||
if not isinstance(value, basestring):
|
if not isinstance(value, basestring):
|
||||||
log.error(u"Setting a non string value ({}) for a key ({}) which has a signal flag".format(value, key))
|
log.error(u"Setting a non string value ({}) for a key ({}) which has a signal flag".format(value, key))
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -696,7 +696,7 @@ class SatMUCClient (muc.MUCClient):
|
||||||
self.userLeftRoom(room, user)
|
self.userLeftRoom(room, user)
|
||||||
|
|
||||||
def userJoinedRoom(self, 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:
|
if user.nick in self.__changing_nicks:
|
||||||
self.__changing_nicks.remove(user.nick)
|
self.__changing_nicks.remove(user.nick)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ class XEP_0054(object):
|
||||||
# hashs in memory. Hashed should be shared between profiles
|
# hashs in memory. Hashed should be shared between profiles
|
||||||
for jid_s, avatar_hash in self.avatars_cache.iteritems():
|
for jid_s, avatar_hash in self.avatars_cache.iteritems():
|
||||||
jid_ = jid.JID(jid_s)
|
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
|
@defer.inlineCallbacks
|
||||||
def profileConnected(self, profile):
|
def profileConnected(self, profile):
|
||||||
|
|
@ -122,7 +122,7 @@ class XEP_0054(object):
|
||||||
@param profile: profile which received the update
|
@param profile: profile which received the update
|
||||||
"""
|
"""
|
||||||
assert not jid_.resource # VCard are retrieved with bare jid
|
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":
|
if name == "avatar":
|
||||||
self.avatars_cache[jid_.userhost()] = value
|
self.avatars_cache[jid_.userhost()] = value
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ class XEP_0085(object):
|
||||||
if value == DELETE_VALUE:
|
if value == DELETE_VALUE:
|
||||||
self.host.memory.delEntityData(entity_jid, ENTITY_KEY, profile)
|
self.host.memory.delEntityData(entity_jid, ENTITY_KEY, profile)
|
||||||
else:
|
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:
|
if not value or value == DELETE_VALUE:
|
||||||
# reinit chat state UI for this or these contact(s)
|
# reinit chat state UI for this or these contact(s)
|
||||||
self.host.bridge.chatStateReceived(entity_jid.full(), "", profile)
|
self.host.bridge.chatStateReceived(entity_jid.full(), "", profile)
|
||||||
|
|
@ -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)
|
self.updateEntityData(C.ENTITY_ALL, True if bool("true") else DELETE_VALUE, profile_key=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)
|
self.updateEntityData(from_jid, True, profile_key=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)
|
self.updateEntityData(from_jid, False, profile_key=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)
|
self.updateEntityData(to_jid, True, profile_key=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
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ class XEP_0115(object):
|
||||||
client.caps_sent = False
|
client.caps_sent = False
|
||||||
if cap_hash not in self.host.memory.disco.hashes:
|
if cap_hash not in self.host.memory.disco.hashes:
|
||||||
self.host.memory.disco.hashes[cap_hash] = disco_infos
|
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):
|
class XEP_0115_handler(XMPPHandler):
|
||||||
|
|
@ -146,7 +146,7 @@ class XEP_0115_handler(XMPPHandler):
|
||||||
if c_ver in self.host.memory.disco.hashes:
|
if c_ver in self.host.memory.disco.hashes:
|
||||||
# we already know the hash, we update the jid entity
|
# 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()})
|
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
|
return
|
||||||
|
|
||||||
if c_hash != 'sha-1': # unknown hash method
|
if c_hash != 'sha-1': # unknown hash method
|
||||||
|
|
|
||||||
|
|
@ -286,7 +286,7 @@ class FakeMemory(Memory):
|
||||||
def delWaitingSub(self, contact_jid, profile_key):
|
def delWaitingSub(self, contact_jid, profile_key):
|
||||||
pass
|
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.setdefault(entity_jid, {})
|
||||||
self.entities_data[entity_jid][key] = value
|
self.entities_data[entity_jid][key] = value
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue