changeset 1315:be3a301540c0 frontends_multi_profiles

core (memory): updateEntityData now accept a "silent" argument to avoid sending signal to frontends when updating an attribute with "signalOnUpdate" flag.
author Goffi <goffi@goffi.org>
date Mon, 09 Feb 2015 21:39:51 +0100
parents bb9c32249778
children 8adcdf2cdfe1
files src/core/xmpp.py src/memory/disco.py src/memory/memory.py src/plugins/plugin_xep_0045.py src/plugins/plugin_xep_0054.py src/plugins/plugin_xep_0085.py src/plugins/plugin_xep_0115.py src/test/helpers.py
diffstat 8 files changed, 17 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/core/xmpp.py	Mon Feb 09 21:39:51 2015 +0100
+++ b/src/core/xmpp.py	Mon Feb 09 21:39:51 2015 +0100
@@ -319,10 +319,6 @@
                                            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,
--- a/src/memory/disco.py	Mon Feb 09 21:39:51 2015 +0100
+++ b/src/memory/disco.py	Mon Feb 09 21:39:51 2015 +0100
@@ -107,7 +107,7 @@
             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 @@
             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)
 
--- a/src/memory/memory.py	Mon Feb 09 21:39:51 2015 +0100
+++ b/src/memory/memory.py	Mon Feb 09 21:39:51 2015 +0100
@@ -444,7 +444,7 @@
         @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 @@
                 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 @@
                            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 @@
             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:
--- a/src/plugins/plugin_xep_0045.py	Mon Feb 09 21:39:51 2015 +0100
+++ b/src/plugins/plugin_xep_0045.py	Mon Feb 09 21:39:51 2015 +0100
@@ -696,7 +696,7 @@
             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:
--- a/src/plugins/plugin_xep_0054.py	Mon Feb 09 21:39:51 2015 +0100
+++ b/src/plugins/plugin_xep_0054.py	Mon Feb 09 21:39:51 2015 +0100
@@ -105,7 +105,7 @@
         #       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 @@
         @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
 
--- a/src/plugins/plugin_xep_0085.py	Mon Feb 09 21:39:51 2015 +0100
+++ b/src/plugins/plugin_xep_0085.py	Mon Feb 09 21:39:51 2015 +0100
@@ -137,7 +137,7 @@
         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 @@
         @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 @@
                 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 @@
         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
--- a/src/plugins/plugin_xep_0115.py	Mon Feb 09 21:39:51 2015 +0100
+++ b/src/plugins/plugin_xep_0115.py	Mon Feb 09 21:39:51 2015 +0100
@@ -107,7 +107,7 @@
             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 @@
         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
--- a/src/test/helpers.py	Mon Feb 09 21:39:51 2015 +0100
+++ b/src/test/helpers.py	Mon Feb 09 21:39:51 2015 +0100
@@ -286,7 +286,7 @@
     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