Mercurial > libervia-web
diff src/browser/sat_browser/chat.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 | c2f22ca12e23 |
line wrap: on
line diff
--- a/src/browser/sat_browser/chat.py Fri Mar 27 00:15:42 2015 +0100 +++ b/src/browser/sat_browser/chat.py Mon Mar 23 09:35:46 2015 +0100 @@ -105,6 +105,9 @@ # FIXME: workaround for a pyjamas issue: calling hash on a class method always return a different value if that method is defined directly within the class (with the "def" keyword) self.presenceListener = self.onPresenceUpdate self.host.addListener('presence', self.presenceListener, [C.PROF_KEY_NONE]) + self.avatarListener = self.onAvatarUpdate + host.addListener('avatar', self.avatarListener, [C.PROF_KEY_NONE]) + self._body.add(chat_area) self.content = AbsolutePanel() self.content.setStyleName('chatContent') @@ -150,7 +153,7 @@ # _new_panel.refresh() # return _new_panel - def refresh(self): + def refresh(self): # FIXME: not needed anymore since unibox has been removed """Refresh the display of this widget. If the unibox is disabled, add a message box at the bottom of the panel""" # FIXME: must be checked @@ -200,8 +203,21 @@ @param profile: %(doc_profile)s """ assert self.type == C.CHAT_GROUP - if entity.bare == self.target: - self.occupants_panel.setPresence(entity, show) + if entity.bare != self.target: + return + self.update(entity) + + def onAvatarUpdate(self, entity, hash_, profile): + """Called on avatar update events + + @param jid_: jid of the entity with updated avatar + @param hash_: hash of the avatar + @param profile: %(doc_profile)s + """ + assert self.type == C.CHAT_GROUP + if entity.bare != self.target: + return + self.update(entity) def onQuit(self): libervia_widget.LiberviaWidget.onQuit(self) @@ -209,28 +225,6 @@ self.host.removeListener('presence', self.presenceListener) self.host.bridge.call('mucLeave', None, unicode(self.target.bare)) - def setUserNick(self, nick): - """Set the nick of the user, usefull for e.g. change the color of the user""" - self.nick = nick - - def addUser(self, nick): - """Add user if it is not in the group list""" - QuickChat.addUser(self, nick) - occupant_jid = jid.JID("%s/%s" % (unicode(self.target), nick)) - self.occupants_panel.addContact(occupant_jid) - - def removeUser(self, nick): - """Remove a user from the group list""" - QuickChat.removeUser(self, nick) - occupant_jid = jid.JID("%s/%s" % (unicode(self.target), nick)) - self.occupants_panel.removeContact(occupant_jid) - - def changeUserNick(self, old_nick, new_nick): - assert self.type == C.CHAT_GROUP - # self.occupants_panel.removeOccupant(old_nick) - # self.occupants_panel.addOccupant(new_nick) - self.printInfo(_("%(old_nick)s is now known as %(new_nick)s") % {'old_nick': old_nick, 'new_nick': new_nick}) - # def historyPrint(self, size=C.HISTORY_LIMIT_DEFAULT): # """Print the initial history""" # def getHistoryCB(history): @@ -289,44 +283,36 @@ """Refresh the title of this Chat dialog @param title (unicode): main title or None to use default - @param extra (dict{unicode: unicode}): extra info + @param suffix (unicode): extra title (e.g. for chat states) or None """ if title is None: title = unicode(self.target.bare) if extra: - extra_title = ' '.join([u'({})'.format(value) for value in extra.values()]) - title = '%s %s' % (title, extra_title) + title += ' %s' % extra libervia_widget.LiberviaWidget.setTitle(self, title) - def setConnected(self, jid_s, resource, availability, priority, statuses): - """Set connection status - @param jid_s (unicode): JID userhost as unicode - """ - raise Exception("should not be there") # FIXME - assert(jid_s == self.target.bare) - if self.type != C.CHAT_GROUP: - return - box = self.occupants_panel.getOccupantBox(resource) - if box: - html_tools.setPresenceStyle(box, availability) - - def setOccupantStates(self, occupant_jid, states): - """Set a MUC occupant's states. + def update(self, entity=None): + """Update one or all entities. - @param occupant_jid (jid.JID): occupant to update - @param states (dict{unicode: unicode}): new states + @param entity (jid.JID): entity to update """ - self.occupants_panel.getContactBox(occupant_jid).updateStates(states) - if 'chat_state' in states.keys(): # start/stop sending "composing" state from now - self.chat_state_machine.started = not not states['chat_state'] + states = self.getEntityStates(self.target) + if self.type == C.CHAT_ONE2ONE: # only update the chat title + self.setTitle(extra=' '.join([u'({})'.format(value) for value in states.values()])) + else: + if entity is None: # rebuild all the occupants list + nicks = list(self.occupants) + nicks.sort() + self.occupants_panel.setList([jid.newResource(self.target, nick) for nick in nicks]) + else: # add, remove or update only one occupant + contact_list = self.host.contact_lists[self.profile] + show = contact_list.getCache(entity, C.PRESENCE_SHOW) + if show == C.PRESENCE_UNAVAILABLE or show is None: + self.occupants_panel.removeContactBox(entity) + else: + box = self.occupants_panel.updateContactBox(entity) + box.states.setHTML(u''.join(states.values())) - def setContactStates(self, contact_jid, states): - """Set a one2one contact's states. - - @param contact_jid (jid.JID): contact - @param states (dict{unicode: unicode}): new states - """ - self.setTitle(extra=states) if 'chat_state' in states.keys(): # start/stop sending "composing" state from now self.chat_state_machine.started = not not states['chat_state']