comparison plugins/plugin_xep_0045.py @ 78:ace2af8abc5a

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
author Goffi <goffi@goffi.org>
date Wed, 31 Mar 2010 17:16:27 +1100
parents 1ae680f9682e
children 39c672544593
comparison
equal deleted inserted replaced
77:1ae680f9682e 78:ace2af8abc5a
67 def __init__(self, host): 67 def __init__(self, host):
68 info(_("Plugin XEP_0045 initialization")) 68 info(_("Plugin XEP_0045 initialization"))
69 self.host = host 69 self.host = host
70 self.clients={} 70 self.clients={}
71 host.bridge.addMethod("joinMUC", ".communication", in_sign='ssss', out_sign='', method=self.join) 71 host.bridge.addMethod("joinMUC", ".communication", in_sign='ssss', out_sign='', method=self.join)
72 host.bridge.addMethod("getRoomJoined", ".communication", in_sign='s', out_sign='a(ssass)', method=self.getRoomJoined)
73 host.bridge.addMethod("getRoomSubjects", ".communication", in_sign='s', out_sign='a(sss)', method=self.getRoomSubjects)
72 host.bridge.addSignal("roomJoined", ".communication", signature='ssasss') #args: room_id, room_service, room_nicks, user_nick, profile 74 host.bridge.addSignal("roomJoined", ".communication", signature='ssasss') #args: room_id, room_service, room_nicks, user_nick, profile
73 host.bridge.addSignal("roomUserJoined", ".communication", signature='sssa{ss}s') #args: room_id, room_service, user_nick, user_data, profile 75 host.bridge.addSignal("roomUserJoined", ".communication", signature='sssa{ss}s') #args: room_id, room_service, user_nick, user_data, profile
74 host.bridge.addSignal("roomUserLeft", ".communication", signature='sssa{ss}s') #args: room_id, room_service, user_nick, user_data, profile 76 host.bridge.addSignal("roomUserLeft", ".communication", signature='sssa{ss}s') #args: room_id, room_service, user_nick, user_data, profile
75 host.bridge.addSignal("roomNewSubject", ".communication", signature='ssss') #args: room_id, room_service, subject, profile 77 host.bridge.addSignal("roomNewSubject", ".communication", signature='ssss') #args: room_id, room_service, subject, profile
76 78
96 def __err_joining_room(self, failure, profile): 98 def __err_joining_room(self, failure, profile):
97 """Called when something is going wrong when joining the room""" 99 """Called when something is going wrong when joining the room"""
98 error ("Error when joining the room") 100 error ("Error when joining the room")
99 #TODO: gof: send an error message throught the bridge 101 #TODO: gof: send an error message throught the bridge
100 102
103 def getRoomJoined(self, profile_key='@DEFAULT@'):
104 """Return room where user is"""
105 profile = self.host.memory.getProfileName(profile_key)
106 result = []
107 if not self.__check_profile(profile):
108 return result
109 for room in self.clients[profile].joined_rooms.values():
110 result.append((room.roomIdentifier, room.service, [user.nick for user in room.roster.values()], room.nick))
111 return result
112
113 def getRoomSubjects(self, profile_key='@DEFAULT@'):
114 """Return received subjects of rooms"""
115 profile = self.host.memory.getProfileName(profile_key)
116 if not self.__check_profile(profile):
117 return []
118 return self.clients[profile].rec_subjects.values()
119
101 def join(self, service, roomId, nick, profile_key='@DEFAULT@'): 120 def join(self, service, roomId, nick, profile_key='@DEFAULT@'):
102 profile = self.host.memory.getProfileName(profile_key) 121 profile = self.host.memory.getProfileName(profile_key)
103 if not self.__check_profile(profile): 122 if not self.__check_profile(profile):
104 return 123 return
105 room_jid = roomId+'@'+service 124 room_jid = roomId+'@'+service
121 140
122 def __init__(self, plugin_parent): 141 def __init__(self, plugin_parent):
123 self.plugin_parent = plugin_parent 142 self.plugin_parent = plugin_parent
124 self.host = plugin_parent.host 143 self.host = plugin_parent.host
125 muc.MUCClient.__init__(self) 144 muc.MUCClient.__init__(self)
126 self.joined_rooms = {} #FIXME gof: check if necessary 145 self.joined_rooms = {}
146 self.rec_subjects = {}
127 print "init SatMUCClient OK" 147 print "init SatMUCClient OK"
128 148
129 def receivedGroupChat(self, room, user, body): 149 def receivedGroupChat(self, room, user, body):
130 debug('receivedGroupChat: room=%s user=%s body=%s', room, user, body) 150 debug('receivedGroupChat: room=%s user=%s body=%s', room, user, body)
131 151
143 print("FIXME: MUC status not managed yet") 163 print("FIXME: MUC status not managed yet")
144 #FIXME: gof 164 #FIXME: gof
145 165
146 def receivedSubject(self, room, subject): 166 def receivedSubject(self, room, subject):
147 debug (_("New subject for room (%(room_id)s): %(subject)s") % {'room_id':room.occupantJID.userhost(),'subject':subject}) 167 debug (_("New subject for room (%(room_id)s): %(subject)s") % {'room_id':room.occupantJID.userhost(),'subject':subject})
168 room_jid = room.roomIdentifier+'@'+room.service
169 self.rec_subjects[room_jid] = (room.roomIdentifier, room.service, subject)
148 self.host.bridge.roomNewSubject(room.roomIdentifier, room.service, subject, self.parent.profile) 170 self.host.bridge.roomNewSubject(room.roomIdentifier, room.service, subject, self.parent.profile)
149 171
150 #def connectionInitialized(self): 172 #def connectionInitialized(self):
151 #pass 173 #pass
152 174