diff browser_side/contact.py @ 413:7a8991cda2fa

browser_side: display presence with the highest priority
author souliane <souliane@mailoo.org>
date Thu, 20 Mar 2014 22:16:02 +0100
parents 564208366dd6
children d52f529a6d42
line wrap: on
line diff
--- a/browser_side/contact.py	Wed Mar 19 20:27:46 2014 +0100
+++ b/browser_side/contact.py	Thu Mar 20 22:16:02 2014 +0100
@@ -322,7 +322,21 @@
             if not jid in self.connected:
                 self.connected[jid] = {}
             self.connected[jid][resource] = (availability, priority, statuses)
-        self._contact_list.setState(jid, "availability", availability)
+
+        # check if the contact is connected with another resource, use the one with highest priority
+        if jid in self.connected:
+            max_resource = max_priority = None
+            for tmp_resource in self.connected[jid]:
+                if max_priority is None or self.connected[jid][tmp_resource][1] >= max_priority:
+                    max_resource = tmp_resource
+                    max_priority = self.connected[jid][tmp_resource][1]
+            if availability == "unavailable":  # do not check the priority here, because 'unavailable' has a dummy one
+                priority = max_priority
+                availability = self.connected[jid][max_resource][0]
+        if jid not in self.connected or priority >= max_priority:
+            # case 1: jid not in self.connected means all resources are disconnected, update with 'unavailable'
+            # case 2: update (or confirm) with the values of the resource which takes precedence
+            self._contact_list.setState(jid, "availability", availability)
 
         # update the connected contacts chooser live
         if hasattr(self.host, "room_contacts_chooser") and self.host.room_contacts_chooser is not None: