Mercurial > libervia-backend
changeset 917:a9401694d2dc
bridge, frontends: display presence with the highest priority + reset your own presence when you (dis)connect
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 20 Mar 2014 21:18:18 +0100 (2014-03-20) |
parents | 1a759096ccbd |
children | 1597fb8b9108 |
files | frontends/src/bridge/DBus.py frontends/src/primitivus/primitivus frontends/src/quick_frontend/quick_app.py src/bridge/DBus.py src/bridge/bridge_constructor/bridge_template.ini src/core/sat_main.py |
diffstat | 6 files changed, 39 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/bridge/DBus.py Fri Mar 21 16:27:09 2014 +0100 +++ b/frontends/src/bridge/DBus.py Thu Mar 20 21:18:18 2014 +0100 @@ -200,8 +200,8 @@ def setParam(self, name, value, category, security_limit=-1, profile_key="@DEFAULT@"): return self.db_core_iface.setParam(name, value, category, security_limit, profile_key) - def setPresence(self, to_jid='', show='', priority=0, statuses={}, profile_key="@DEFAULT@"): - return self.db_core_iface.setPresence(to_jid, show, priority, statuses, profile_key) + def setPresence(self, to_jid='', show='', statuses={}, profile_key="@DEFAULT@"): + return self.db_core_iface.setPresence(to_jid, show, statuses, profile_key) def subscription(self, sub_type, entity, profile_key="@DEFAULT@"): return self.db_core_iface.subscription(sub_type, entity, profile_key)
--- a/frontends/src/primitivus/primitivus Fri Mar 21 16:27:09 2014 +0100 +++ b/frontends/src/primitivus/primitivus Thu Mar 20 21:18:18 2014 +0100 @@ -608,6 +608,7 @@ def setStatusOnline(self, online=True, show="", statuses={}): if not online or not statuses: + self.status_bar.setPresenceStatus(show if online else 'unavailable', '') return try: self.status_bar.setPresenceStatus(show, statuses['default'])
--- a/frontends/src/quick_frontend/quick_app.py Fri Mar 21 16:27:09 2014 +0100 +++ b/frontends/src/quick_frontend/quick_app.py Thu Mar 20 21:18:18 2014 +0100 @@ -179,10 +179,10 @@ priority = presences[contact][res][1] statuses = presences[contact][res][2] self.presenceUpdate(jabber_id, show, priority, statuses, profile) - data = self.bridge.getEntityData(contact, ['avatar', 'nick'], profile) - for key in ('avatar', 'nick'): - if key in data: - self.entityDataUpdated(contact, key, data[key], profile) + data = self.bridge.getEntityData(contact, ['avatar', 'nick'], profile) + for key in ('avatar', 'nick'): + if key in data: + self.entityDataUpdated(contact, key, data[key], profile) #The waiting subscription requests waitingSub = self.bridge.getWaitingSub(profile) @@ -313,7 +313,7 @@ self.setStatusOnline(True, show, statuses) return - self.contact_list.updatePresence(from_jid, show, priority, statuses) + presences = self.profiles[profile].setdefault('presences', {}) if show != 'unavailable': @@ -321,13 +321,32 @@ if from_jid.bare in self.profiles[profile]['watched'] and not from_jid.bare in self.profiles[profile]['onlineContact']: self.showAlert(_("Watched jid [%s] is connected !") % from_jid.bare) + presences[jabber_id] = {'show': show, 'priority': priority, 'statuses': statuses} self.profiles[profile]['onlineContact'].add(from_jid) # FIXME onlineContact is useless with CM, must be removed #TODO: vcard data (avatar) if show == "unavailable" and from_jid in self.profiles[profile]['onlineContact']: + try: + del presences[jabber_id] + except KeyError: + pass self.profiles[profile]['onlineContact'].remove(from_jid) + # check if the contact is connected with another resource, use the one with highest priority + jids = [jid for jid in presences if JID(jid).bare == from_jid.bare] + if jids: + max_jid = max(jids, key=lambda jid: presences[jid]['priority']) + data = presences[max_jid] + max_priority = data['priority'] + if show == "unavailable": # do not check the priority here, because 'unavailable' has a dummy one + from_jid = JID(max_jid) + show, priority, statuses = data['show'], data['priority'], data['statuses'] + if not jids or priority >= max_priority: + # case 1: not jids means all resources are disconnected, send the 'unavailable' presence + # case 2: update (or confirm) with the values of the resource which takes precedence + self.contact_list.updatePresence(from_jid, show, priority, statuses) + def roomJoined(self, room_jid, room_nicks, user_nick, profile): """Called when a MUC room is joined""" if not self.check_profile(profile):
--- a/src/bridge/DBus.py Fri Mar 21 16:27:09 2014 +0100 +++ b/src/bridge/DBus.py Thu Mar 20 21:18:18 2014 +0100 @@ -396,10 +396,10 @@ return self._callback("setParam", unicode(name), unicode(value), unicode(category), security_limit, unicode(profile_key)) @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, - in_signature='ssia{ss}s', out_signature='', + in_signature='ssa{ss}s', out_signature='', async_callbacks=None) - def setPresence(self, to_jid='', show='', priority=0, statuses={}, profile_key="@DEFAULT@"): - return self._callback("setPresence", unicode(to_jid), unicode(show), priority, statuses, unicode(profile_key)) + def setPresence(self, to_jid='', show='', statuses={}, profile_key="@DEFAULT@"): + return self._callback("setPresence", unicode(to_jid), unicode(show), statuses, unicode(profile_key)) @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, in_signature='sss', out_signature='',
--- a/src/bridge/bridge_constructor/bridge_template.ini Fri Mar 21 16:27:09 2014 +0100 +++ b/src/bridge/bridge_constructor/bridge_template.ini Thu Mar 20 21:18:18 2014 +0100 @@ -357,19 +357,17 @@ [setPresence] type=method category=core -sig_in=ssia{ss}s +sig_in=ssa{ss}s sig_out= param_0_default='' param_1_default='' -param_2_default=0 -param_3_default={} -param_4_default="@DEFAULT@" +param_2_default={} +param_3_default="@DEFAULT@" doc=Set presence information for the profile doc_param_0=to_jid: the JID to who we send the presence data (emtpy string for broadcast) doc_param_1=show: as for [presenceUpdate] -doc_param_2=priority: as for [presenceUpdate] -doc_param_3=statuses: as for [presenceUpdate] -doc_param_4=%(doc_profile_key)s +doc_param_2=statuses: as for [presenceUpdate] +doc_param_3=%(doc_profile_key)s [subscription] type=method
--- a/src/core/sat_main.py Fri Mar 21 16:27:09 2014 +0100 +++ b/src/core/sat_main.py Thu Mar 20 21:18:18 2014 +0100 @@ -574,15 +574,16 @@ extra=mess_data['extra'], profile=profile) - def _setPresence(self, to="", show="", priority=0, statuses=None, profile_key=C.PROF_KEY_NONE): - return self.setPresence(jid.JID(to) if to else None, show, priority, statuses, profile_key) + def _setPresence(self, to="", show="", statuses=None, profile_key=C.PROF_KEY_NONE): + return self.setPresence(jid.JID(to) if to else None, show, statuses, profile_key) - def setPresence(self, to_jid=None, show="", priority=0, statuses=None, profile_key=C.PROF_KEY_NONE): + def setPresence(self, to_jid=None, show="", statuses=None, profile_key=C.PROF_KEY_NONE): """Send our presence information""" if statuses is None: statuses = {} profile = self.memory.getProfileName(profile_key) assert(profile) + priority = int(self.memory.getParamA("Priority", "Connection", profile_key=profile)) self.profiles[profile].presence.available(to_jid, show, statuses, priority) #XXX: FIXME: temporary fix to work around openfire 3.7.0 bug (presence is not broadcasted to generating resource) if '' in statuses: