Mercurial > libervia-backend
diff frontends/src/quick_frontend/quick_chat.py @ 1378:3dae6964c071
quick_frontends, primitivus: move the chat states logic to quick_frontend
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 20 Mar 2015 16:28:19 +0100 |
parents | 017270e6eea4 |
children | da2ea16fabc6 |
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_chat.py Fri Mar 20 16:25:38 2015 +0100 +++ b/frontends/src/quick_frontend/quick_chat.py Fri Mar 20 16:28:19 2015 +0100 @@ -23,7 +23,7 @@ from sat_frontends.tools import jid from sat_frontends.quick_frontend import quick_widgets from sat_frontends.quick_frontend.constants import Const as C - +from collections import OrderedDict try: # FIXME: to be removed when an acceptable solution is here @@ -34,6 +34,8 @@ class QuickChat(quick_widgets.QuickWidget): + visible_states = ['chat_state'] + def __init__(self, host, target, type_=C.CHAT_ONE2ONE, profiles=None): """ @param type_: can be C.CHAT_ONE2ONE for single conversation or C.CHAT_GROUP for chat à la IRC @@ -207,12 +209,25 @@ """ raise NotImplementedError - def updateChatState(self, from_jid, state): - """Set the chat state (XEP-0085) of the contact. + def updateEntityState(self, entity, type_, value): + """Update a state value for the given entity. - @param state: the new chat state + @param entity (jid.JID): entity to update + @param type_ (unicode): type of state (e.g. 'chat_state') + @param value (unicode): new value """ - raise NotImplementedError + contact_list = self.host.contact_lists[self.profile] + contact_list.setCache(entity, type_, value) + clist = self.host.contact_lists[self.profile] + states = OrderedDict() + for key in self.visible_states: + value = clist.getCache(entity, key) + if value: + states[key] = value + if self.type == C.CHAT_GROUP: + self.setOccupantStates(entity, states) + else: + self.setContactStates(entity, states) def addGamePanel(self, widget): """Insert a game panel to this Chat dialog.