comparison src/browser/sat_browser/chat.py @ 687:3845a086f0b3

browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend: - Chat uses presence and avatar listener, remove unecessary methods for MUC and contact states - contact list doesn't add unecessary ContactBox (e.g for MUC bare entities) - nick, message alerts are handled directly in ContactLabel
author souliane <souliane@mailoo.org>
date Mon, 23 Mar 2015 09:35:46 +0100
parents 9877607c719a
children c2f22ca12e23
comparison
equal deleted inserted replaced
686:90a5a5af2550 687:3845a086f0b3
103 chat_area.add(self.occupants_panel) 103 chat_area.add(self.occupants_panel)
104 DOM.setAttribute(chat_area.getWidgetTd(self.occupants_panel), "className", "occupantsPanelCell") 104 DOM.setAttribute(chat_area.getWidgetTd(self.occupants_panel), "className", "occupantsPanelCell")
105 # FIXME: workaround for a pyjamas issue: calling hash on a class method always return a different value if that method is defined directly within the class (with the "def" keyword) 105 # FIXME: workaround for a pyjamas issue: calling hash on a class method always return a different value if that method is defined directly within the class (with the "def" keyword)
106 self.presenceListener = self.onPresenceUpdate 106 self.presenceListener = self.onPresenceUpdate
107 self.host.addListener('presence', self.presenceListener, [C.PROF_KEY_NONE]) 107 self.host.addListener('presence', self.presenceListener, [C.PROF_KEY_NONE])
108 self.avatarListener = self.onAvatarUpdate
109 host.addListener('avatar', self.avatarListener, [C.PROF_KEY_NONE])
110
108 self._body.add(chat_area) 111 self._body.add(chat_area)
109 self.content = AbsolutePanel() 112 self.content = AbsolutePanel()
110 self.content.setStyleName('chatContent') 113 self.content.setStyleName('chatContent')
111 self.content_scroll = base_panel.ScrollPanelWrapper(self.content) 114 self.content_scroll = base_panel.ScrollPanelWrapper(self.content)
112 chat_area.add(self.content_scroll) 115 chat_area.add(self.content_scroll)
148 # _new_panel.historyPrint() 151 # _new_panel.historyPrint()
149 # host.setSelected(_new_panel) 152 # host.setSelected(_new_panel)
150 # _new_panel.refresh() 153 # _new_panel.refresh()
151 # return _new_panel 154 # return _new_panel
152 155
153 def refresh(self): 156 def refresh(self): # FIXME: not needed anymore since unibox has been removed
154 """Refresh the display of this widget. If the unibox is disabled, 157 """Refresh the display of this widget. If the unibox is disabled,
155 add a message box at the bottom of the panel""" 158 add a message box at the bottom of the panel"""
156 # FIXME: must be checked 159 # FIXME: must be checked
157 # self.host.contact_panel.setContactMessageWaiting(self.target.bare, False) 160 # self.host.contact_panel.setContactMessageWaiting(self.target.bare, False)
158 # self.content_scroll.scrollToBottom() 161 # self.content_scroll.scrollToBottom()
198 @parap priority: resource's priority 201 @parap priority: resource's priority
199 @param statuses: dict of statuses 202 @param statuses: dict of statuses
200 @param profile: %(doc_profile)s 203 @param profile: %(doc_profile)s
201 """ 204 """
202 assert self.type == C.CHAT_GROUP 205 assert self.type == C.CHAT_GROUP
203 if entity.bare == self.target: 206 if entity.bare != self.target:
204 self.occupants_panel.setPresence(entity, show) 207 return
208 self.update(entity)
209
210 def onAvatarUpdate(self, entity, hash_, profile):
211 """Called on avatar update events
212
213 @param jid_: jid of the entity with updated avatar
214 @param hash_: hash of the avatar
215 @param profile: %(doc_profile)s
216 """
217 assert self.type == C.CHAT_GROUP
218 if entity.bare != self.target:
219 return
220 self.update(entity)
205 221
206 def onQuit(self): 222 def onQuit(self):
207 libervia_widget.LiberviaWidget.onQuit(self) 223 libervia_widget.LiberviaWidget.onQuit(self)
208 if self.type == C.CHAT_GROUP: 224 if self.type == C.CHAT_GROUP:
209 self.host.removeListener('presence', self.presenceListener) 225 self.host.removeListener('presence', self.presenceListener)
210 self.host.bridge.call('mucLeave', None, unicode(self.target.bare)) 226 self.host.bridge.call('mucLeave', None, unicode(self.target.bare))
211
212 def setUserNick(self, nick):
213 """Set the nick of the user, usefull for e.g. change the color of the user"""
214 self.nick = nick
215
216 def addUser(self, nick):
217 """Add user if it is not in the group list"""
218 QuickChat.addUser(self, nick)
219 occupant_jid = jid.JID("%s/%s" % (unicode(self.target), nick))
220 self.occupants_panel.addContact(occupant_jid)
221
222 def removeUser(self, nick):
223 """Remove a user from the group list"""
224 QuickChat.removeUser(self, nick)
225 occupant_jid = jid.JID("%s/%s" % (unicode(self.target), nick))
226 self.occupants_panel.removeContact(occupant_jid)
227
228 def changeUserNick(self, old_nick, new_nick):
229 assert self.type == C.CHAT_GROUP
230 # self.occupants_panel.removeOccupant(old_nick)
231 # self.occupants_panel.addOccupant(new_nick)
232 self.printInfo(_("%(old_nick)s is now known as %(new_nick)s") % {'old_nick': old_nick, 'new_nick': new_nick})
233 227
234 # def historyPrint(self, size=C.HISTORY_LIMIT_DEFAULT): 228 # def historyPrint(self, size=C.HISTORY_LIMIT_DEFAULT):
235 # """Print the initial history""" 229 # """Print the initial history"""
236 # def getHistoryCB(history): 230 # def getHistoryCB(history):
237 # # display day change 231 # # display day change
287 281
288 def setTitle(self, title=None, extra=None): 282 def setTitle(self, title=None, extra=None):
289 """Refresh the title of this Chat dialog 283 """Refresh the title of this Chat dialog
290 284
291 @param title (unicode): main title or None to use default 285 @param title (unicode): main title or None to use default
292 @param extra (dict{unicode: unicode}): extra info 286 @param suffix (unicode): extra title (e.g. for chat states) or None
293 """ 287 """
294 if title is None: 288 if title is None:
295 title = unicode(self.target.bare) 289 title = unicode(self.target.bare)
296 if extra: 290 if extra:
297 extra_title = ' '.join([u'({})'.format(value) for value in extra.values()]) 291 title += ' %s' % extra
298 title = '%s %s' % (title, extra_title)
299 libervia_widget.LiberviaWidget.setTitle(self, title) 292 libervia_widget.LiberviaWidget.setTitle(self, title)
300 293
301 def setConnected(self, jid_s, resource, availability, priority, statuses): 294 def update(self, entity=None):
302 """Set connection status 295 """Update one or all entities.
303 @param jid_s (unicode): JID userhost as unicode 296
304 """ 297 @param entity (jid.JID): entity to update
305 raise Exception("should not be there") # FIXME 298 """
306 assert(jid_s == self.target.bare) 299 states = self.getEntityStates(self.target)
307 if self.type != C.CHAT_GROUP: 300 if self.type == C.CHAT_ONE2ONE: # only update the chat title
308 return 301 self.setTitle(extra=' '.join([u'({})'.format(value) for value in states.values()]))
309 box = self.occupants_panel.getOccupantBox(resource) 302 else:
310 if box: 303 if entity is None: # rebuild all the occupants list
311 html_tools.setPresenceStyle(box, availability) 304 nicks = list(self.occupants)
312 305 nicks.sort()
313 def setOccupantStates(self, occupant_jid, states): 306 self.occupants_panel.setList([jid.newResource(self.target, nick) for nick in nicks])
314 """Set a MUC occupant's states. 307 else: # add, remove or update only one occupant
315 308 contact_list = self.host.contact_lists[self.profile]
316 @param occupant_jid (jid.JID): occupant to update 309 show = contact_list.getCache(entity, C.PRESENCE_SHOW)
317 @param states (dict{unicode: unicode}): new states 310 if show == C.PRESENCE_UNAVAILABLE or show is None:
318 """ 311 self.occupants_panel.removeContactBox(entity)
319 self.occupants_panel.getContactBox(occupant_jid).updateStates(states) 312 else:
320 if 'chat_state' in states.keys(): # start/stop sending "composing" state from now 313 box = self.occupants_panel.updateContactBox(entity)
321 self.chat_state_machine.started = not not states['chat_state'] 314 box.states.setHTML(u''.join(states.values()))
322 315
323 def setContactStates(self, contact_jid, states):
324 """Set a one2one contact's states.
325
326 @param contact_jid (jid.JID): contact
327 @param states (dict{unicode: unicode}): new states
328 """
329 self.setTitle(extra=states)
330 if 'chat_state' in states.keys(): # start/stop sending "composing" state from now 316 if 'chat_state' in states.keys(): # start/stop sending "composing" state from now
331 self.chat_state_machine.started = not not states['chat_state'] 317 self.chat_state_machine.started = not not states['chat_state']
332 318
333 def addGamePanel(self, widget): 319 def addGamePanel(self, widget):
334 """Insert a game panel to this Chat dialog. 320 """Insert a game panel to this Chat dialog.