primitivus: display chat states (with symbols) for MUC participants
This commit is contained in:
parent
73b374f6fc
commit
67d15eb488
1 changed files with 80 additions and 41 deletions
|
|
@ -25,6 +25,7 @@ from sat_frontends.quick_frontend.quick_chat import QuickChat
|
|||
from sat_frontends.primitivus.card_game import CardGame
|
||||
from sat_frontends.quick_frontend.quick_utils import escapePrivate, unescapePrivate
|
||||
from sat_frontends.primitivus.xmlui import XMLUI
|
||||
from sat_frontends.primitivus.constants import Const
|
||||
import time
|
||||
from sat.tools.jid import JID
|
||||
|
||||
|
|
@ -175,21 +176,32 @@ class Chat(urwid.WidgetWrap, QuickChat):
|
|||
main_widget = self.pile
|
||||
self._w = main_widget
|
||||
|
||||
def updateChatState(self, state):
|
||||
"""Update the chat state of the contact.
|
||||
@param state: new state to set
|
||||
def updateChatState(self, state, nick=None):
|
||||
"""Set the chat state (XEP-0085) of the contact. Leave nick to None
|
||||
to set the state for a one2one conversation, or give a nickname or
|
||||
Const.ALL_OCCUPANTS to set the state of a participant within a MUC.
|
||||
@param state: the new chat state
|
||||
@param nick: None for one2one, the MUC user nick or Const.ALL_OCCUPANTS
|
||||
"""
|
||||
if (self.type == 'one2one'):
|
||||
if nick:
|
||||
assert(self.type == 'group')
|
||||
occupants = self.occupants if nick == Const.ALL_OCCUPANTS else [nick]
|
||||
options = self.present_wid.getAllValues()
|
||||
for index in xrange(0, len(options)):
|
||||
nick = options[index].value
|
||||
if nick in occupants:
|
||||
options[index] = (nick, '%s %s' % (Const.MUC_USER_STATES[state], nick))
|
||||
self.present_wid.changeValues(options)
|
||||
self.host.redraw()
|
||||
else:
|
||||
assert(self.type == 'one2one')
|
||||
self.__setSurrendedText(state)
|
||||
self.showDecoration()
|
||||
self.host.redraw()
|
||||
elif (self.type == 'group'):
|
||||
# TODO: chat state for groupchat
|
||||
pass
|
||||
|
||||
def _presentClicked(self, list_wid, clicked_wid):
|
||||
assert(self.type == 'group')
|
||||
nick = clicked_wid.getValue()
|
||||
nick = clicked_wid.getValue().value
|
||||
if nick == self.getUserNick():
|
||||
#We ignore click on our own nick
|
||||
return
|
||||
|
|
@ -250,9 +262,9 @@ class Chat(urwid.WidgetWrap, QuickChat):
|
|||
nick = unicode(param_nick) #FIXME: should be done in DBus bridge
|
||||
QuickChat.replaceUser(self, nick, show_info)
|
||||
presents = self.present_wid.getAllValues()
|
||||
if nick not in presents:
|
||||
if nick not in [present.value for present in presents]:
|
||||
presents.append(nick)
|
||||
presents.sort()
|
||||
presents.sort(cmp=lambda a, b: cmp(a.value if hasattr(a, 'value') else a, b.value if hasattr(b, 'value') else b))
|
||||
self.present_wid.changeValues(presents)
|
||||
self.host.redraw()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue