comparison src/browser/sat_browser/chat.py @ 944:5d9f6d25c586

browser: various fixes this is a first pass to fix main Libervia features which have been broken with changes in backend: - fixed Chat signature - added/removed/replaced a couple of missing methods - use contact_list_widget instead of contact_list when needed
author Goffi <goffi@goffi.org>
date Fri, 19 May 2017 17:03:04 +0200
parents 0c0551967bdf
children fd4eae654182
comparison
equal deleted inserted replaced
943:aacda981c348 944:5d9f6d25c586
92 self.setStyleName('chatText') 92 self.setStyleName('chatText')
93 93
94 94
95 class Chat(QuickChat, libervia_widget.LiberviaWidget, KeyboardHandler): 95 class Chat(QuickChat, libervia_widget.LiberviaWidget, KeyboardHandler):
96 96
97 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, profiles=None): 97 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, nick=None, occupants=None, subject=None, profiles=None):
98 """Panel used for conversation (one 2 one or group chat) 98 """Panel used for conversation (one 2 one or group chat)
99 99
100 @param host: SatWebFrontend instance 100 @param host: SatWebFrontend instance
101 @param target: entity (jid.JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room) 101 @param target: entity (jid.JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room)
102 @param type: one2one for simple conversation, group for MUC 102 @param type: one2one for simple conversation, group for MUC
103 """ 103 """
104 QuickChat.__init__(self, host, target, type_, profiles=profiles) 104 QuickChat.__init__(self, host, target, type_, nick, occupants, subject, profiles=profiles)
105 self.vpanel = VerticalPanel() 105 self.vpanel = VerticalPanel()
106 self.vpanel.setSize('100%', '100%') 106 self.vpanel.setSize('100%', '100%')
107 107
108 # FIXME: temporary dirty initialization to display the OTR state 108 # FIXME: temporary dirty initialization to display the OTR state
109 header_info = host.plugins['otr'].getInfoTextForUser(target) if (type_ == C.CHAT_ONE2ONE and 'otr' in host.plugins) else None 109 header_info = host.plugins['otr'].getInfoTextForUser(target) if (type_ == C.CHAT_ONE2ONE and 'otr' in host.plugins) else None
125 self.host.addListener('presence', self.presenceListener, [C.PROF_KEY_NONE]) 125 self.host.addListener('presence', self.presenceListener, [C.PROF_KEY_NONE])
126 self.avatarListener = self.onAvatarUpdate 126 self.avatarListener = self.onAvatarUpdate
127 host.addListener('avatar', self.avatarListener, [C.PROF_KEY_NONE]) 127 host.addListener('avatar', self.avatarListener, [C.PROF_KEY_NONE])
128 Window.addWindowResizeListener(self) 128 Window.addWindowResizeListener(self)
129 129
130 else:
131 self.chat_state = None
132
130 self._body.add(chat_area) 133 self._body.add(chat_area)
131 self.content = AbsolutePanel() 134 self.content = AbsolutePanel()
132 self.content.setStyleName('chatContent') 135 self.content.setStyleName('chatContent')
133 self.content_scroll = base_panel.ScrollPanelWrapper(self.content) 136 self.content_scroll = base_panel.ScrollPanelWrapper(self.content)
134 chat_area.add(self.content_scroll) 137 chat_area.add(self.content_scroll)
281 title = unicode(self.target.bare) 284 title = unicode(self.target.bare)
282 if extra: 285 if extra:
283 title += ' %s' % extra 286 title += ' %s' % extra
284 libervia_widget.LiberviaWidget.setTitle(self, title) 287 libervia_widget.LiberviaWidget.setTitle(self, title)
285 288
289 def onChatState(self, from_jid, state, profile):
290 super(Chat, self).onChatState(from_jid, state, profile)
291 if self.type == C.CHAT_ONE2ONE:
292 self.title_dynamic = C.CHAT_STATE_ICON[state]
293
286 def update(self, entity=None): 294 def update(self, entity=None):
287 """Update one or all entities. 295 """Update one or all entities.
288 296
289 @param entity (jid.JID): entity to update 297 @param entity (jid.JID): entity to update
290 """ 298 """
291 states = self.getEntityStates(self.target)
292 if self.type == C.CHAT_ONE2ONE: # only update the chat title 299 if self.type == C.CHAT_ONE2ONE: # only update the chat title
293 self.setTitle(extra=' '.join([u'({})'.format(value) for value in states.values()])) 300 if self.chat_state:
301 self.setTitle(extra='({})'.format(self.chat_state))
294 else: 302 else:
295 if entity is None: # rebuild all the occupants list 303 if entity is None: # rebuild all the occupants list
296 nicks = list(self.occupants) 304 nicks = list(self.occupants)
297 nicks.sort() 305 nicks.sort()
298 self.occupants_panel.setList([jid.newResource(self.target, nick) for nick in nicks]) 306 self.occupants_panel.setList([jid.newResource(self.target, nick) for nick in nicks])
300 contact_list = self.host.contact_lists[self.profile] 308 contact_list = self.host.contact_lists[self.profile]
301 show = contact_list.getCache(entity, C.PRESENCE_SHOW) 309 show = contact_list.getCache(entity, C.PRESENCE_SHOW)
302 if show == C.PRESENCE_UNAVAILABLE or show is None: 310 if show == C.PRESENCE_UNAVAILABLE or show is None:
303 self.occupants_panel.removeContactBox(entity) 311 self.occupants_panel.removeContactBox(entity)
304 else: 312 else:
305 box = self.occupants_panel.updateContactBox(entity) 313 pass
306 box.states.setHTML(u''.join(states.values())) 314 # FIXME: legacy code, chat state must be checked
307 315 # box = self.occupants_panel.updateContactBox(entity)
308 if 'chat_state' in states.keys(): # start/stop sending "composing" state from now 316 # box.states.setHTML(u''.join(states.values()))
309 self.chat_state_machine.started = not not states['chat_state'] 317
318 # FIXME: legacy code, chat state must be checked
319 # if 'chat_state' in states.keys(): # start/stop sending "composing" state from now
320 # self.chat_state_machine.started = not not states['chat_state']
310 321
311 self.onWindowResized() # be sure to set the good height 322 self.onWindowResized() # be sure to set the good height
312 323
313 def addGamePanel(self, widget): 324 def addGamePanel(self, widget):
314 """Insert a game panel to this Chat dialog. 325 """Insert a game panel to this Chat dialog.