quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
This commit is contained in:
parent
1a03845539
commit
78f14091b1
3 changed files with 96 additions and 54 deletions
|
|
@ -534,6 +534,7 @@ class QuickApp(object):
|
|||
chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile)
|
||||
chat_widget.setUserNick(unicode(user_nick))
|
||||
self.contact_lists[profile].setSpecial(room_jid, C.CONTACT_SPECIAL_GROUP)
|
||||
chat_widget.update()
|
||||
|
||||
def roomLeftHandler(self, room_jid_s, profile):
|
||||
"""Called when a MUC room is left"""
|
||||
|
|
@ -579,16 +580,20 @@ class QuickApp(object):
|
|||
@param state (unicode): new state
|
||||
@param profile (unicode): current profile
|
||||
"""
|
||||
log.debug(_(u"Received new chat state {} from {} [{}]").format(state, from_jid_s, profile))
|
||||
from_jid = jid.JID(from_jid_s) if from_jid_s != C.ENTITY_ALL else C.ENTITY_ALL
|
||||
contact_list = self.contact_lists[profile]
|
||||
for widget in self.widgets.getWidgets(quick_chat.QuickChat):
|
||||
if profile != widget.profile:
|
||||
continue
|
||||
to_display = C.USER_CHAT_STATES[state] if (state and widget.type == C.CHAT_GROUP) else state
|
||||
if widget.type == C.CHAT_GROUP and from_jid_s == C.ENTITY_ALL:
|
||||
for occupant in [jid.newResource(widget.target, nick) for nick in widget.occupants]:
|
||||
widget.updateEntityState(occupant, 'chat_state', to_display)
|
||||
contact_list.setCache(occupant, 'chat_state', to_display)
|
||||
widget.update(occupant)
|
||||
elif from_jid.bare == widget.target.bare: # roster contact or MUC occupant
|
||||
widget.updateEntityState(from_jid, 'chat_state', to_display)
|
||||
contact_list.setCache(from_jid, 'chat_state', to_display)
|
||||
widget.update(from_jid)
|
||||
|
||||
def personalEventHandler(self, sender, event_type, data):
|
||||
"""Called when a PEP event is received.
|
||||
|
|
|
|||
|
|
@ -206,30 +206,19 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def updateEntityState(self, entity, type_, value):
|
||||
"""Update a state value for the given entity.
|
||||
def getEntityStates(self, entity):
|
||||
"""Retrieve states for an entity.
|
||||
|
||||
@param entity (jid.JID): entity to update
|
||||
@param type_ (unicode): type of state (e.g. 'chat_state')
|
||||
@param value (unicode): new value
|
||||
@param entity (jid.JID): entity
|
||||
@return: OrderedDict{unicode: unicode}
|
||||
"""
|
||||
contact_list = self.host.contact_lists[self.profile]
|
||||
contact_list.setCache(entity, type_, value)
|
||||
clist = self.host.contact_lists[self.profile]
|
||||
states = OrderedDict()
|
||||
clist = self.host.contact_lists[self.profile]
|
||||
for key in self.visible_states:
|
||||
value = clist.getCache(entity, key)
|
||||
if value:
|
||||
states[key] = value
|
||||
self.setContactStates(entity, states)
|
||||
|
||||
def setContactStates(self, contact_jid, states):
|
||||
"""Set a contact (one2one or MUC occupant) states.
|
||||
|
||||
@param contact_jid (jid.JID): contact
|
||||
@param states (dict{unicode: unicode}): new states
|
||||
"""
|
||||
raise NotImplementedError
|
||||
return states
|
||||
|
||||
def addGamePanel(self, widget):
|
||||
"""Insert a game panel to this Chat dialog.
|
||||
|
|
@ -245,5 +234,12 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def update(self, entity=None):
|
||||
"""Update one or all entities.
|
||||
|
||||
@param entity (jid.JID): entity to update
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
quick_widgets.register(QuickChat)
|
||||
|
|
|
|||
|
|
@ -59,12 +59,11 @@ class RoomGame(object):
|
|||
chat_widget.visible_states.append(cls._game_name)
|
||||
symbols = games.SYMBOLS[cls._game_name]
|
||||
index = 0
|
||||
contact_list = host.contact_lists[profile]
|
||||
for occupant in chat_widget.occupants:
|
||||
occupant_jid = jid.newResource(room_jid, occupant)
|
||||
if occupant in players:
|
||||
chat_widget.updateEntityState(occupant_jid, cls._game_name, symbols[index % len(symbols)])
|
||||
else:
|
||||
chat_widget.updateEntityState(occupant_jid, cls._game_name, None)
|
||||
contact_list.setCache(occupant_jid, cls._game_name, symbols[index % len(symbols)] if occupant in players else None)
|
||||
chat_widget.update(occupant_jid)
|
||||
|
||||
if suffix == "Players" or chat_widget.nick not in players:
|
||||
return # waiting for other players to join, or not playing
|
||||
|
|
|
|||
Loading…
Reference in a new issue