Added method to know which MUC are joined, and which subjects were received.

- plugin xep-0045: new methods getRoomJoined and getRoomSubjects
- wix: room joined are openned and subjects are set on profile plug
This commit is contained in:
Goffi 2010-03-31 17:16:27 +11:00
commit a9fc22c842

View file

@ -69,6 +69,8 @@ class XEP_0045():
self.host = host
self.clients={}
host.bridge.addMethod("joinMUC", ".communication", in_sign='ssss', out_sign='', method=self.join)
host.bridge.addMethod("getRoomJoined", ".communication", in_sign='s', out_sign='a(ssass)', method=self.getRoomJoined)
host.bridge.addMethod("getRoomSubjects", ".communication", in_sign='s', out_sign='a(sss)', method=self.getRoomSubjects)
host.bridge.addSignal("roomJoined", ".communication", signature='ssasss') #args: room_id, room_service, room_nicks, user_nick, profile
host.bridge.addSignal("roomUserJoined", ".communication", signature='sssa{ss}s') #args: room_id, room_service, user_nick, user_data, profile
host.bridge.addSignal("roomUserLeft", ".communication", signature='sssa{ss}s') #args: room_id, room_service, user_nick, user_data, profile
@ -98,6 +100,23 @@ class XEP_0045():
error ("Error when joining the room")
#TODO: gof: send an error message throught the bridge
def getRoomJoined(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))
return result
def getRoomSubjects(self, profile_key='@DEFAULT@'):
"""Return received subjects of rooms"""
profile = self.host.memory.getProfileName(profile_key)
if not self.__check_profile(profile):
return []
return self.clients[profile].rec_subjects.values()
def join(self, service, roomId, nick, profile_key='@DEFAULT@'):
profile = self.host.memory.getProfileName(profile_key)
if not self.__check_profile(profile):
@ -123,7 +142,8 @@ class SatMUCClient (muc.MUCClient):
self.plugin_parent = plugin_parent
self.host = plugin_parent.host
muc.MUCClient.__init__(self)
self.joined_rooms = {} #FIXME gof: check if necessary
self.joined_rooms = {}
self.rec_subjects = {}
print "init SatMUCClient OK"
def receivedGroupChat(self, room, user, body):
@ -145,6 +165,8 @@ class SatMUCClient (muc.MUCClient):
def receivedSubject(self, room, subject):
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 connectionInitialized(self):