changeset 75:7322a41f8a8e

Basic user joined/left management - plugin XEP-0045: user joined./left signal is sended - wix: user are adder/removed when these signals are catched
author Goffi <goffi@goffi.org>
date Mon, 29 Mar 2010 16:54:53 +1100
parents 6e3a06b4dd36
children 8becde8a967c
files frontends/quick_frontend/quick_app.py frontends/wix/chat.py frontends/wix/contact_list.py frontends/wix/main_window.py plugins/plugin_xep_0045.py
diffstat 5 files changed, 51 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/quick_frontend/quick_app.py	Wed Mar 24 16:50:53 2010 +1100
+++ b/frontends/quick_frontend/quick_app.py	Mon Mar 29 16:54:53 2010 +1100
@@ -43,6 +43,8 @@
         self.bridge.register("newMessage", self.newMessage)
         self.bridge.register("presenceUpdate", self.presenceUpdate)
         self.bridge.register("roomJoined", self.roomJoined)
+        self.bridge.register("roomUserJoined", self.roomUserJoined)
+        self.bridge.register("roomUserLeft", self.roomUserLeft)
         self.bridge.register("subscribe", self.subscribe)
         self.bridge.register("paramUpdate", self.paramUpdate)
         self.bridge.register("contactDeleted", self.contactDeleted)
@@ -198,9 +200,31 @@
     
     def roomJoined(self, room_id, room_service, room_nicks, user_nick, profile):
         """Called when a MUC room is joined"""
-        debug (_("Room [%(room_name)s] joined by %(profile)s") % {'room_name':room_id+'@'+room_service, 'profile': profile})
+        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
+        self.chat_wins[room_jid].setType("group")
+        self.chat_wins[room_jid].setPresents([user_nick]+room_nicks)
 
 
+    def roomUserJoined(self, room_id, room_service, 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):
+        """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 subscribe(self, type, raw_jid, profile):
         """Called when a subsciption maangement signal is received"""
--- a/frontends/wix/chat.py	Wed Mar 24 16:50:53 2010 +1100
+++ b/frontends/wix/chat.py	Mon Mar 29 16:54:53 2010 +1100
@@ -97,6 +97,25 @@
             return
         for nick in nicks:
            self.present_panel.presents.replace(nick)
+    
+    
+    def replaceUser(self, nick):
+        """Add user if it is not in the group list"""
+        debug (_("Replacing user %s") % nick)
+        if self.type != "group":
+            error (_("[INTERNAL] trying to replace user for a non group chat window"))
+            return
+        self.present_panel.presents.replace(nick)
+      
+    def removeUser(self, nick):
+        """Remove a user from the group list"""
+        debug(_("Removing user %s") % nick)
+        if self.type != "group":
+            error (_("[INTERNAL] trying to remove user for a non group chat window"))
+            return
+        self.present_panel.presents.remove(nick)
+
+
 
     def createMenus(self):
         info("Creating menus")
--- a/frontends/wix/contact_list.py	Wed Mar 24 16:50:53 2010 +1100
+++ b/frontends/wix/contact_list.py	Mon Mar 29 16:54:53 2010 +1100
@@ -137,7 +137,7 @@
         """remove a contact from the list"""
         debug (_("removing %s"), contact)
         list_idx = self.__find_idx(contact)
-        list_idx.reverse()  #we me make some deletions, we have to reverse the order
+        list_idx.reverse()  #as we make some deletions, we have to reverse the order
         for i in list_idx:
             self.Delete(i)
 
--- a/frontends/wix/main_window.py	Wed Mar 24 16:50:53 2010 +1100
+++ b/frontends/wix/main_window.py	Mon Mar 29 16:54:53 2010 +1100
@@ -162,8 +162,6 @@
 
     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)
-        self.chat_wins[room_id+'@'+room_service].setType("group")
-        self.chat_wins[room_id+'@'+room_service].setPresents([user_nick]+room_nicks)
 
     def showAlert(self, message):
         # TODO: place this in a separate class
--- a/plugins/plugin_xep_0045.py	Wed Mar 24 16:50:53 2010 +1100
+++ b/plugins/plugin_xep_0045.py	Mon Mar 29 16:54:53 2010 +1100
@@ -74,6 +74,10 @@
         host.bridge.addSignal("roomUserLeft", ".communication", signature='sssa{ss}s') #args: room_id, room_service, user_nick, user_data, profile
 
     def __check_profile(self, profile):
+        """check if profile is used and connected
+        if profile known but disconnected, remove it from known profiles
+        @param profile: profile to check
+        @return: True if the profile is known and connected, else False"""
         if not profile or not self.clients.has_key(profile) or not self.host.isConnected(profile):
             error (_('Unknown or disconnected profile'))
             if self.clients.has_key(profile):
@@ -86,9 +90,9 @@
         print "room joined (profile = %s)" % profile
         room_jid = room.roomIdentifier+'@'+room.service
         self.clients[profile].joined_rooms[room_jid] = room
-        self.host.bridge.roomJoined(room.roomIdentifier, room.service, room.roster.keys(), room.nick, profile)
+        self.host.bridge.roomJoined(room.roomIdentifier, room.service, [user.nick for user in room.roster.values()], room.nick, profile)
 
-    def __err_joining_room(self, failure, profile): #, profile):
+    def __err_joining_room(self, failure, profile):
         """Called when something is going wrong when joining the room"""
         error ("Error when joining the room")
         pdb.set_trace()