comparison frontends/src/quick_frontend/quick_app.py @ 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
parents cd02f5ef30df
children 71926ec2114d
comparison
equal deleted inserted replaced
916:1a759096ccbd 917:a9401694d2dc
177 jabber_id = contact + ('/' + res if res else '') 177 jabber_id = contact + ('/' + res if res else '')
178 show = presences[contact][res][0] 178 show = presences[contact][res][0]
179 priority = presences[contact][res][1] 179 priority = presences[contact][res][1]
180 statuses = presences[contact][res][2] 180 statuses = presences[contact][res][2]
181 self.presenceUpdate(jabber_id, show, priority, statuses, profile) 181 self.presenceUpdate(jabber_id, show, priority, statuses, profile)
182 data = self.bridge.getEntityData(contact, ['avatar', 'nick'], profile) 182 data = self.bridge.getEntityData(contact, ['avatar', 'nick'], profile)
183 for key in ('avatar', 'nick'): 183 for key in ('avatar', 'nick'):
184 if key in data: 184 if key in data:
185 self.entityDataUpdated(contact, key, data[key], profile) 185 self.entityDataUpdated(contact, key, data[key], profile)
186 186
187 #The waiting subscription requests 187 #The waiting subscription requests
188 waitingSub = self.bridge.getWaitingSub(profile) 188 waitingSub = self.bridge.getWaitingSub(profile)
189 for sub in waitingSub: 189 for sub in waitingSub:
190 self.subscribe(waitingSub[sub], sub, profile) 190 self.subscribe(waitingSub[sub], sub, profile)
311 self.setStatusOnline(False) 311 self.setStatusOnline(False)
312 else: 312 else:
313 self.setStatusOnline(True, show, statuses) 313 self.setStatusOnline(True, show, statuses)
314 return 314 return
315 315
316 self.contact_list.updatePresence(from_jid, show, priority, statuses) 316 presences = self.profiles[profile].setdefault('presences', {})
317 317
318 if show != 'unavailable': 318 if show != 'unavailable':
319 319
320 #FIXME: must be moved in a plugin 320 #FIXME: must be moved in a plugin
321 if from_jid.bare in self.profiles[profile]['watched'] and not from_jid.bare in self.profiles[profile]['onlineContact']: 321 if from_jid.bare in self.profiles[profile]['watched'] and not from_jid.bare in self.profiles[profile]['onlineContact']:
322 self.showAlert(_("Watched jid [%s] is connected !") % from_jid.bare) 322 self.showAlert(_("Watched jid [%s] is connected !") % from_jid.bare)
323 323
324 presences[jabber_id] = {'show': show, 'priority': priority, 'statuses': statuses}
324 self.profiles[profile]['onlineContact'].add(from_jid) # FIXME onlineContact is useless with CM, must be removed 325 self.profiles[profile]['onlineContact'].add(from_jid) # FIXME onlineContact is useless with CM, must be removed
325 326
326 #TODO: vcard data (avatar) 327 #TODO: vcard data (avatar)
327 328
328 if show == "unavailable" and from_jid in self.profiles[profile]['onlineContact']: 329 if show == "unavailable" and from_jid in self.profiles[profile]['onlineContact']:
330 try:
331 del presences[jabber_id]
332 except KeyError:
333 pass
329 self.profiles[profile]['onlineContact'].remove(from_jid) 334 self.profiles[profile]['onlineContact'].remove(from_jid)
335
336 # check if the contact is connected with another resource, use the one with highest priority
337 jids = [jid for jid in presences if JID(jid).bare == from_jid.bare]
338 if jids:
339 max_jid = max(jids, key=lambda jid: presences[jid]['priority'])
340 data = presences[max_jid]
341 max_priority = data['priority']
342 if show == "unavailable": # do not check the priority here, because 'unavailable' has a dummy one
343 from_jid = JID(max_jid)
344 show, priority, statuses = data['show'], data['priority'], data['statuses']
345 if not jids or priority >= max_priority:
346 # case 1: not jids means all resources are disconnected, send the 'unavailable' presence
347 # case 2: update (or confirm) with the values of the resource which takes precedence
348 self.contact_list.updatePresence(from_jid, show, priority, statuses)
330 349
331 def roomJoined(self, room_jid, room_nicks, user_nick, profile): 350 def roomJoined(self, room_jid, room_nicks, user_nick, profile):
332 """Called when a MUC room is joined""" 351 """Called when a MUC room is joined"""
333 if not self.check_profile(profile): 352 if not self.check_profile(profile):
334 return 353 return