comparison 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
comparison
equal deleted inserted replaced
1377:017270e6eea4 1378:3dae6964c071
21 from sat.core.log import getLogger 21 from sat.core.log import getLogger
22 log = getLogger(__name__) 22 log = getLogger(__name__)
23 from sat_frontends.tools import jid 23 from sat_frontends.tools import jid
24 from sat_frontends.quick_frontend import quick_widgets 24 from sat_frontends.quick_frontend import quick_widgets
25 from sat_frontends.quick_frontend.constants import Const as C 25 from sat_frontends.quick_frontend.constants import Const as C
26 26 from collections import OrderedDict
27 27
28 try: 28 try:
29 # FIXME: to be removed when an acceptable solution is here 29 # FIXME: to be removed when an acceptable solution is here
30 unicode('') # XXX: unicode doesn't exist in pyjamas 30 unicode('') # XXX: unicode doesn't exist in pyjamas
31 except (TypeError, AttributeError): # Error raised is not the same depending on pyjsbuild options 31 except (TypeError, AttributeError): # Error raised is not the same depending on pyjsbuild options
32 unicode = lambda x: str(x) 32 unicode = lambda x: str(x)
33 33
34 34
35 class QuickChat(quick_widgets.QuickWidget): 35 class QuickChat(quick_widgets.QuickWidget):
36
37 visible_states = ['chat_state']
36 38
37 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, profiles=None): 39 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, profiles=None):
38 """ 40 """
39 @param type_: can be C.CHAT_ONE2ONE for single conversation or C.CHAT_GROUP for chat à la IRC 41 @param type_: can be C.CHAT_ONE2ONE for single conversation or C.CHAT_GROUP for chat à la IRC
40 """ 42 """
205 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist" 207 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist"
206 @param extra (dict): message data 208 @param extra (dict): message data
207 """ 209 """
208 raise NotImplementedError 210 raise NotImplementedError
209 211
210 def updateChatState(self, from_jid, state): 212 def updateEntityState(self, entity, type_, value):
211 """Set the chat state (XEP-0085) of the contact. 213 """Update a state value for the given entity.
212 214
213 @param state: the new chat state 215 @param entity (jid.JID): entity to update
214 """ 216 @param type_ (unicode): type of state (e.g. 'chat_state')
215 raise NotImplementedError 217 @param value (unicode): new value
218 """
219 contact_list = self.host.contact_lists[self.profile]
220 contact_list.setCache(entity, type_, value)
221 clist = self.host.contact_lists[self.profile]
222 states = OrderedDict()
223 for key in self.visible_states:
224 value = clist.getCache(entity, key)
225 if value:
226 states[key] = value
227 if self.type == C.CHAT_GROUP:
228 self.setOccupantStates(entity, states)
229 else:
230 self.setContactStates(entity, states)
216 231
217 def addGamePanel(self, widget): 232 def addGamePanel(self, widget):
218 """Insert a game panel to this Chat dialog. 233 """Insert a game panel to this Chat dialog.
219 234
220 @param widget (Widget): the game panel 235 @param widget (Widget): the game panel