Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0045.py @ 916:1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 21 Mar 2014 16:27:09 +0100 |
parents | 1fe00f0c9a91 |
children | d609581bf74a |
comparison
equal
deleted
inserted
replaced
915:6f96ee4d8cc0 | 916:1a759096ccbd |
---|---|
16 | 16 |
17 # You should have received a copy of the GNU Affero General Public License | 17 # You should have received a copy of the GNU Affero General Public License |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from sat.core.i18n import _ | 20 from sat.core.i18n import _ |
21 from sat.core.constants import Const as C | |
21 from logging import debug, info, warning, error | 22 from logging import debug, info, warning, error |
22 from twisted.internet import defer | 23 from twisted.internet import defer |
23 from twisted.words.protocols.jabber import jid | 24 from twisted.words.protocols.jabber import jid |
24 | 25 |
25 from sat.core import exceptions | 26 from sat.core import exceptions |
114 mess = _("Error while joining the room %s" % room_jid.userhost()) | 115 mess = _("Error while joining the room %s" % room_jid.userhost()) |
115 error(mess) | 116 error(mess) |
116 self.host.bridge.newAlert(mess, _("Group chat error"), "ERROR", profile) | 117 self.host.bridge.newAlert(mess, _("Group chat error"), "ERROR", profile) |
117 raise failure | 118 raise failure |
118 | 119 |
119 def getRoomsJoined(self, profile_key='@DEFAULT@'): | 120 def getRoomsJoined(self, profile_key=C.PROF_KEY_NONE): |
120 """Return room where user is""" | 121 """Return room where user is""" |
121 profile = self.host.memory.getProfileName(profile_key) | 122 profile = self.host.memory.getProfileName(profile_key) |
122 result = [] | 123 result = [] |
123 if not self.__check_profile(profile): | 124 if not self.__check_profile(profile): |
124 return result | 125 return result |
125 for room in self.clients[profile].joined_rooms.values(): | 126 for room in self.clients[profile].joined_rooms.values(): |
126 result.append((room.roomJID.userhost(), [user.nick for user in room.roster.values()], room.nick)) | 127 result.append((room.roomJID.userhost(), [user.nick for user in room.roster.values()], room.nick)) |
127 return result | 128 return result |
128 | 129 |
129 def getRoomNick(self, room_jid_s, profile_key='@DEFAULT@'): | 130 def getRoomNick(self, room_jid_s, profile_key=C.PROF_KEY_NONE): |
130 """return nick used in room by user | 131 """return nick used in room by user |
131 @param room_jid_s: unicode room id | 132 @param room_jid_s: unicode room id |
132 @profile_key: profile | 133 @profile_key: profile |
133 @return: nick or empty string in case of error""" | 134 @return: nick or empty string in case of error""" |
134 profile = self.host.memory.getProfileName(profile_key) | 135 profile = self.host.memory.getProfileName(profile_key) |
172 missing.append(user) | 173 missing.append(user) |
173 else: | 174 else: |
174 nicks.append(nick) | 175 nicks.append(nick) |
175 return nicks, missing | 176 return nicks, missing |
176 | 177 |
177 def _configureRoom(self, room_jid_s, profile_key='@NONE@'): | 178 def _configureRoom(self, room_jid_s, profile_key=C.PROF_KEY_NONE): |
178 d = self.configureRoom(jid.JID(room_jid_s), profile_key) | 179 d = self.configureRoom(jid.JID(room_jid_s), profile_key) |
179 d.addCallback(lambda xmlui: xmlui.toXml()) | 180 d.addCallback(lambda xmlui: xmlui.toXml()) |
180 return d | 181 return d |
181 | 182 |
182 def configureRoom(self, room_jid, profile_key='@NONE@'): | 183 def configureRoom(self, room_jid, profile_key=C.PROF_KEY_NONE): |
183 """ return the room configuration form | 184 """ return the room configuration form |
184 @param room: jid of the room to configure | 185 @param room: jid of the room to configure |
185 @param profile_key: %(doc_profile_key)s | 186 @param profile_key: %(doc_profile_key)s |
186 @return: configuration form as XMLUI | 187 @return: configuration form as XMLUI |
187 | 188 |
226 raise exceptions.ProfileUnknownError("Unknown or disconnected profile") | 227 raise exceptions.ProfileUnknownError("Unknown or disconnected profile") |
227 if room_jid.userhost() not in self.clients[profile].joined_rooms: | 228 if room_jid.userhost() not in self.clients[profile].joined_rooms: |
228 raise UnknownRoom("This room has not been joined") | 229 raise UnknownRoom("This room has not been joined") |
229 return self.clients[profile].joined_rooms[room_jid.userhost()].inRoster(muc.User(nick)) | 230 return self.clients[profile].joined_rooms[room_jid.userhost()].inRoster(muc.User(nick)) |
230 | 231 |
231 def getRoomsSubjects(self, profile_key='@DEFAULT@'): | 232 def getRoomsSubjects(self, profile_key=C.PROF_KEY_NONE): |
232 """Return received subjects of rooms""" | 233 """Return received subjects of rooms""" |
233 profile = self.host.memory.getProfileName(profile_key) | 234 profile = self.host.memory.getProfileName(profile_key) |
234 if not self.__check_profile(profile): | 235 if not self.__check_profile(profile): |
235 return [] | 236 return [] |
236 return self.clients[profile].rec_subjects.values() | 237 return self.clients[profile].rec_subjects.values() |
246 #to manage this, but this hack fill do it for test purpose | 247 #to manage this, but this hack fill do it for test purpose |
247 muc_service = service | 248 muc_service = service |
248 break | 249 break |
249 return muc_service | 250 return muc_service |
250 | 251 |
251 def getUniqueName(self, muc_service="", profile_key='@DEFAULT@'): | 252 def getUniqueName(self, muc_service="", profile_key=C.PROF_KEY_NONE): |
252 """Return unique name for room, avoiding collision | 253 """Return unique name for room, avoiding collision |
253 @param muc_service: leave empty string to use the default service | 254 @param muc_service: leave empty string to use the default service |
254 @return: unique room userhost, or '' if an error occured. | 255 @return: unique room userhost, or '' if an error occured. |
255 """ | 256 """ |
256 #TODO: we should use #RFC-0045 10.1.4 when available here | 257 #TODO: we should use #RFC-0045 10.1.4 when available here |
266 error(_("Can't find a MUC service")) | 267 error(_("Can't find a MUC service")) |
267 return "" | 268 return "" |
268 muc_service = muc_service.userhost() | 269 muc_service = muc_service.userhost() |
269 return "%s@%s" % (room_name, muc_service) | 270 return "%s@%s" % (room_name, muc_service) |
270 | 271 |
271 def join(self, room_jid, nick, options, profile_key='@DEFAULT@'): | 272 def join(self, room_jid, nick, options, profile_key=C.PROF_KEY_NONE): |
272 def _errDeferred(exc_obj=Exception, txt='Error while joining room'): | 273 def _errDeferred(exc_obj=Exception, txt='Error while joining room'): |
273 d = defer.Deferred() | 274 d = defer.Deferred() |
274 d.errback(exc_obj(txt)) | 275 d.errback(exc_obj(txt)) |
275 return d | 276 return d |
276 | 277 |
289 # FIXME: how to set the cancel method on the Deferred created by wokkel? | 290 # FIXME: how to set the cancel method on the Deferred created by wokkel? |
290 # This happens when the room is not reachable, e.g. no internet connection: | 291 # This happens when the room is not reachable, e.g. no internet connection: |
291 # > /usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py(480)_startRunCallbacks() | 292 # > /usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py(480)_startRunCallbacks() |
292 # -> raise AlreadyCalledError(extra) | 293 # -> raise AlreadyCalledError(extra) |
293 | 294 |
294 def _join(self, room_jid_s, nick, options={}, profile_key='@DEFAULT@'): | 295 def _join(self, room_jid_s, nick, options={}, profile_key=C.PROF_KEY_NONE): |
295 """join method used by bridge: use the join method, but doesn't return any deferred | 296 """join method used by bridge: use the join method, but doesn't return any deferred |
296 @return the room userhost (given value or unique generated name) | 297 @return the room userhost (given value or unique generated name) |
297 """ | 298 """ |
298 profile = self.host.memory.getProfileName(profile_key) | 299 profile = self.host.memory.getProfileName(profile_key) |
299 if not self.__check_profile(profile): | 300 if not self.__check_profile(profile): |
333 raise exceptions.ProfileUnknownError("Unknown or disconnected profile") | 334 raise exceptions.ProfileUnknownError("Unknown or disconnected profile") |
334 if room_jid.userhost() not in self.clients[profile].joined_rooms: | 335 if room_jid.userhost() not in self.clients[profile].joined_rooms: |
335 raise UnknownRoom("This room has not been joined") | 336 raise UnknownRoom("This room has not been joined") |
336 return self.clients[profile].subject(room_jid, subject) | 337 return self.clients[profile].subject(room_jid, subject) |
337 | 338 |
338 def mucNick(self, room_jid_s, nick, profile_key='@DEFAULT@'): | 339 def mucNick(self, room_jid_s, nick, profile_key=C.PROF_KEY_NONE): |
339 """Change nickname in a room""" | 340 """Change nickname in a room""" |
340 return self.nick(jid.JID(room_jid_s), nick, profile_key) | 341 return self.nick(jid.JID(room_jid_s), nick, profile_key) |
341 | 342 |
342 def mucLeave(self, room_jid_s, profile_key='@DEFAULT@'): | 343 def mucLeave(self, room_jid_s, profile_key=C.PROF_KEY_NONE): |
343 """Leave a room""" | 344 """Leave a room""" |
344 return self.leave(jid.JID(room_jid_s), profile_key) | 345 return self.leave(jid.JID(room_jid_s), profile_key) |
345 | 346 |
346 def getHandler(self, profile): | 347 def getHandler(self, profile): |
347 self.clients[profile] = SatMUCClient(self) | 348 self.clients[profile] = SatMUCClient(self) |