Mercurial > libervia-web
changeset 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 | 9977de10b7da |
children | ae598511850d |
files | browser_side/contact.py libervia_server/__init__.py |
diffstat | 2 files changed, 16 insertions(+), 2 deletions(-) [+] |
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:
--- a/libervia_server/__init__.py Wed Mar 19 20:27:46 2014 +0100 +++ b/libervia_server/__init__.py Thu Mar 20 22:16:02 2014 +0100 @@ -215,7 +215,7 @@ @param status: any string to describe your status """ profile = ISATSession(self.session).profile - self.sat_host.bridge.setPresence('', presence, 0, {'': status}, profile) + self.sat_host.bridge.setPresence('', presence, {'': status}, profile) def jsonrpc_sendMessage(self, to_jid, msg, subject, type_, options={}):