comparison src/browser/contact.py @ 455:05e98b8d9f02

browser side: display messages from contacts not in roster
author souliane <souliane@mailoo.org>
date Thu, 29 May 2014 15:51:26 +0200
parents 1a0cec9b0f1e
children 36f27d1e64b2
comparison
equal deleted inserted replaced
454:3ef6ce200c27 455:05e98b8d9f02
196 web_panel = WebPanel(self.host, "/blog/%s" % node) 196 web_panel = WebPanel(self.host, "/blog/%s" % node)
197 self.host.addTab("%s's blog" % node, web_panel) 197 self.host.addTab("%s's blog" % node, web_panel)
198 else: 198 else:
199 sender.onClick(sender) 199 sender.onClick(sender)
200 200
201 def add(self, jid, name=None): 201 def add(self, jid_s, name=None):
202 """Add a contact
203
204 @param jid_s (str): JID as unicode
205 @param name (str): nickname
206 """
202 def item_cb(item): 207 def item_cb(item):
203 self.context_menu.registerRightClickSender(item) 208 self.context_menu.registerRightClickSender(item)
204 GenericContactList.add(self, jid, name, item_cb) 209 GenericContactList.add(self, jid_s, name, item_cb)
205 210
206 def setState(self, jid, type_, state): 211 def setState(self, jid, type_, state):
207 """Change the appearance of the contact, according to the state 212 """Change the appearance of the contact, according to the state
208 @param jid: jid which need to change state 213 @param jid: jid which need to change state
209 @param type_: one of availability, messageWaiting 214 @param type_: one of availability, messageWaiting
273 tab_bar_h = DOM.getAbsoluteTop(_elts.item(0)) or height # getAbsoluteTop can be 0 if tabBar is hidden 278 tab_bar_h = DOM.getAbsoluteTop(_elts.item(0)) or height # getAbsoluteTop can be 0 if tabBar is hidden
274 279
275 ideal_height = tab_bar_h - DOM.getAbsoluteTop(contact_panel_elt) - 5 280 ideal_height = tab_bar_h - DOM.getAbsoluteTop(contact_panel_elt) - 5
276 self.scroll_panel.setHeight("%s%s" % (ideal_height, "px")) 281 self.scroll_panel.setHeight("%s%s" % (ideal_height, "px"))
277 282
278 def updateContact(self, jid, attributes, groups): 283 def updateContact(self, jid_s, attributes, groups):
279 """Add a contact to the panel if it doesn't exist, update it else 284 """Add a contact to the panel if it doesn't exist, update it else
280 @param jid: jid userhost as unicode 285 @param jid_s: jid userhost as unicode
281 @attributes: cf SàT Bridge API's newContact 286 @param attributes: cf SàT Bridge API's newContact
282 @param groups: list of groups""" 287 @param groups: list of groups"""
283 _current_groups = self.getContactGroups(jid) 288 _current_groups = self.getContactGroups(jid_s)
284 _new_groups = set(groups) 289 _new_groups = set(groups)
285 _key = "@%s: " 290 _key = "@%s: "
286 291
287 for group in _current_groups.difference(_new_groups): 292 for group in _current_groups.difference(_new_groups):
288 # We remove the contact from the groups where he isn't anymore 293 # We remove the contact from the groups where he isn't anymore
289 self.groups[group].remove(jid) 294 self.groups[group].remove(jid_s)
290 if not self.groups[group]: 295 if not self.groups[group]:
291 # The group is now empty, we must remove it 296 # The group is now empty, we must remove it
292 del self.groups[group] 297 del self.groups[group]
293 self._groupList.remove(group) 298 self._groupList.remove(group)
294 if self.host.uni_box: 299 if self.host.uni_box:
299 if not group in self.groups.keys(): 304 if not group in self.groups.keys():
300 self.groups[group] = set() 305 self.groups[group] = set()
301 self._groupList.add(group) 306 self._groupList.add(group)
302 if self.host.uni_box: 307 if self.host.uni_box:
303 self.host.uni_box.addKey(_key % group) 308 self.host.uni_box.addKey(_key % group)
304 self.groups[group].add(jid) 309 self.groups[group].add(jid_s)
305 310
306 # We add the contact to contact list, it will check if contact already exists 311 # We add the contact to contact list, it will check if contact already exists
307 self._contact_list.add(jid) 312 self._contact_list.add(jid_s)
308 313
309 def removeContact(self, jid): 314 def removeContact(self, jid):
310 """Remove contacts from groups where he is and contact list""" 315 """Remove contacts from groups where he is and contact list"""
311 self.updateContact(jid, {}, []) # we remove contact from every group 316 self.updateContact(jid, {}, []) # we remove contact from every group
312 self._contact_list.remove(jid) 317 self._contact_list.remove(jid)
357 """ 362 """
358 contacts = self.connected.keys() 363 contacts = self.connected.keys()
359 contacts.sort() 364 contacts.sort()
360 return contacts if not filter_muc else list(set(contacts).intersection(set(self.getContacts()))) 365 return contacts if not filter_muc else list(set(contacts).intersection(set(self.getContacts())))
361 366
362 def getContactGroups(self, contact_jid): 367 def getContactGroups(self, contact_jid_s):
363 """Get groups where contact is 368 """Get groups where contact is
364 @param group: string of single group, or list of string 369 @param group: string of single group, or list of string
365 @param contact_jid: jid to test 370 @param contact_jid_s: jid to test, as unicode
366 """ 371 """
367 result = set() 372 result = set()
368 for group in self.groups: 373 for group in self.groups:
369 if self.isContactInGroup(group, contact_jid): 374 if self.isContactInGroup(group, contact_jid_s):
370 result.add(group) 375 result.add(group)
371 return result 376 return result
372 377
373 def isContactInGroup(self, group, contact_jid): 378 def isContactInGroup(self, group, contact_jid):
374 """Test if the contact_jid is in the group 379 """Test if the contact_jid is in the group