diff src/browser/sat_browser/chat.py @ 673:e489218886d7 frontends_multi_profiles

browser_side: add attribute "merge_resources" to ContactsPanel to display the MUC occupants + override Chat.replaceUser and Chat.removeUser
author souliane <souliane@mailoo.org>
date Wed, 11 Mar 2015 19:01:27 +0100
parents b39a9eddfe56
children 849ffb24d5bf
line wrap: on
line diff
--- a/src/browser/sat_browser/chat.py	Wed Mar 11 12:50:19 2015 +0100
+++ b/src/browser/sat_browser/chat.py	Wed Mar 11 19:01:27 2015 +0100
@@ -34,6 +34,7 @@
 from pyjamas.ui.HTML import HTML
 from pyjamas.ui.KeyboardListener import KEY_ENTER, KeyboardHandler
 from pyjamas.ui.HTMLPanel import HTMLPanel
+from pyjamas import DOM
 
 from datetime import datetime
 from time import time
@@ -96,12 +97,12 @@
         chat_area = HorizontalPanel()
         chat_area.setStyleName('chatArea')
         if type_ == C.CHAT_GROUP:
-            self.occupants_panel = contact_panel.ContactsPanel(host,
+            self.occupants_panel = contact_panel.ContactsPanel(host, merge_resources=False,
                                                                contacts_style="muc_contact",
                                                                contacts_menus=(C.MENU_JID_CONTEXT),
                                                                contacts_display=('resource',))
-            self.occupants_panel.setStyleName("occupantsPanel")
             chat_area.add(self.occupants_panel)
+            DOM.setAttribute(chat_area.getWidgetTd(self.occupants_panel), "className", "occupantsPanelCell")
         self._body.add(chat_area)
         self.content = AbsolutePanel()
         self.content.setStyleName('chatContent')
@@ -204,21 +205,24 @@
         self.nick = nick
 
     def setPresents(self, nicks):
-        """Set the users presents in this room
-        @param occupants (list[unicode]): list of nicks
+        """Set the occupants of a group chat.
+
+        @param nicks (list[unicode]): sorted list of nicknames
         """
-        self.occupants_panel.setList([jid.JID(u"%s/%s" % (self.target,nick)) for nick in nicks])
+        QuickChat.setPresents(self, nicks)
+        self.occupants_panel.setList([jid.JID(u"%s/%s" % (self.target, nick)) for nick in nicks])
 
-    # def userJoined(self, nick, data):
-    #     if self.occupants_panel.getOccupantBox(nick):
-    #         return  # user is already displayed
-    #     self.occupants_panel.addOccupant(nick)
-    #     if self.occupants_initialised:
-    #         self.printInfo("=> %s has joined the room" % nick)
+    def replaceUser(self, nick, show_info=True):
+        """Add user if it is not in the group list"""
+        QuickChat.replaceUser(self, nick, show_info)
+        occupant_jid = jid.JID("%s/%s" % (unicode(self.target), nick))
+        self.occupants_panel.addContact(occupant_jid)
 
-    # def userLeft(self, nick, data):
-    #     self.occupants_panel.removeOccupant(nick)
-    #     self.printInfo("<= %s has left the room" % nick)
+    def removeUser(self, nick, show_info=True):
+        """Remove a user from the group list"""
+        QuickChat.removeUser(self, nick, show_info)
+        occupant_jid = jid.JID("%s/%s" % (unicode(self.target), nick))
+        self.occupants_panel.removeContact(occupant_jid)
 
     def changeUserNick(self, old_nick, new_nick):
         assert self.type == C.CHAT_GROUP