Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0048.py @ 985:9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 07 Apr 2014 16:24:29 +0200 |
parents | df8e1b557125 |
children | 224cafc67324 |
comparison
equal
deleted
inserted
replaced
984:df8e1b557125 | 985:9ebdba4ab907 |
---|---|
309 bookmarks = yield self._getServerBookmarks(storage_type, client.profile) | 309 bookmarks = yield self._getServerBookmarks(storage_type, client.profile) |
310 bookmarks[type_][location] = data | 310 bookmarks[type_][location] = data |
311 bookmark_elt = self._dict2BookmarkElt(type_, bookmarks) | 311 bookmark_elt = self._dict2BookmarkElt(type_, bookmarks) |
312 yield self._setServerBookmarks(storage_type, bookmark_elt, client.profile) | 312 yield self._setServerBookmarks(storage_type, bookmark_elt, client.profile) |
313 | 313 |
314 @defer.inlineCallbacks | |
315 def removeBookmark(self, type_, location, storage_type="all", profile_key=C.PROF_KEY_NONE): | |
316 """Remove a stored bookmark | |
317 | |
318 @param type_: bookmark type, one of: | |
319 - XEP_0048.MUC_TYPE: Multi-User chat room | |
320 - XEP_0048.URL_TYPE: web page URL | |
321 @param location: dependeding on type_, can be a MUC room jid or an url | |
322 @param storage_type: where the bookmark is stored, can be: | |
323 - "all": remove from everywhere | |
324 - "pubsub": PubSub private storage (XEP-0223) | |
325 - "private": Private XML storage (XEP-0049) | |
326 - "local": Store in SàT database | |
327 @param profile_key: %(doc_profile_key)s | |
328 """ | |
329 assert storage_type in ('all', 'pubsub', 'private', 'local') | |
330 client = self.host.getClient(profile_key) | |
331 | |
332 if storage_type in ('all', 'local'): | |
333 try: | |
334 del client.bookmarks_local[type_][location] | |
335 yield client.bookmarks_local.force(type_) | |
336 except KeyError: | |
337 debug("Bookmark is not present in local storage") | |
338 | |
339 if storage_type in ('all', 'private'): | |
340 bookmarks = yield self._getServerBookmarks('private', client.profile) | |
341 try: | |
342 del bookmarks[type_][location] | |
343 bookmark_elt = self._dict2BookmarkElt(type_, bookmarks) | |
344 yield self._setServerBookmarks('private', bookmark_elt, client.profile) | |
345 except KeyError: | |
346 debug("Bookmark is not present in private storage") | |
347 | |
348 if storage_type == 'pubsub': | |
349 raise NotImplementedError | |
350 | |
314 def cmd_bookmark(self, mess_data, profile): | 351 def cmd_bookmark(self, mess_data, profile): |
315 """Bookmark a MUC room | 352 """(Un)bookmark a MUC room |
316 | 353 |
317 @command (group): [autojoin] | 354 @command (group): [autojoin | remove] |
318 - autojoin: join room automatically on connection | 355 - autojoin: join room automatically on connection |
319 """ | 356 """ |
320 debug("Catched bookmark command") | 357 debug("Catched bookmark command") |
321 client = self.host.getClient(profile) | 358 client = self.host.getClient(profile) |
322 txt_cmd = self.host.plugins[C.TEXT_CMDS] | 359 txt_cmd = self.host.plugins[C.TEXT_CMDS] |
325 #/bookmark command does nothing if we are not on a group chat | 362 #/bookmark command does nothing if we are not on a group chat |
326 info("Ignoring /bookmark command on a non groupchat message") | 363 info("Ignoring /bookmark command on a non groupchat message") |
327 return True | 364 return True |
328 | 365 |
329 options = mess_data["unparsed"].strip().split() | 366 options = mess_data["unparsed"].strip().split() |
367 if options and options[0] not in ('autojoin', 'remove'): | |
368 txt_cmd.feedBack(_("Bad arguments"), mess_data, profile) | |
369 return False | |
370 | |
330 room_jid = mess_data["to"].userhostJID() | 371 room_jid = mess_data["to"].userhostJID() |
372 | |
373 if "remove" in options: | |
374 self.removeBookmark(XEP_0048.MUC_TYPE, room_jid, profile_key = profile) | |
375 txt_cmd.feedBack(_("All [%s] bookmarks are being removed") % room_jid.full(), mess_data, profile) | |
376 return False | |
377 | |
331 data = { "name": room_jid.user, | 378 data = { "name": room_jid.user, |
332 "nick": client.jid.user, | 379 "nick": client.jid.user, |
333 "autojoin": "true" if "autojoin" in options else "false", | 380 "autojoin": "true" if "autojoin" in options else "false", |
334 } | 381 } |
335 self.addBookmark(XEP_0048.MUC_TYPE, room_jid, data, profile_key=profile) | 382 self.addBookmark(XEP_0048.MUC_TYPE, room_jid, data, profile_key=profile) |