changeset 405:10b4f577d0c0

MUC update to follow wokkel's MUC branch update - bridge methods have been updated (API change) - plugin XEP-0045 has been updated
author Goffi <goffi@goffi.org>
date Sat, 08 Oct 2011 18:43:17 +0200
parents 6a1c6c41b91b
children b03b38b20c18
files frontends/src/bridge/DBus.py frontends/src/primitivus/primitivus frontends/src/quick_frontend/quick_app.py frontends/src/wix/main_window.py src/bridge/bridge_constructor/dbus_frontend_template.py src/plugins/plugin_xep_0045.py
diffstat 6 files changed, 58 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/bridge/DBus.py	Sat Oct 08 11:19:25 2011 +0200
+++ b/frontends/src/bridge/DBus.py	Sat Oct 08 18:43:17 2011 +0200
@@ -160,14 +160,16 @@
 
 
 #methods from plugins
-    def getRoomJoined(self, profile_key='@DEFAULT@'):
-        return self.db_plugin_iface.getRoomJoined(profile_key)
+    def getRoomsJoined(self, profile_key='@DEFAULT@'):
+        return self.db_plugin_iface.getRoomsJoined(profile_key)
 
-    def getRoomSubjects(self, profile_key='@DEFAULT@'):
-        return self.db_plugin_iface.getRoomSubjects(profile_key)
+    def getRoomsSubjectss(self, profile_key='@DEFAULT@'):
+        return self.db_plugin_iface.getRoomsSubjectss(profile_key)
 
-    def joinMUC(self, service, roomId, nick, profile_key='@DEFAULT@'):
-        return self.db_plugin_iface.joinMUC(service, roomId, nick, profile_key)
+    def joinMUC(self, room_jid, nick, options, profile_key='@DEFAULT@'):
+        if options == None:
+            options = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature
+        return self.db_plugin_iface.joinMUC(room_jid, nick, options, profile_key)
 
     def tarotGameLaunch(self, players, profile_key='@DEFAULT@'):
         return self.db_plugin_iface.tarotGameLaunch(players, profile_key)
--- a/frontends/src/primitivus/primitivus	Sat Oct 08 11:19:25 2011 +0200
+++ b/frontends/src/primitivus/primitivus	Sat Oct 08 18:43:17 2011 +0200
@@ -435,7 +435,7 @@
         self.removePopUp()
         room_jid = JID(edit.get_edit_text())
         if room_jid.is_valid():
-            self.bridge.joinMUC(room_jid.domain, room_jid.node, self.profiles[self.profile]['whoami'].node, self.profile)
+            self.bridge.joinMUC(room_jid, self.profiles[self.profile]['whoami'].node, {}, self.profile)
         else:
             message = _("'%s' is an invalid JID !") % room_jid
             error (message)
--- a/frontends/src/quick_frontend/quick_app.py	Sat Oct 08 11:19:25 2011 +0200
+++ b/frontends/src/quick_frontend/quick_app.py	Sat Oct 08 18:43:17 2011 +0200
@@ -160,10 +160,10 @@
                 self.subscribe(waitingSub[sub], sub, profile)
 
             #Now we open the MUC window where we already are:
-            for room_args in self.bridge.getRoomJoined(profile):
+            for room_args in self.bridge.getRoomsJoined(profile):
                 self.roomJoined(*room_args, profile=profile)
 
-            for subject_args in self.bridge.getRoomSubjects(profile):
+            for subject_args in self.bridge.getRoomsSubjectss(profile):
                 self.roomNewSubject(*subject_args, profile=profile)
         
         if autoconnect and not self.bridge.isConnected(profile_key):
@@ -283,41 +283,37 @@
             if not self.CM.isConnected(from_jid):
                 self.contactList.disconnect(from_jid)
     
-    def roomJoined(self, room_id, room_service, room_nicks, user_nick, profile):
+    def roomJoined(self, room_jid, room_nicks, user_nick, profile):
         """Called when a MUC room is joined"""
         if not self.check_profile(profile):
             return
-        debug (_("Room [%(room_name)s] joined by %(profile)s, users presents:%(users)s") % {'room_name':room_id+'@'+room_service, 'profile': profile, 'users':room_nicks})
-        room_jid=room_id+'@'+room_service
+        debug (_("Room [%(room_jid)s] joined by %(profile)s, users presents:%(users)s") % {'room_jid':room_jid, 'profile': profile, 'users':room_nicks})
         self.chat_wins[room_jid].setUserNick(user_nick)
         self.chat_wins[room_jid].setType("group")
         self.chat_wins[room_jid].id = room_jid
         self.chat_wins[room_jid].setPresents(list(set([user_nick]+room_nicks)))
 
 
-    def roomUserJoined(self, room_id, room_service, user_nick, user_data, profile):
+    def roomUserJoined(self, room_jid, user_nick, user_data, profile):
         """Called when an user joined a MUC room"""
         if not self.check_profile(profile):
             return
-        room_jid=room_id+'@'+room_service
         if self.chat_wins.has_key(room_jid):
             self.chat_wins[room_jid].replaceUser(user_nick)
             debug (_("user [%(user_nick)s] joined room [%(room_jid)s]") % {'user_nick':user_nick, 'room_jid':room_jid})
 
-    def roomUserLeft(self, room_id, room_service, user_nick, user_data, profile):
+    def roomUserLeft(self, room_jid, user_nick, user_data, profile):
         """Called when an user joined a MUC room"""
         if not self.check_profile(profile):
             return
-        room_jid=room_id+'@'+room_service
         if self.chat_wins.has_key(room_jid):
             self.chat_wins[room_jid].removeUser(user_nick)
             debug (_("user [%(user_nick)s] left room [%(room_jid)s]") % {'user_nick':user_nick, 'room_jid':room_jid})
 
-    def roomNewSubject(self, room_id, room_service, subject, profile):
+    def roomNewSubject(self, room_jid, subject, profile):
         """Called when subject of MUC room change"""
         if not self.check_profile(profile):
             return
-        room_jid=room_id+'@'+room_service
         if self.chat_wins.has_key(room_jid):
             self.chat_wins[room_jid].setSubject(subject)
             debug (_("new subject for room [%(room_jid)s]: %(subject)s") % {'room_jid':room_jid, "subject":subject})
--- a/frontends/src/wix/main_window.py	Sat Oct 08 11:19:25 2011 +0200
+++ b/frontends/src/wix/main_window.py	Sat Oct 08 18:43:17 2011 +0200
@@ -190,9 +190,6 @@
     def newMessage(self, from_jid, msg, type, to_jid, profile):
         QuickApp.newMessage(self, from_jid, msg, type, to_jid, profile)
 
-    def roomJoined(self, room_id, room_service, room_nicks, user_nick, profile):
-        super(MainWindow, self).roomJoined(room_id, room_service, room_nicks, user_nick, profile)
-
     def showAlert(self, message):
         # TODO: place this in a separate class
         popup=wx.PopupWindow(self)
@@ -464,7 +461,7 @@
         if dlg.ShowModal() == wx.ID_OK:
             room_jid=JID(dlg.GetValue())
             if room_jid.is_valid():
-                self.bridge.joinMUC(room_jid.domain, room_jid.node, self.profiles[self.profile]['whoami'].node, self.profile)
+                self.bridge.joinMUC(room_jid, self.profiles[self.profile]['whoami'].node, {}, self.profile)
             else:
                 error (_("'%s' is an invalid JID !"), room_jid)
 
--- a/src/bridge/bridge_constructor/dbus_frontend_template.py	Sat Oct 08 11:19:25 2011 +0200
+++ b/src/bridge/bridge_constructor/dbus_frontend_template.py	Sat Oct 08 18:43:17 2011 +0200
@@ -59,14 +59,16 @@
 ##METHODS_PART##
 
 #methods from plugins
-    def getRoomJoined(self, profile_key='@DEFAULT@'):
-        return self.db_plugin_iface.getRoomJoined(profile_key)
+    def getRoomsJoined(self, profile_key='@DEFAULT@'):
+        return self.db_plugin_iface.getRoomsJoined(profile_key)
 
-    def getRoomSubjects(self, profile_key='@DEFAULT@'):
-        return self.db_plugin_iface.getRoomSubjects(profile_key)
+    def getRoomsSubjectss(self, profile_key='@DEFAULT@'):
+        return self.db_plugin_iface.getRoomsSubjectss(profile_key)
 
-    def joinMUC(self, service, roomId, nick, profile_key='@DEFAULT@'):
-        return self.db_plugin_iface.joinMUC(service, roomId, nick, profile_key)
+    def joinMUC(self, room_jid, nick, options, profile_key='@DEFAULT@'):
+        if options == None:
+            options = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature
+        return self.db_plugin_iface.joinMUC(room_jid, nick, options, profile_key)
 
     def tarotGameLaunch(self, players, profile_key='@DEFAULT@'):
         return self.db_plugin_iface.tarotGameLaunch(players, profile_key)
--- a/src/plugins/plugin_xep_0045.py	Sat Oct 08 11:19:25 2011 +0200
+++ b/src/plugins/plugin_xep_0045.py	Sat Oct 08 18:43:17 2011 +0200
@@ -58,14 +58,14 @@
         info(_("Plugin XEP_0045 initialization"))
         self.host = host
         self.clients={}
-        host.bridge.addMethod("joinMUC", ".plugin", in_sign='ssss', out_sign='', method=self._join)
-        host.bridge.addMethod("getRoomJoined", ".plugin", in_sign='s', out_sign='a(ssass)', method=self.getRoomJoined)
-        host.bridge.addMethod("getRoomSubjects", ".plugin", in_sign='s', out_sign='a(sss)', method=self.getRoomSubjects)
+        host.bridge.addMethod("joinMUC", ".plugin", in_sign='ssa{ss}s', out_sign='', method=self._join)
+        host.bridge.addMethod("getRoomsJoined", ".plugin", in_sign='s', out_sign='a(sass)', method=self.getRoomsJoined)
+        host.bridge.addMethod("getRoomsSubjectss", ".plugin", in_sign='s', out_sign='a(ss)', method=self.getRoomsSubjectss)
         host.bridge.addMethod("getUniqueRoomName", ".plugin", in_sign='s', out_sign='s', method=self.getUniqueName)
-        host.bridge.addSignal("roomJoined", ".plugin", signature='ssasss') #args: room_id, room_service, room_nicks, user_nick, profile
-        host.bridge.addSignal("roomUserJoined", ".plugin", signature='sssa{ss}s') #args: room_id, room_service, user_nick, user_data, profile
-        host.bridge.addSignal("roomUserLeft", ".plugin", signature='sssa{ss}s') #args: room_id, room_service, user_nick, user_data, profile
-        host.bridge.addSignal("roomNewSubject", ".plugin", signature='ssss') #args: room_id, room_service, subject, profile
+        host.bridge.addSignal("roomJoined", ".plugin", signature='sasss') #args: room_jid, room_nicks, user_nick, profile
+        host.bridge.addSignal("roomUserJoined", ".plugin", signature='ssa{ss}s') #args: room_jid, user_nick, user_data, profile
+        host.bridge.addSignal("roomUserLeft", ".plugin", signature='ssa{ss}s') #args: room_jid, user_nick, user_data, profile
+        host.bridge.addSignal("roomNewSubject", ".plugin", signature='sss') #args: room_jid, subject, profile
 
     def __check_profile(self, profile):
         """check if profile is used and connected
@@ -82,17 +82,15 @@
     def __room_joined(self, room, profile):
         """Called when the user is in the requested room"""
         def _sendBridgeSignal(ignore=None):
-            self.host.bridge.roomJoined(room.roomIdentifier, room.service, [user.nick for user in room.roster.values()], room.nick, profile)
+            self.host.bridge.roomJoined(room.roomJID.userhost(), [user.nick for user in room.roster.values()], room.nick, profile)
 
-        room_jid = room.roomIdentifier+'@'+room.service
-        self.clients[profile].joined_rooms[room_jid] = room
+        room_jid_s = room.roomJID.userhost()
+        self.clients[profile].joined_rooms[room_jid_s] = room
         if room.status == '201':
             #FIXME: the current behaviour is to create an instant room
             #and send the signal only when the room is unlocked
             #a proper configuration management should be done
-            #TODO: wokkel's muc currently doesn't manage correctly message from the room
-            #      service (without resource) in room.getUser 
-            self.clients[profile].configure(room_jid).addCallbacks(_sendBridgeSignal, lambda x: error(_('Error while configuring the room')))
+            self.clients[profile].configure(room_jid_s).addCallbacks(_sendBridgeSignal, lambda x: error(_('Error while configuring the room')))
         else:
             _sendBridgeSignal()
         return room
@@ -104,14 +102,14 @@
         error (mess)
         self.host.bridge.newAlert(mess, _("Group chat error"), "ERROR", profile)
 
-    def getRoomJoined(self, profile_key='@DEFAULT@'):
+    def getRoomsJoined(self, profile_key='@DEFAULT@'):
         """Return room where user is"""
         profile = self.host.memory.getProfileName(profile_key)
         result = []
         if not self.__check_profile(profile):
             return result
         for room in self.clients[profile].joined_rooms.values():
-            result.append((room.roomIdentifier, room.service, [user.nick for user in room.roster.values()], room.nick))
+            result.append((room.roomJID.userhost(), [user.nick for user in room.roster.values()], room.nick))
         return result
 
     def getRoomNick(self, room_jid, profile_key='@DEFAULT@'):
@@ -125,7 +123,7 @@
         return self.clients[profile].joined_rooms[room_jid].nick
 
 
-    def getRoomSubjects(self, profile_key='@DEFAULT@'):
+    def getRoomsSubjectss(self, profile_key='@DEFAULT@'):
         """Return received subjects of rooms"""
         profile = self.host.memory.getProfileName(profile_key)
         if not self.__check_profile(profile):
@@ -138,7 +136,7 @@
         #TODO: we should be able to select the MUC service here
         return uuid.uuid1() 
 
-    def join(self, service, roomId, nick, profile_key='@DEFAULT@'):
+    def join(self, room_jid, nick, options, profile_key='@DEFAULT@'):
         def _errDeferred(exc_obj = Exception, txt='Error while joining room'):
             d = defer.Deferred()
             d.errback(exc_obj(txt))
@@ -146,23 +144,19 @@
         profile = self.host.memory.getProfileName(profile_key)
         if not self.__check_profile(profile):
             return _errDeferred() 
-        room_jid = roomId+'@'+service
-        if self.clients[profile].joined_rooms.has_key(room_jid):
-            warning(_('%(profile)s is already in room %(room_jid)s') % {'profile':profile, 'room_jid':room_jid})
+        if self.clients[profile].joined_rooms.has_key(room_jid.userhost()):
+            warning(_('%(profile)s is already in room %(room_jid)s') % {'profile':profile, 'room_jid':room_jid.userhost()})
             return _errDeferred() 
-        info (_("[%(profile)s] is joining room %(room)s with nick %(nick)s") % {'profile':profile,'room':roomId+'@'+service, 'nick':nick})
-        try:
-            return self.clients[profile].join(service, roomId, nick).addCallbacks(self.__room_joined, self.__err_joining_room, callbackKeywords={'profile':profile}, errbackKeywords={'profile':profile})
-        except:
-            #XXX: this is a ugly workaround as MUCClient thrown an error if there is invalid chars in the room jid (like with the default string)
-            #FIXME: must be removed when MUCClient manage this better
-            d = _errDeferred(txt="ugly workaround")
-            d.addErrback(self.__err_joining_room, profile)
-            return d
+        info (_("[%(profile)s] is joining room %(room)s with nick %(nick)s") % {'profile':profile,'room':room_jid.userhost(), 'nick':nick})
 
-    def _join(self, service, roomId, nick, profile_key='@DEFAULT@'):
+        history_options = options["history"] == "True" if options.has_key("history") else None
+        password = options["password"] if options.has_key("password") else None
+        
+        return self.clients[profile].join(room_jid, nick, history_options, password).addCallbacks(self.__room_joined, self.__err_joining_room, callbackKeywords={'profile':profile}, errbackKeywords={'profile':profile})
+
+    def _join(self, room_jid, nick, options={}, profile_key='@DEFAULT@'):
         """join method used by bridge: use the _join method, but doesn't return any deferred"""
-        d = self.join(service, roomId, nick, profile_key)
+        d = self.join(jid.JID(room_jid), nick, options, profile_key)
         d.addErrback(lambda x: warning(_('Error while joining room'))) #TODO: error management + signal in bridge
     
     def getHandler(self, profile):
@@ -189,24 +183,22 @@
         debug (_("user %(nick)s has joined room (%(room_id)s)") % {'nick':user.nick, 'room_id':room.occupantJID.userhost()})
         if not self.host.trigger.point("MUC user joined", room, user, self.parent.profile):
             return
-        user_data={'entity':user.entity or '', 'affiliation':user.affiliation, 'role':user.role} 
-        self.host.bridge.roomUserJoined(room.roomIdentifier, room.service, user.nick, user_data, self.parent.profile)
+        user_data={'entity':user.entity.full() if user.entity else  '', 'affiliation':user.affiliation, 'role':user.role} 
+        self.host.bridge.roomUserJoined(room.roomJID.userhost(), user.nick, user_data, self.parent.profile)
     
     def userLeftRoom(self, room, user):
         debug (_("user %(nick)s left room (%(room_id)s)") % {'nick':user.nick, 'room_id':room.occupantJID.userhost()})
-        user_data={'entity':user.entity or '', 'affiliation':user.affiliation, 'role':user.role} 
-        self.host.bridge.roomUserLeft(room.roomIdentifier, room.service, user.nick, user_data, self.parent.profile)
+        user_data={'entity':user.entity.full() if user.entity else  '', 'affiliation':user.affiliation, 'role':user.role} 
+        self.host.bridge.roomUserLeft(room.rooJID.userhost(), user.nick, user_data, self.parent.profile)
 
     def userUpdatedStatus(self, room, user, show, status):
         print("FIXME: MUC status not managed yet")
         #FIXME: gof
 
-    def receivedSubject(self, occupantJID, subject):
-        room = self._getRoom(occupantJID)
-        debug (_("New subject for room (%(room_id)s): %(subject)s") % {'room_id':room.occupantJID.userhost(),'subject':subject})
-        room_jid = room.roomIdentifier+'@'+room.service
-        self.rec_subjects[room_jid] = (room.roomIdentifier, room.service, subject)
-        self.host.bridge.roomNewSubject(room.roomIdentifier, room.service, subject, self.parent.profile)
+    def receivedSubject(self, room, user, subject):
+        debug (_("New subject for room (%(room_id)s): %(subject)s") % {'room_id':room.roomJID.full(),'subject':subject})
+        self.rec_subjects[room.roomJID.userhost()] = (room.roomJID.userhost(), subject)
+        self.host.bridge.roomNewSubject(room.roomJID.userhost(), subject, self.parent.profile)
 
     #def connectionInitialized(self):
         #pass