diff src/browser/sat_browser/panels.py @ 574:b07f0fe2763a

browser_side: safer attributes handling in getOrCreateLiberviaWidget + use it to create MUC panels
author souliane <souliane@mailoo.org>
date Sat, 18 Oct 2014 13:16:56 +0200
parents 12823bcbd05b
children e1a773a64fb6
line wrap: on
line diff
--- a/src/browser/sat_browser/panels.py	Fri Oct 17 13:26:33 2014 +0200
+++ b/src/browser/sat_browser/panels.py	Sat Oct 18 13:16:56 2014 +0200
@@ -747,15 +747,15 @@
     def accepted_groups(self):
         return self._accepted_groups
 
-    def matchEntity(self, entity):
+    def matchEntity(self, item):
         """
-        @param entity: single group as a string, list of groups
+        @param item: single group as a string, list of groups
         (as an array) or None (for the meta group = "all groups")
         @return: True if self matches the given entity
         """
-        entity = entity if isinstance(entity, list) else ([] if entity is None else [entity])
-        entity.sort()  # sort() do not return the sorted list: do it here, not on the "return" line
-        return self.accepted_groups == entity
+        groups = item if isinstance(item, list) else ([] if item is None else [item])
+        groups.sort()  # sort() do not return the sorted list: do it here, not on the "return" line
+        return self.accepted_groups == groups
 
     def getWarningData(self, comment=None):
         """
@@ -1151,10 +1151,11 @@
         base_widget.LiberviaWidget.addDropKey("CONTACT", cls.createPanel)
 
     @classmethod
-    def createPanel(cls, host, item):
+    def createPanel(cls, host, item, type_='one2one'):
+        assert(item)
         _contact = item if isinstance(item, jid.JID) else jid.JID(item)
         host.contact_panel.setContactMessageWaiting(_contact.bare, False)
-        _new_panel = ChatPanel(host, _contact)  # XXX: pyjamas doesn't seems to support creating with cls directly
+        _new_panel = ChatPanel(host, _contact, type_)  # XXX: pyjamas doesn't seems to support creating with cls directly
         _new_panel.historyPrint()
         host.setSelected(_new_panel)
         _new_panel.refresh()
@@ -1182,17 +1183,15 @@
         else:
             self.host.showWarning(*self.getWarningData())
 
-    def matchEntity(self, entity):
+    def matchEntity(self, item, type_=None):
         """
         @param entity: target jid as a string or jid.JID instance.
         Could also be a couple with a type in the second element.
         @return: True if self matches the given entity
         """
-        if isinstance(entity, tuple):
-            entity, type_ = entity if len(entity) > 1 else (entity[0], self.type)
-        else:
+        if type_ is None:
             type_ = self.type
-        entity = entity if isinstance(entity, jid.JID) else jid.JID(entity)
+        entity = item if isinstance(item, jid.JID) else jid.JID(item)
         try:
             return self.target.bare == entity.bare and self.type == type_
         except AttributeError as e: