comparison src/plugins/plugin_xep_0045.py @ 587:952322b1d490

Remove trailing whitespaces.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 18 Jan 2013 17:55:34 +0100
parents ca13633d3b6b
children beaf6bec2fcd
comparison
equal deleted inserted replaced
586:6a718ede8be1 587:952322b1d490
104 """Called when something is going wrong when joining the room""" 104 """Called when something is going wrong when joining the room"""
105 if failure.value.condition == 'conflict': 105 if failure.value.condition == 'conflict':
106 # we have a nickname conflict, we try again with "_" suffixed to current nickname 106 # we have a nickname conflict, we try again with "_" suffixed to current nickname
107 nick += '_' 107 nick += '_'
108 return self.clients[profile].join(room_jid, nick, history_options, password).addCallbacks(self.__room_joined, self.__err_joining_room, callbackKeywords={'profile':profile}, errbackArgs=[room_jid, nick, history_options, password, profile]) 108 return self.clients[profile].join(room_jid, nick, history_options, password).addCallbacks(self.__room_joined, self.__err_joining_room, callbackKeywords={'profile':profile}, errbackArgs=[room_jid, nick, history_options, password, profile])
109 109
110 mess = _("Error when joining the room") 110 mess = _("Error when joining the room")
111 error (mess) 111 error (mess)
112 self.host.bridge.newAlert(mess, _("Group chat error"), "ERROR", profile) 112 self.host.bridge.newAlert(mess, _("Group chat error"), "ERROR", profile)
113 raise failure 113 raise failure
114 114
129 @return: nick or empty string in case of error""" 129 @return: nick or empty string in case of error"""
130 profile = self.host.memory.getProfileName(profile_key) 130 profile = self.host.memory.getProfileName(profile_key)
131 if not self.__check_profile(profile) or not self.clients[profile].joined_rooms.has_key(room_jid_s): 131 if not self.__check_profile(profile) or not self.clients[profile].joined_rooms.has_key(room_jid_s):
132 return '' 132 return ''
133 return self.clients[profile].joined_rooms[room_jid_s].nick 133 return self.clients[profile].joined_rooms[room_jid_s].nick
134 134
135 def isNickInRoom(self, room_jid, nick, profile): 135 def isNickInRoom(self, room_jid, nick, profile):
136 """Tell if a nick is currently present in a room""" 136 """Tell if a nick is currently present in a room"""
137 profile = self.host.memory.getProfileName(profile) 137 profile = self.host.memory.getProfileName(profile)
138 if not self.__check_profile(profile): 138 if not self.__check_profile(profile):
139 raise exceptions.UnknownProfileError("Unknown or disconnected profile") 139 raise exceptions.UnknownProfileError("Unknown or disconnected profile")
140 if not self.clients[profile].joined_rooms.has_key(room_jid.userhost()): 140 if not self.clients[profile].joined_rooms.has_key(room_jid.userhost()):
141 raise UnknownRoom("This room has not been joined") 141 raise UnknownRoom("This room has not been joined")
142 return self.clients[profile].joined_rooms[room_jid.userhost()].inRoster(nick) 142 return self.clients[profile].joined_rooms[room_jid.userhost()].inRoster(nick)
143 143
144 def getRoomsSubjects(self, profile_key='@DEFAULT@'): 144 def getRoomsSubjects(self, profile_key='@DEFAULT@'):
145 """Return received subjects of rooms""" 145 """Return received subjects of rooms"""
146 profile = self.host.memory.getProfileName(profile_key) 146 profile = self.host.memory.getProfileName(profile_key)
150 150
151 def getUniqueName(self, profile_key='@DEFAULT@'): 151 def getUniqueName(self, profile_key='@DEFAULT@'):
152 """Return unique name for room, avoiding collision""" 152 """Return unique name for room, avoiding collision"""
153 #TODO: we should use #RFC-0045 10.1.4 when available here 153 #TODO: we should use #RFC-0045 10.1.4 when available here
154 #TODO: we should be able to select the MUC service here 154 #TODO: we should be able to select the MUC service here
155 return uuid.uuid1() 155 return uuid.uuid1()
156 156
157 def join(self, room_jid, nick, options, profile_key='@DEFAULT@'): 157 def join(self, room_jid, nick, options, profile_key='@DEFAULT@'):
158 def _errDeferred(exc_obj = Exception, txt='Error while joining room'): 158 def _errDeferred(exc_obj = Exception, txt='Error while joining room'):
159 d = defer.Deferred() 159 d = defer.Deferred()
160 d.errback(exc_obj(txt)) 160 d.errback(exc_obj(txt))
161 return d 161 return d
162 162
163 profile = self.host.memory.getProfileName(profile_key) 163 profile = self.host.memory.getProfileName(profile_key)
164 if not self.__check_profile(profile): 164 if not self.__check_profile(profile):
165 return _errDeferred() 165 return _errDeferred()
166 if self.clients[profile].joined_rooms.has_key(room_jid.userhost()): 166 if self.clients[profile].joined_rooms.has_key(room_jid.userhost()):
167 warning(_('%(profile)s is already in room %(room_jid)s') % {'profile':profile, 'room_jid':room_jid.userhost()}) 167 warning(_('%(profile)s is already in room %(room_jid)s') % {'profile':profile, 'room_jid':room_jid.userhost()})
168 return _errDeferred() 168 return _errDeferred()
169 info (_("[%(profile)s] is joining room %(room)s with nick %(nick)s") % {'profile':profile,'room':room_jid.userhost(), 'nick':nick}) 169 info (_("[%(profile)s] is joining room %(room)s with nick %(nick)s") % {'profile':profile,'room':room_jid.userhost(), 'nick':nick})
170 170
171 history_options = options["history"] == "True" if options.has_key("history") else None 171 history_options = options["history"] == "True" if options.has_key("history") else None
172 password = options["password"] if options.has_key("password") else None 172 password = options["password"] if options.has_key("password") else None
173 173
174 return self.clients[profile].join(room_jid, nick, history_options, password).addCallbacks(self.__room_joined, self.__err_joining_room, callbackKeywords={'profile':profile}, errbackArgs=[room_jid, nick, history_options, password, profile]) 174 return self.clients[profile].join(room_jid, nick, history_options, password).addCallbacks(self.__room_joined, self.__err_joining_room, callbackKeywords={'profile':profile}, errbackArgs=[room_jid, nick, history_options, password, profile])
175 175
176 def _join(self, room_jid_s, nick, options={}, profile_key='@DEFAULT@'): 176 def _join(self, room_jid_s, nick, options={}, profile_key='@DEFAULT@'):
177 """join method used by bridge: use the _join method, but doesn't return any deferred""" 177 """join method used by bridge: use the _join method, but doesn't return any deferred"""
178 profile = self.host.memory.getProfileName(profile_key) 178 profile = self.host.memory.getProfileName(profile_key)
191 def nick(self, room_jid, nick, profile_key): 191 def nick(self, room_jid, nick, profile_key):
192 profile = self.host.memory.getProfileName(profile_key) 192 profile = self.host.memory.getProfileName(profile_key)
193 if not self.__check_profile(profile): 193 if not self.__check_profile(profile):
194 raise exceptions.UnknownProfileError("Unknown or disconnected profile") 194 raise exceptions.UnknownProfileError("Unknown or disconnected profile")
195 if not self.clients[profile].joined_rooms.has_key(room_jid.userhost()): 195 if not self.clients[profile].joined_rooms.has_key(room_jid.userhost()):
196 raise UnknownRoom("This room has not been joined") 196 raise UnknownRoom("This room has not been joined")
197 return self.clients[profile].nick(room_jid, nick) 197 return self.clients[profile].nick(room_jid, nick)
198 198
199 def leave(self, room_jid, profile_key): 199 def leave(self, room_jid, profile_key):
200 profile = self.host.memory.getProfileName(profile_key) 200 profile = self.host.memory.getProfileName(profile_key)
201 if not self.__check_profile(profile): 201 if not self.__check_profile(profile):
202 raise exceptions.UnknownProfileError("Unknown or disconnected profile") 202 raise exceptions.UnknownProfileError("Unknown or disconnected profile")
203 if not self.clients[profile].joined_rooms.has_key(room_jid.userhost()): 203 if not self.clients[profile].joined_rooms.has_key(room_jid.userhost()):
204 raise UnknownRoom("This room has not been joined") 204 raise UnknownRoom("This room has not been joined")
205 return self.clients[profile].leave(room_jid) 205 return self.clients[profile].leave(room_jid)
206 206
207 def subject(self, room_jid, subject, profile_key): 207 def subject(self, room_jid, subject, profile_key):
208 profile = self.host.memory.getProfileName(profile_key) 208 profile = self.host.memory.getProfileName(profile_key)
209 if not self.__check_profile(profile): 209 if not self.__check_profile(profile):
210 raise exceptions.UnknownProfileError("Unknown or disconnected profile") 210 raise exceptions.UnknownProfileError("Unknown or disconnected profile")
211 if not self.clients[profile].joined_rooms.has_key(room_jid.userhost()): 211 if not self.clients[profile].joined_rooms.has_key(room_jid.userhost()):
212 raise UnknownRoom("This room has not been joined") 212 raise UnknownRoom("This room has not been joined")
213 return self.clients[profile].subject(room_jid, subject) 213 return self.clients[profile].subject(room_jid, subject)
214 214
215 def mucNick(self, room_jid_s, nick, profile_key='@DEFAULT@'): 215 def mucNick(self, room_jid_s, nick, profile_key='@DEFAULT@'):
216 """Change nickname in a room""" 216 """Change nickname in a room"""
217 return self.nick(jid.JID(room_jid_s), nick, profile_key) 217 return self.nick(jid.JID(room_jid_s), nick, profile_key)
225 return self.clients[profile] 225 return self.clients[profile]
226 226
227 227
228 class SatMUCClient (muc.MUCClient): 228 class SatMUCClient (muc.MUCClient):
229 #implements(iwokkel.IDisco) 229 #implements(iwokkel.IDisco)
230 230
231 def __init__(self, plugin_parent): 231 def __init__(self, plugin_parent):
232 self.plugin_parent = plugin_parent 232 self.plugin_parent = plugin_parent
233 self.host = plugin_parent.host 233 self.host = plugin_parent.host
234 muc.MUCClient.__init__(self) 234 muc.MUCClient.__init__(self)
235 self.joined_rooms = {} #FIXME: seem to do the same thing as MUCClient's _rooms attribute, must be removed 235 self.joined_rooms = {} #FIXME: seem to do the same thing as MUCClient's _rooms attribute, must be removed
238 # and to discard userJoinedRoom signal in this case 238 # and to discard userJoinedRoom signal in this case
239 print "init SatMUCClient OK" 239 print "init SatMUCClient OK"
240 240
241 def subject(self, room, subject): 241 def subject(self, room, subject):
242 return muc.MUCClientProtocol.subject(self, room, subject) 242 return muc.MUCClientProtocol.subject(self, room, subject)
243 243
244 def unavailableReceived(self, presence): 244 def unavailableReceived(self, presence):
245 #XXX: we override this method to manage nickname change 245 #XXX: we override this method to manage nickname change
246 #TODO: feed this back to Wokkel 246 #TODO: feed this back to Wokkel
247 """ 247 """
248 Unavailable presence was received. 248 Unavailable presence was received.
272 self.__changing_nicks.remove(user.nick) 272 self.__changing_nicks.remove(user.nick)
273 else: 273 else:
274 debug (_("user %(nick)s has joined room (%(room_id)s)") % {'nick':user.nick, 'room_id':room.occupantJID.userhost()}) 274 debug (_("user %(nick)s has joined room (%(room_id)s)") % {'nick':user.nick, 'room_id':room.occupantJID.userhost()})
275 if not self.host.trigger.point("MUC user joined", room, user, self.parent.profile): 275 if not self.host.trigger.point("MUC user joined", room, user, self.parent.profile):
276 return 276 return
277 user_data={'entity':user.entity.full() if user.entity else '', 'affiliation':user.affiliation, 'role':user.role} 277 user_data={'entity':user.entity.full() if user.entity else '', 'affiliation':user.affiliation, 'role':user.role}
278 self.host.bridge.roomUserJoined(room.roomJID.userhost(), user.nick, user_data, self.parent.profile) 278 self.host.bridge.roomUserJoined(room.roomJID.userhost(), user.nick, user_data, self.parent.profile)
279 279
280 def userLeftRoom(self, room, user): 280 def userLeftRoom(self, room, user):
281 if user.nick == room.nick: 281 if user.nick == room.nick:
282 # we left the room 282 # we left the room
283 room_jid_s = room.roomJID.userhost() 283 room_jid_s = room.roomJID.userhost()
284 info (_("Room [%(room)s] left (%(profile)s))") % { "room": room_jid_s, 284 info (_("Room [%(room)s] left (%(profile)s))") % { "room": room_jid_s,
286 self.host.memory.delEntityCache(room.roomJID, self.parent.profile) 286 self.host.memory.delEntityCache(room.roomJID, self.parent.profile)
287 del self.plugin_parent.clients[self.parent.profile].joined_rooms[room_jid_s] 287 del self.plugin_parent.clients[self.parent.profile].joined_rooms[room_jid_s]
288 self.host.bridge.roomLeft(room.roomJID.userhost(), self.parent.profile) 288 self.host.bridge.roomLeft(room.roomJID.userhost(), self.parent.profile)
289 else: 289 else:
290 debug (_("user %(nick)s left room (%(room_id)s)") % {'nick':user.nick, 'room_id':room.occupantJID.userhost()}) 290 debug (_("user %(nick)s left room (%(room_id)s)") % {'nick':user.nick, 'room_id':room.occupantJID.userhost()})
291 user_data={'entity':user.entity.full() if user.entity else '', 'affiliation':user.affiliation, 'role':user.role} 291 user_data={'entity':user.entity.full() if user.entity else '', 'affiliation':user.affiliation, 'role':user.role}
292 self.host.bridge.roomUserLeft(room.roomJID.userhost(), user.nick, user_data, self.parent.profile) 292 self.host.bridge.roomUserLeft(room.roomJID.userhost(), user.nick, user_data, self.parent.profile)
293 293
294 def userChangedNick(self, room, user, new_nick): 294 def userChangedNick(self, room, user, new_nick):
295 self.host.bridge.roomUserChangedNick(room.roomJID.userhost(), user.nick, new_nick, self.parent.profile) 295 self.host.bridge.roomUserChangedNick(room.roomJID.userhost(), user.nick, new_nick, self.parent.profile)
296 296
303 self.rec_subjects[room.roomJID.userhost()] = (room.roomJID.userhost(), subject) 303 self.rec_subjects[room.roomJID.userhost()] = (room.roomJID.userhost(), subject)
304 self.host.bridge.roomNewSubject(room.roomJID.userhost(), subject, self.parent.profile) 304 self.host.bridge.roomNewSubject(room.roomJID.userhost(), subject, self.parent.profile)
305 305
306 #def connectionInitialized(self): 306 #def connectionInitialized(self):
307 #pass 307 #pass
308 308
309 #def getDiscoInfo(self, requestor, target, nodeIdentifier=''): 309 #def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
310 #return [disco.DiscoFeature(NS_VCARD)] 310 #return [disco.DiscoFeature(NS_VCARD)]
311 311
312 #def getDiscoItems(self, requestor, target, nodeIdentifier=''): 312 #def getDiscoItems(self, requestor, target, nodeIdentifier=''):
313 #return [] 313 #return []
314 314