Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0045.py @ 1068:1513511a0586
plugin XEP-0045: room configuration returns a success or failure message
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 12 Jun 2014 18:56:08 +0200 |
parents | a7d33c7a8277 |
children | 246712d2e7bc |
comparison
equal
deleted
inserted
replaced
1067:f7f15d44fdfa | 1068:1513511a0586 |
---|---|
15 # GNU Affero General Public License for more details. | 15 # GNU Affero General Public License for more details. |
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 _, D_ |
21 from sat.core.constants import Const as C | 21 from sat.core.constants import Const as C |
22 from sat.core.log import getLogger | 22 from sat.core.log import getLogger |
23 log = getLogger(__name__) | 23 log = getLogger(__name__) |
24 from twisted.internet import defer | 24 from twisted.internet import defer |
25 from twisted.words.protocols.jabber import jid | 25 from twisted.words.protocols.jabber import jid |
122 """Called when something is going wrong when joining the room""" | 122 """Called when something is going wrong when joining the room""" |
123 if hasattr(failure.value, "condition") and failure.value.condition == 'conflict': | 123 if hasattr(failure.value, "condition") and failure.value.condition == 'conflict': |
124 # we have a nickname conflict, we try again with "_" suffixed to current nickname | 124 # we have a nickname conflict, we try again with "_" suffixed to current nickname |
125 nick += '_' | 125 nick += '_' |
126 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]) | 126 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]) |
127 mess = _("Error while joining the room %s" % room_jid.userhost()) | 127 mess = D_("Error while joining the room %s" % room_jid.userhost()) |
128 log.error(mess) | 128 log.error(mess) |
129 self.host.bridge.newAlert(mess, _("Group chat error"), "ERROR", profile) | 129 self.host.bridge.newAlert(mess, D_("Group chat error"), "ERROR", profile) |
130 raise failure | 130 raise failure |
131 | 131 |
132 def getRoomsJoined(self, profile_key=C.PROF_KEY_NONE): | 132 def getRoomsJoined(self, profile_key=C.PROF_KEY_NONE): |
133 """Return room where user is""" | 133 """Return room where user is""" |
134 profile = self.host.memory.getProfileName(profile_key) | 134 profile = self.host.memory.getProfileName(profile_key) |
204 """ | 204 """ |
205 profile = self.host.memory.getProfileName(profile_key) | 205 profile = self.host.memory.getProfileName(profile_key) |
206 if not self.__check_profile(profile): | 206 if not self.__check_profile(profile): |
207 raise exceptions.ProfileUnknownError("Unknown or disconnected profile") | 207 raise exceptions.ProfileUnknownError("Unknown or disconnected profile") |
208 if room_jid.userhost() not in self.clients[profile].joined_rooms: | 208 if room_jid.userhost() not in self.clients[profile].joined_rooms: |
209 raise UnknownRoom("This room has not been joined") | 209 raise UnknownRoom(D_("This room has not been joined")) |
210 | 210 |
211 def config2XMLUI(result): | 211 def config2XMLUI(result): |
212 if not result: | 212 if not result: |
213 return "" | 213 return "" |
214 session_id, session_data = self._sessions.newSession(profile=profile) | 214 session_id, session_data = self._sessions.newSession(profile=profile) |
223 | 223 |
224 def _submitConfiguration(self, raw_data, profile): | 224 def _submitConfiguration(self, raw_data, profile): |
225 try: | 225 try: |
226 session_data = self._sessions.profileGet(raw_data["session_id"], profile) | 226 session_data = self._sessions.profileGet(raw_data["session_id"], profile) |
227 except KeyError: | 227 except KeyError: |
228 log.warning ("session id doesn't exist, session has probably expired") | 228 log.warning(D_("Session ID doesn't exist, session has probably expired.")) |
229 # TODO: send error dialog | 229 _dialog = xml_tools.XMLUI('popup', title=D_('Room configuration failed')) |
230 return defer.succeed({}) | 230 _dialog.addText(D_("Session ID doesn't exist, session has probably expired.")) |
231 return defer.succeed({'xmlui': _dialog.toXml()}) | |
231 | 232 |
232 data = xml_tools.XMLUIResult2DataFormResult(raw_data) | 233 data = xml_tools.XMLUIResult2DataFormResult(raw_data) |
233 d = self.clients[profile].configure(session_data['room_jid'], data) | 234 d = self.clients[profile].configure(session_data['room_jid'], data) |
234 d.addCallback(lambda ignore: {}) | 235 _dialog = xml_tools.XMLUI('popup', title=D_('Room configuration succeed')) |
236 _dialog.addText(D_("The new settings have been saved.")) | |
237 d.addCallback(lambda ignore: {'xmlui': _dialog.toXml()}) | |
235 del self._sessions[raw_data["session_id"]] | 238 del self._sessions[raw_data["session_id"]] |
236 return d | 239 return d |
237 | 240 |
238 def isNickInRoom(self, room_jid, nick, profile): | 241 def isNickInRoom(self, room_jid, nick, profile): |
239 """Tell if a nick is currently present in a room""" | 242 """Tell if a nick is currently present in a room""" |