comparison frontends/src/primitivus/chat.py @ 2020:f67da1cab6d3

quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling: - occupants can be clicked again - QuickChat.Occupant now keep room jid and real jid if available - history messages are filtered correctly when requesting history for MUC room or private conversation
author Goffi <goffi@goffi.org>
date Sun, 24 Jul 2016 18:07:45 +0200
parents 7199e6bdb94e
children 88c41a195728
comparison
equal deleted inserted replaced
2019:c0ff84243650 2020:f67da1cab6d3
27 from sat_frontends.quick_frontend import quick_games 27 from sat_frontends.quick_frontend import quick_games
28 from sat_frontends.primitivus import game_tarot 28 from sat_frontends.primitivus import game_tarot
29 from sat_frontends.primitivus.constants import Const as C 29 from sat_frontends.primitivus.constants import Const as C
30 from sat_frontends.primitivus.keys import action_key_map as a_key 30 from sat_frontends.primitivus.keys import action_key_map as a_key
31 from sat_frontends.primitivus.widget import PrimitivusWidget 31 from sat_frontends.primitivus.widget import PrimitivusWidget
32 from sat_frontends.primitivus.contact_list import ContactList
32 import time 33 import time
33 import locale 34 import locale
34 from sat_frontends.tools import jid
35 from functools import total_ordering 35 from functools import total_ordering
36 import bisect 36 import bisect
37 37
38 38
39 OCCUPANTS_FOOTER = _(u"{} occupants") 39 OCCUPANTS_FOOTER = _(u"{} occupants")
139 139
140 def __init__(self, occupant_data): 140 def __init__(self, occupant_data):
141 self.occupant_data = occupant_data 141 self.occupant_data = occupant_data
142 occupant_data.widgets.add(self) 142 occupant_data.widgets.add(self)
143 markup = self._generateMarkup() 143 markup = self._generateMarkup()
144 super(OccupantWidget, self).__init__(urwid.Text(markup)) 144 text = sat_widgets.ClickableText(markup)
145 urwid.connect_signal(text,
146 'click',
147 self.occupant_data.parent._occupantsClicked,
148 user_args=[self.occupant_data])
149 super(OccupantWidget, self).__init__(text)
145 150
146 def __eq__(self, other): 151 def __eq__(self, other):
147 if other is None: 152 if other is None:
148 return False 153 return False
149 return self.occupant_data.nick == other.occupant_data.nick 154 return self.occupant_data.nick == other.occupant_data.nick
257 262
258 # we must adapt the behaviour with the type 263 # we must adapt the behaviour with the type
259 if type_ == C.CHAT_GROUP: 264 if type_ == C.CHAT_GROUP:
260 if len(self.chat_colums.contents) == 1: 265 if len(self.chat_colums.contents) == 1:
261 self.occupants_widget = OccupantsWidget(self) 266 self.occupants_widget = OccupantsWidget(self)
262 # FIXME
263 # , option_type=sat_widgets.ClickableText, on_click=self._occupantsClicked)
264 self.occupants_panel = sat_widgets.VerticalSeparator(self.occupants_widget) 267 self.occupants_panel = sat_widgets.VerticalSeparator(self.occupants_widget)
265 self._appendOccupantsPanel() 268 self._appendOccupantsPanel()
266 self.host.addListener('presence', self.presenceListener, [profiles]) 269 self.host.addListener('presence', self.presenceListener, [profiles])
267 270
268 # focus marker is a separator indicated last visible message before focus was lost 271 # focus marker is a separator indicated last visible message before focus was lost
471 def removeUser(self, occupant_data): 474 def removeUser(self, occupant_data):
472 occupant = super(Chat, self).removeUser(occupant_data) 475 occupant = super(Chat, self).removeUser(occupant_data)
473 if occupant is not None: 476 if occupant is not None:
474 self.occupants_widget.removeUser(occupant) 477 self.occupants_widget.removeUser(occupant)
475 478
476 def _occupantsClicked(self, list_wid, clicked_wid): 479 def _occupantsClicked(self, occupant, clicked_wid):
477 # FIXME: not called anymore after refactoring
478 assert self.type == C.CHAT_GROUP 480 assert self.type == C.CHAT_GROUP
479 nick = clicked_wid.getValue().value
480 if nick == self.nick:
481 # We ignore clicks on our own nick
482 return
483 contact_list = self.host.contact_lists[self.profile] 481 contact_list = self.host.contact_lists[self.profile]
484 full_jid = jid.JID("%s/%s" % (self.target.bare, nick))
485 482
486 # we have a click on a nick, we need to create the widget if it doesn't exists 483 # we have a click on a nick, we need to create the widget if it doesn't exists
487 self.getOrCreatePrivateWidget(full_jid) 484 self.getOrCreatePrivateWidget(occupant.jid)
488 485
489 # now we select the new window 486 # now we select the new window
490 contact_list.setFocus(full_jid, True) 487 for contact_list in self.host.widgets.getWidgets(ContactList, profiles=(self.profile,)):
488 contact_list.setFocus(occupant.jid, True)
491 489
492 def _appendOccupantsPanel(self): 490 def _appendOccupantsPanel(self):
493 self.chat_colums.contents.append((self.occupants_panel, ('weight', 2, False))) 491 self.chat_colums.contents.append((self.occupants_panel, ('weight', 2, False)))
494 492
495 def _removeOccupantsPanel(self): 493 def _removeOccupantsPanel(self):