changeset 624:9092e624bb27 frontends_multi_profiles

browser_side: fixes various issues
author souliane <souliane@mailoo.org>
date Sun, 22 Feb 2015 21:51:20 +0100
parents 4f7550a083b4
children ed9cd20260ff
files src/browser/libervia_main.py src/browser/sat_browser/blog.py src/browser/sat_browser/chat.py src/browser/sat_browser/contact_list.py src/browser/sat_browser/plugin_sec_otr.py src/browser/sat_browser/richtext.py src/common/constants.py
diffstat 7 files changed, 43 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/src/browser/libervia_main.py	Sun Feb 22 21:42:14 2015 +0100
+++ b/src/browser/libervia_main.py	Sun Feb 22 21:51:20 2015 +0100
@@ -60,7 +60,9 @@
 except ImportError:
     pass
 
-unicode = lambda s: str(s)
+
+unicode = str  # FIXME: pyjamas workaround
+
 
 MAX_MBLOG_CACHE = 500  # Max microblog entries kept in memories
 
@@ -207,7 +209,8 @@
         @return: the URL to the avatar (str)
         """
         assert isinstance(jid_, jid.JID)
-        avatar_hash = self.contact_lists[C.PROF_KEY_NONE].getCache(jid_, 'avatar')
+        contact_list = self.contact_list  # pyjamas issue: need a temporary variable to call a property's method
+        avatar_hash = contact_list.getCache(jid_, 'avatar')
         if avatar_hash is None:
             # we have no value for avatar_hash, so we request the vcard
             self.bridge.getCard(unicode(jid_), profile=C.PROF_KEY_NONE)
@@ -351,7 +354,6 @@
 
     def addContactList(self, dummy):
         contact_list = ContactList(self)
-        self.contact_lists[C.PROF_KEY_NONE] = contact_list
         self.panel.addContactList(contact_list)
         return contact_list
 
--- a/src/browser/sat_browser/blog.py	Sun Feb 22 21:42:14 2015 +0100
+++ b/src/browser/sat_browser/blog.py	Sun Feb 22 21:51:20 2015 +0100
@@ -166,7 +166,7 @@
         is_publisher = self.author == self._blog_panel.host.whoami.bare
         if is_publisher:
             self.update_label = addIcon(u"✍", "Edit this message")
-        if is_publisher or str(self.node).endswith(self._blog_panel.host.whoami.bare):
+        if is_publisher or str(self.node).endswith(unicode(self._blog_panel.host.whoami.bare)):
             self.delete_label = addIcon(u"✗", "Delete this message")
 
     def updateAvatar(self, new_avatar):
@@ -374,7 +374,10 @@
         self.vpanel = VerticalPanel()
         self.vpanel.setStyleName('microblogPanel')
         self.setWidget(self.vpanel)
-        host.addListener('avatar', self.onAvatarUpdate)
+
+        # 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)
+        self.avatarListener = self.onAvatarUpdate
+        host.addListener('avatar', self.avatarListener, [C.PROF_KEY_NONE])
 
     def __str__(self):
         return u"Blog Widget [target: {}, profile: {}]".format(self.target, self.profile)
@@ -385,17 +388,16 @@
 
     def onDelete(self):
         quick_widgets.QuickWidget.onDelete(self)
-        self.host.removeListener('avatar', self.onAvatarUpdate)
+        self.host.removeListener('avatar', self.avatarListener)
 
-    def onAvatarUpdate(self, jid_, hash_, profile):
+    def onAvatarUpdate(self, jid_, hash_):
         """Called on avatar update events
 
         @param jid_: jid of the entity with updated avatar
         @param hash_: hash of the avatar
-        @param profile: should be C.PROF_KEY_NONE
         """
-        whoami = self.host.profiles[self.profile].whoami.bare
-        if self.isJidAccepted(jid_) or jid_.bare  == whoami.bare:
+        whoami = self.host.profiles[self.profile].whoami
+        if self.isJidAccepted(jid_) or jid_.bare == whoami.bare:
             self.updateValue('avatar', jid_, hash_)
 
     def refresh(self):
@@ -567,7 +569,7 @@
         assert isinstance(sender, jid.JID) # FIXME temporary
         if (mblog_entry.type == "comment"
             or self.isJidAccepted(sender)
-            or (groups == None and sender == self.host.profiles[self.profile].whoami.bare)
+            or (groups is None and sender == self.host.profiles[self.profile].whoami.bare)
             or (groups and groups.intersection(self.accepted_groups))):
             self.addEntry(mblog_entry)
 
@@ -580,7 +582,7 @@
         _entry = MicroblogEntry(self, data)
         if _entry.type == "comment":
             comments_hash = (_entry.service, _entry.node)
-            if not comments_hash in self.comments:
+            if comments_hash not in self.comments:
                 # The comments node is not known in this panel
                 return None
             parent = self.comments[comments_hash]
--- a/src/browser/sat_browser/chat.py	Sun Feb 22 21:42:14 2015 +0100
+++ b/src/browser/sat_browser/chat.py	Sun Feb 22 21:51:20 2015 +0100
@@ -49,6 +49,9 @@
 import plugin_xep_0085
 
 
+unicode = str  # FIXME: pyjamas workaround
+
+
 class ChatText(HTMLPanel):
 
     def __init__(self, nick, mymess, msg, extra):
@@ -88,7 +91,7 @@
             host.plugins['otr'].infoTextCallback(target, cb)
         header_info = header_info_cb if (type_ == C.CHAT_ONE2ONE and 'otr' in host.plugins) else None
 
-        base_widget.LiberviaWidget.__init__(self, host, title=target.bare, info=header_info, selectable=True)
+        base_widget.LiberviaWidget.__init__(self, host, title=unicode(target.bare), info=header_info, selectable=True)
         self._body = AbsolutePanel()
         self._body.setStyleName('chatPanel_body')
         chat_area = HorizontalPanel()
@@ -206,7 +209,7 @@
     def onQuit(self):
         base_widget.LiberviaWidget.onQuit(self)
         if self.type == C.CHAT_GROUP:
-            self.host.bridge.call('mucLeave', None, self.target.bare)
+            self.host.bridge.call('mucLeave', None, unicode(self.target.bare))
 
     def setUserNick(self, nick):
         """Set the nick of the user, usefull for e.g. change the color of the user"""
@@ -338,10 +341,10 @@
 
     def refreshTitle(self):
         """Refresh the title of this Chat dialog"""
+        title = unicode(self.target.bare)
         if self._state:
-            self.setTitle(self.target.bare + " (" + self._state + ")")
-        else:
-            self.setTitle(self.target.bare)
+            title += " (%s)".format(self._state)
+        self.setTitle(title)
 
     def setConnected(self, jid_s, resource, availability, priority, statuses):
         """Set connection status
--- a/src/browser/sat_browser/contact_list.py	Sun Feb 22 21:42:14 2015 +0100
+++ b/src/browser/sat_browser/contact_list.py	Sun Feb 22 21:51:20 2015 +0100
@@ -352,7 +352,10 @@
         self.add(self.scroll_panel)
         self.setStyleName('contactList')
         Window.addWindowResizeListener(self)
-        host.addListener('avatar', self.onAvatarUpdate)
+
+        # 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)
+        self.avatarListener = self.onAvatarUpdate
+        host.addListener('avatar', self.avatarListener, [C.PROF_KEY_NONE])
 
     @property
     def profile(self):
@@ -360,7 +363,7 @@
 
     def onDelete(self):
         QuickContactList.onDelete(self)
-        self.host.removeListener('avatar', self.onAvatarUpdate)
+        self.host.removeListener('avatar', self.avatarListener)
 
     def update(self):
         ### GROUPS ###
@@ -473,10 +476,6 @@
     #         # case 2: update (or confirm) with the values of the resource which takes precedence
     #         self._contacts_panel.setState(jid_s, "availability", availability)
 
-    #     # update the connected contacts chooser live
-    #     if hasattr(self.host, "room_contacts_chooser") and self.host.room_contacts_chooser is not None:
-    #         self.host.room_contacts_chooser.resetContacts()
-
     #     self.updateVisibility([jid_s], self.getContactGroups(jid_s))
 
     def setContactMessageWaiting(self, jid, waiting):
@@ -557,12 +556,11 @@
         """
         self._contacts_panel.updateAvatar(jid_s, url)
 
-    def onAvatarUpdate(self, jid_, hash_, profile):
+    def onAvatarUpdate(self, jid_, hash_):
         """Called on avatar update events
 
         @param jid_: jid of the entity with updated avatar
         @param hash_: hash of the avatar
-        @param profile: should be C.PROF_KEY_NONE
         """
         self._contacts_panel.updateAvatar(jid_, self.host.getAvatarURL(jid_))
 
--- a/src/browser/sat_browser/plugin_sec_otr.py	Sun Feb 22 21:42:14 2015 +0100
+++ b/src/browser/sat_browser/plugin_sec_otr.py	Sun Feb 22 21:51:20 2015 +0100
@@ -264,20 +264,20 @@
         title = (AUTH_OTHER_TITLE if act == "asked" else AUTH_US_TITLE).format(jid=self.peer)
         if type_ == 'question':
             if act == 'asked':
-                def cb(question, answer=None):
-                    if question is False or not answer:  # dialog cancelled or the answer is empty
+                def cb(result, question, answer=None):
+                    if not result or not answer:  # dialog cancelled or the answer is empty
                         return
                     self.smpAuthSecret(answer, question)
                 text = (AUTH_INFO_TXT + "<i>" + AUTH_QUEST_DEFINE_TXT + "</i>" + AUTH_QUEST_DEFINE).format(eol=DIALOG_EOL)
                 dialog.PromptDialog(cb, [text, AUTH_SECRET_INPUT.format(eol=DIALOG_EOL)], title=title, AddStyleName="maxWidthLimit").show()
             else:
-                def cb(answer):
-                    if not answer:  # dialog cancelled or the answer is empty
+                def cb(result, answer):
+                    if not result or not answer:  # dialog cancelled or the answer is empty
                         self.smpAuthAbort('answered')
                         return
                     self.smpAuthSecret(answer)
                 text = (AUTH_INFO_TXT + "<i>" + AUTH_QUEST_ANSWER_TXT + "</i>" + AUTH_QUEST_ANSWER).format(eol=DIALOG_EOL, question=data)
-                dialog.PromptDialog(cb, text + AUTH_SECRET_INPUT.format(eol=DIALOG_EOL), title=title, AddStyleName="maxWidthLimit").show()
+                dialog.PromptDialog(cb, [text + AUTH_SECRET_INPUT.format(eol=DIALOG_EOL)], title=title, AddStyleName="maxWidthLimit").show()
         elif type_ == 'trust':
             self.setCurrentTrust('smp' if data else '', act)
         elif type_ == 'abort':
@@ -344,7 +344,7 @@
         log.debug(u"getContextForUser [%s]" % other_jid)
         if not other_jid.resource:
             log.error("getContextForUser called with a bare jid")
-            running_sessions = [jid_.bareJID() for jid_ in self.contexts.keys() if self.contexts[jid_].state == otr.context.STATE_ENCRYPTED]
+            running_sessions = [jid_.bare for jid_ in self.contexts.keys() if self.contexts[jid_].state == otr.context.STATE_ENCRYPTED]
             if start or (other_jid in running_sessions):
                 users_ml = DIALOG_USERS_ML.format(subject=D_("OTR issue in Libervia: getContextForUser called with a bare jid in an encrypted context"))
                 text = RESOURCE_ISSUE.format(eol=DIALOG_EOL, jid=other_jid, users_ml=users_ml)
@@ -485,7 +485,7 @@
         return False  # interrupt the main process
 
     def presenceReceivedTrigger(self, entity, show, priority, statuses):
-        if show == "unavailable":
+        if show == C.PRESENCE_UNAVAILABLE:
             self.endSession(entity, finish=True)
         return True
 
@@ -542,7 +542,8 @@
 
         try:
             other_jid = menu_data['jid']
-            if other_jid.bare not in self.host.contact_panel.connected:
+            contact_list = self.host.contact_list
+            if contact_list.getCache(other_jid.bare, C.PRESENCE_SHOW) is None:
                 dialog.InfoDialog(ACTION_NA_TITLE, ACTION_NA, AddStyleName="maxWidthLimit").show()
                 return
             self.fixResource(other_jid, cb)
--- a/src/browser/sat_browser/richtext.py	Sun Feb 22 21:42:14 2015 +0100
+++ b/src/browser/sat_browser/richtext.py	Sun Feb 22 21:51:20 2015 +0100
@@ -442,7 +442,7 @@
             setText()
             return True
         if recipients is None:
-            recipients = self.recipient.getContacts()
+            recipients = self.recipient.getItemsByKey()
         target = ""
         # we could eventually allow more in the future
         allowed = 1
@@ -487,7 +487,7 @@
 
     def __sendMessage(self):
         """Send the message."""
-        recipients = self.recipient.getContacts()
+        recipients = self.recipient.getItemsByKey()
         targets = []
         for addr in recipients:
             for recipient in recipients[addr]:
@@ -518,7 +518,7 @@
         list_ = []
         list_.append("@@")
         list_.extend("@%s" % group for group in parent.host.contact_panel.getGroups())
-        list_.extend(contact for contact in parent.host.contact_panel.getContacts())
+        list_.extend(contact for contact in parent.host.contact_list.roster_entities)
         list_manager.ListManager.__init__(self, parent, composition.RECIPIENT_TYPES, list_, {'y': y_offset})
 
         self.registerPopupMenuPanel(entries=composition.RECIPIENT_TYPES,
--- a/src/common/constants.py	Sun Feb 22 21:42:14 2015 +0100
+++ b/src/common/constants.py	Sun Feb 22 21:51:20 2015 +0100
@@ -18,7 +18,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from sat.core.i18n import D_
-from sat_frontends import constants
+from sat_frontends.quick_frontend import constants
 import os.path