Basic user joined/left management
- plugin XEP-0045: user joined./left signal is sended - wix: user are adder/removed when these signals are catched
This commit is contained in:
parent
ad94be8064
commit
39807e5b36
5 changed files with 51 additions and 6 deletions
|
|
@ -43,6 +43,8 @@ class QuickApp():
|
|||
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 @@ class QuickApp():
|
|||
|
||||
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"""
|
||||
|
|
|
|||
|
|
@ -97,6 +97,25 @@ class Chat(wx.Frame, QuickChat):
|
|||
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")
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
|
|||
"""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)
|
||||
|
||||
|
|
|
|||
|
|
@ -162,8 +162,6 @@ class MainWindow(wx.Frame, QuickApp):
|
|||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -74,6 +74,10 @@ class XEP_0045():
|
|||
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 @@ class XEP_0045():
|
|||
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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue