Mercurial > libervia-web
diff src/browser/sat_browser/contact_widget.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 | 76a67d04c63e |
line wrap: on
line diff
--- a/src/browser/sat_browser/contact_widget.py Fri Mar 27 00:15:42 2015 +0100 +++ b/src/browser/sat_browser/contact_widget.py Mon Mar 23 09:35:46 2015 +0100 @@ -50,21 +50,21 @@ HTML.__init__(self) self.host = host self.jid = jid_ - if "nick" in display: - self.nick = self.host.contact_lists[C.PROF_KEY_NONE].getCache(self.jid, "nick") self.display = display self.alert = False - self.refresh() self.setStyleName('contactLabel') - def refresh(self): - alert_html = "<strong>(*)</strong> " if self.alert else "" + def update(self): + clist = self.host.contact_list + alert_html = "<strong>(*)</strong> " if self.jid in clist._alerts else "" + contact_raw = None for disp in self.display: if disp == "jid": contact_raw = unicode(self.jid) elif disp == "nick": - contact_raw = self.nick + clist = self.host.contact_list + contact_raw = html_tools.html_sanitize(clist.getCache(self.jid, "nick")) elif disp == "bare": contact_raw = unicode(self.jid.bare) elif disp == "resource": @@ -77,26 +77,11 @@ log.error(u"Could not find a contact display for jid {jid} (display: {display})".format(jid=self.jid, display=self.display)) contact_raw = "UNNAMED" contact_html = html_tools.html_sanitize(contact_raw) + html = "%(alert)s%(contact)s" % {'alert': alert_html, 'contact': contact_html} self.setHTML(html) - def updateNick(self, new_nick): - """Change the current nick - - @param new_nick(unicode): new nick to use - """ - self.nick = new_nick - self.refresh() - - def setAlert(self, alert): - """Show a visual indicator - - @param alert: True if alert must be shown - """ - self.alert = alert - self.refresh() - class ContactMenuBar(base_widget.WidgetMenuBar): @@ -132,51 +117,35 @@ self.jid = jid_ self.label = ContactLabel(host, self.jid, display=display) self.avatar = ContactMenuBar(self, host) if plugin_menu_context else Image() - self.states = HTML("") + self.states = HTML() try: # FIXME: dirty hack to force using an Image when the menu is actually empty self.avatar.items[0] except IndexError: self.avatar = Image() - self.updateAvatar(host.getAvatarURL(self.jid.bare)) self.add(self.avatar) self.add(self.label) self.add(self.states) + self.update() self.addClickListener(self) - def setAlert(self, alert): - """Show a visual indicator. - - @param alert (bool): True if alert indicator show be shown - """ - self.label.setAlert(alert) + def update(self): + """Update the display. - def updateAvatar(self, url): - """Update the avatar. - - @param url (unicode): image url + @param with_bare (bool): if True, ignore the resource and update with bare information. """ - self.avatar.setUrl(url) + self.avatar.setUrl(self.host.getAvatarURL(self.jid)) - def updateNick(self, new_nick): - """Update the nickname. - - @param new_nick (unicode): new nickname to use - """ - self.label.updateNick(html_tools.html_sanitize(new_nick)) - - def updateStates(self, states): - """Update the states. - - @param states (dict{unicode: unicode}): new states - """ - self.states.setHTML(u''.join(states.values())) + self.label.update() + clist = self.host.contact_list + show = clist.getCache(self.jid, C.PRESENCE_SHOW) + if show is None: + show = C.PRESENCE_UNAVAILABLE + html_tools.setPresenceStyle(self.label, show) def onClick(self, sender): try: - self.parent.onClick(self.jid.bare) + self.parent.onClick(self.jid) except (AttributeError, TypeError): pass - else: - self.setAlert(False) quick_menus.QuickMenusManager.addDataCollector(C.MENU_JID_CONTEXT, lambda caller, dummy: {'jid': unicode(caller.jid.bare)})