Mercurial > libervia-web
diff src/browser/sat_browser/contact_panel.py @ 684:e876f493dccc
browser_side: follow changes made on quick_frontend for chat states and MUC symbols + minor fixes following the refactorisation:
- some MUC handlers are no more needed, the presence handler is enough
- move the chat states logic to quick_frontend
- display MUC games symbols
- remove classes contact_list.ContactsPanel, contact_panel.Occupant and contact_panel.OccupantsList
- move buildPresenceStyle and setPresenceStyle to html_tools
- fixes games menu callback
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 18 Mar 2015 10:17:04 +0100 |
parents | 849ffb24d5bf |
children | 9877607c719a |
line wrap: on
line diff
--- a/src/browser/sat_browser/contact_panel.py Thu Mar 19 20:41:46 2015 +0100 +++ b/src/browser/sat_browser/contact_panel.py Wed Mar 18 10:17:04 2015 +0100 @@ -24,58 +24,13 @@ log = getLogger(__name__) from sat_frontends.tools import jid -from pyjamas.ui.AbsolutePanel import AbsolutePanel from pyjamas.ui.VerticalPanel import VerticalPanel -from pyjamas.ui.HTML import HTML import html_tools import contact_widget from constants import Const as C -# FIXME: must be removed -class Occupant(HTML): - """Occupant of a MUC room""" - - def __init__(self, nick, state=None, special=""): - """ - @param nick: the user nickname - @param state: the user chate state (XEP-0085) - @param special: a string of symbols (e.g: for activities) - """ - HTML.__init__(self, StyleName="occupant") - self.nick = nick - self._state = state - self.special = special - self._refresh() - - def __str__(self): - return self.nick - - def setState(self, state): - self._state = state - self._refresh() - - def addSpecial(self, special): - """@param special: unicode""" - if special not in self.special: - self.special += special - self._refresh() - - def removeSpecials(self, special): - """@param special: unicode or list""" - if not isinstance(special, list): - special = [special] - for symbol in special: - self.special = self.special.replace(symbol, "") - self._refresh() - - def _refresh(self): - state = (' %s' % C.MUC_USER_STATES[self._state]) if self._state else '' - special = "" if len(self.special) == 0 else " %s" % self.special - self.setHTML("%s%s%s" % (html_tools.html_sanitize(self.nick), special, state)) - - class ContactsPanel(VerticalPanel): """ContactList graphic representation @@ -118,6 +73,11 @@ """ return contact_jid.bare if self.merge_resources else contact_jid + def clear(self): + """Clear all contacts.""" + self._contacts.clear() + VerticalPanel.clear(self) + def setList(self, jids): """set all contacts in the list in one shot. @@ -173,10 +133,7 @@ @param contact_jid (jid.JID): contact JID @param url (unicode): image url """ - try: - self.getContactBox(contact_jid).updateAvatar(url) - except TypeError: - pass + self.getContactBox(contact_jid).updateAvatar(url) def updateNick(self, contact_jid, new_nick): """Update the avatar of the given contact. @@ -184,64 +141,17 @@ @param contact_jid (jid.JID): contact JID @param new_nick (unicode): new nick of the contact """ - try: - self.getContactBox(contact_jid).updateNick(new_nick) - except TypeError: - pass - - - -# FIXME: must be removed and ContactsPanel must be used instead -class OccupantsList(AbsolutePanel): - """Panel user to show occupants of a room""" + self.getContactBox(contact_jid).updateNick(new_nick) - def __init__(self): - AbsolutePanel.__init__(self) - self.occupants_list = {} - self.setStyleName('occupantsList') - - def addOccupant(self, nick): - if nick in self.occupants_list: - return - _occupant = Occupant(nick) - self.occupants_list[nick] = _occupant - self.add(_occupant) - - def removeOccupant(self, nick): - try: - self.remove(self.occupants_list[nick]) - except KeyError: - log.error("trying to remove an unexisting nick") + def setPresence(self, entity, show): + """Update entity's presence. - def getOccupantBox(self, nick): - """Get the widget element of the given nick. - - @return: Occupant + @param entity(jid.JID): entity updated + @param show: availability """ - try: - return self.occupants_list[nick] - except KeyError: - return None - - def clear(self): - self.occupants_list.clear() - AbsolutePanel.clear(self) - - def updateSpecials(self, occupants=[], html=""): - """Set the specified html "symbol" to the listed occupants, - and eventually remove it from the others (if they got it). - This is used for example to visualize who is playing a game. - @param occupants: list of the occupants that need the symbol - @param html: unicode symbol (actually one character or more) - or a list to assign different symbols of the same family. - """ - index = 0 - special = html - for occupant in self.occupants_list.keys(): - if occupant in occupants: - if isinstance(html, list): - special = html[index] - index = (index + 1) % len(html) - self.occupants_list[occupant].addSpecial(special) - else: - self.occupants_list[occupant].removeSpecials(html) + 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)