changeset 839:09ace5cbcb9b

browser (games, menu): rename showFailureRoomInvalid to onJoinMUCFailure and display a nice message when the room has already been joined (it is not a real error)
author souliane <souliane@mailoo.org>
date Wed, 13 Jan 2016 13:11:44 +0100
parents ab87da500820
children 73cc4658f431
files src/browser/libervia_main.py src/browser/sat_browser/game_radiocol.py src/browser/sat_browser/game_tarot.py src/browser/sat_browser/menu.py
diffstat 4 files changed, 14 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/browser/libervia_main.py	Tue Jan 12 20:34:20 2016 +0100
+++ b/src/browser/libervia_main.py	Wed Jan 13 13:11:44 2016 +0100
@@ -692,13 +692,19 @@
         title = err_obj['message']['faultString'] if isinstance(err_obj['message'], dict) else err_obj['message']
         self.showDialog(msg, title, 'error')
 
-    def showFailureRoomInvalid(self, err_data):
-        """Show a failure that has been returned when trying to join an invalid room.
+    def onJoinMUCFailure(self, err_data):
+        """Show a failure that has been returned when trying to join a room.
 
         @param failure (defer.Failure): Failure instance
         """
         # FIXME: remove asap, see self.showFailure
-        msg = _(u"Invalid room identifier. Please give a room short or full identifier like 'room' or '%s'.") % self.default_muc
+        err_code, err_obj = err_data
+        if err_obj["data"] == "AlreadyJoinedRoom":
+            msg = _(u"The room has already been joined.")
+            err_obj["message"] = _(u"Information")
+        else:
+            msg = _(u"Invalid room identifier. Please give a room short or full identifier like 'room' or '%s'.") % self.default_muc
+            err_obj["message"] = _(u"Error")
         self.showFailure(err_data, msg)
 
 
--- a/src/browser/sat_browser/game_radiocol.py	Tue Jan 12 20:34:20 2016 +0100
+++ b/src/browser/sat_browser/game_radiocol.py	Wed Jan 13 13:11:44 2016 +0100
@@ -257,7 +257,7 @@
         help_msg = """Accepted file formats: Ogg Vorbis (recommended), MP3.<br />
         Please do not submit files that are protected by copyright.<br />
         Click <a style="color: red;">here</a> if you need some support :)"""
-        link_cb = lambda: self._parent.host.bridge.joinMUC(self._parent.host.default_muc, self._parent.nick, profile=C.PROF_KEY_NONE, callback=lambda dummy: None, errback=self.host.showFailureRoomInvalid)
+        link_cb = lambda: self._parent.host.bridge.joinMUC(self._parent.host.default_muc, self._parent.nick, profile=C.PROF_KEY_NONE, callback=lambda dummy: None, errback=self._parent.host.onJoinMUCFailure)
         self._parent.printInfo(help_msg, type_='link', link_cb=link_cb)
 
     def pushNextSong(self, title):
@@ -333,7 +333,7 @@
         def callback(room_jid, contacts):
             contacts = [unicode(contact) for contact in contacts]
             room_jid_s = unicode(room_jid) if room_jid else ''
-            host.bridge.launchRadioCollective(contacts, room_jid_s, profile=C.PROF_KEY_NONE, callback=lambda dummy: None, errback=host.showFailureRoomInvalid)
+            host.bridge.launchRadioCollective(contacts, room_jid_s, profile=C.PROF_KEY_NONE, callback=lambda dummy: None, errback=host.onJoinMUCFailure)
         dialog.RoomAndContactsChooser(host, callback, ok_button="Choose", title="Collective Radio", visible=(False, True))
 
 
--- a/src/browser/sat_browser/game_tarot.py	Tue Jan 12 20:34:20 2016 +0100
+++ b/src/browser/sat_browser/game_tarot.py	Wed Jan 13 13:11:44 2016 +0100
@@ -400,7 +400,7 @@
         def onPlayersSelected(room_jid, other_players):
             other_players = [unicode(contact) for contact in other_players]
             room_jid_s = unicode(room_jid) if room_jid else ''
-            host.bridge.launchTarotGame(other_players, room_jid_s, profile=C.PROF_KEY_NONE, callback=lambda dummy: None, errback=host.showFailureRoomInvalid)
+            host.bridge.launchTarotGame(other_players, room_jid_s, profile=C.PROF_KEY_NONE, callback=lambda dummy: None, errback=host.onJoinMUCFailure)
         dialog.RoomAndContactsChooser(host, onPlayersSelected, 3, title="Tarot", title_invite=_(u"Please select 3 other players"), visible=(False, True))
 
     def gotMenus():
--- a/src/browser/sat_browser/menu.py	Tue Jan 12 20:34:20 2016 +0100
+++ b/src/browser/sat_browser/menu.py	Wed Jan 13 13:11:44 2016 +0100
@@ -91,7 +91,7 @@
                 contact_list = self.host.contact_list
                 if room_jid is None or room_jid not in contact_list.getSpecials(C.CONTACT_SPECIAL_GROUP):
                     room_jid_s = unicode(room_jid) if room_jid else ''
-                    self.host.bridge.joinMUC(room_jid_s, nick, profile=C.PROF_KEY_NONE, callback=lambda room_jid: invite(room_jid, contacts), errback=self.host.showFailureRoomInvalid)
+                    self.host.bridge.joinMUC(room_jid_s, nick, profile=C.PROF_KEY_NONE, callback=lambda room_jid: invite(room_jid, contacts), errback=self.host.onJoinMUCFailure)
                 else:
                     self.host.displayWidget(chat.Chat, room_jid, type_="group")
                     invite(room_jid, contacts)
@@ -103,7 +103,7 @@
 
     def onOfficialChatRoom(self):
         nick = self.host.whoami.node
-        self.host.bridge.joinMUC(self.host.default_muc, nick, profile=C.PROF_KEY_NONE, callback=lambda dummy: None, errback=self.host.showFailureRoomInvalid)
+        self.host.bridge.joinMUC(self.host.default_muc, nick, profile=C.PROF_KEY_NONE, callback=lambda dummy: None, errback=self.host.onJoinMUCFailure)
 
     def onSocialContract(self):
         _frame = Frame('contrat_social.html')