Mercurial > libervia-web
diff src/browser/sat_browser/contact_panel.py @ 687:3845a086f0b3
browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
- Chat uses presence and avatar listener, remove unecessary methods for MUC and contact states
- contact list doesn't add unecessary ContactBox (e.g for MUC bare entities)
- nick, message alerts are handled directly in ContactLabel
author | souliane <souliane@mailoo.org> |
---|---|
date | Mon, 23 Mar 2015 09:35:46 +0100 |
parents | 9877607c719a |
children | 7a9c7b9f6a28 |
line wrap: on
line diff
--- a/src/browser/sat_browser/contact_panel.py Fri Mar 27 00:15:42 2015 +0100 +++ b/src/browser/sat_browser/contact_panel.py Mon Mar 23 09:35:46 2015 +0100 @@ -92,66 +92,43 @@ self.clear() for contact_jid in jids: assert isinstance(contact_jid, jid.JID) - self.addContact(contact_jid) + self.updateContactBox(contact_jid) def getContactBox(self, contact_jid): - """Get a contact box for a contact, add it if it doesn't exist yet. + """Get the contact box for the given contact. + + @param contact_jid (jid.JID): contact JID + @return: ContactBox or None + """ + try: + return self._contacts[self._key(contact_jid)] + except KeyError: + return None + + def updateContactBox(self, contact_jid): + """Add a contact or update it if it already exists. @param contact_jid (jid.JID): contact JID @return: ContactBox """ - try: - return self._contacts[self._key(contact_jid)] - except KeyError: - box = contact_widget.ContactBox(self.host, contact_jid, + box = self.getContactBox(contact_jid) + if box: + box.update() + else: + entity = contact_jid.bare if self.merge_resources else contact_jid + box = contact_widget.ContactBox(self.host, entity, style_name=self.contacts_style, display=self.contacts_display, plugin_menu_context=self.contacts_menus) self._contacts[self._key(contact_jid)] = box - return box - - def addContact(self, contact_jid): - """Add a contact to the list. + VerticalPanel.append(self, box) + return box - @param contact_jid (jid.JID): contact JID - """ - box = self.getContactBox(contact_jid) - if box not in self.children: - VerticalPanel.append(self, box) - - def removeContact(self, contact_jid): - """Remove a contact from the list. + def removeContactBox(self, contact_jid): + """Remove a contact. @param contact_jid (jid.JID): contact JID """ - box = self._contacts.pop(self._key(contact_jid)) - VerticalPanel.remove(self, box) - - def updateAvatar(self, contact_jid, url): - """Update the avatar of the given contact - - @param contact_jid (jid.JID): contact JID - @param url (unicode): image url - """ - self.getContactBox(contact_jid).updateAvatar(url) - - def updateNick(self, contact_jid, new_nick): - """Update the avatar of the given contact. - - @param contact_jid (jid.JID): contact JID - @param new_nick (unicode): new nick of the contact - """ - self.getContactBox(contact_jid).updateNick(new_nick) - - def setPresence(self, entity, show): - """Update entity's presence. - - @param entity(jid.JID): entity updated - @param show: availability - """ - if self.merge_resources: # we use cache to have the show information of main resource only - clist = self.host.contact_list - show = clist.getCache(entity.bare, C.PRESENCE_SHOW) - if show is None: - show = C.PRESENCE_UNAVAILABLE - html_tools.setPresenceStyle(self.getContactBox(entity).label, show) + box = self._contacts.pop(self._key(contact_jid), None) + if box: + VerticalPanel.remove(self, box)