plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command

This commit is contained in:
Goffi 2014-04-07 16:24:29 +02:00
commit 643aa4dfb7

View file

@ -311,10 +311,47 @@ class XEP_0048(object):
bookmark_elt = self._dict2BookmarkElt(type_, bookmarks)
yield self._setServerBookmarks(storage_type, bookmark_elt, client.profile)
def cmd_bookmark(self, mess_data, profile):
"""Bookmark a MUC room
@defer.inlineCallbacks
def removeBookmark(self, type_, location, storage_type="all", profile_key=C.PROF_KEY_NONE):
"""Remove a stored bookmark
@command (group): [autojoin]
@param type_: bookmark type, one of:
- XEP_0048.MUC_TYPE: Multi-User chat room
- XEP_0048.URL_TYPE: web page URL
@param location: dependeding on type_, can be a MUC room jid or an url
@param storage_type: where the bookmark is stored, can be:
- "all": remove from everywhere
- "pubsub": PubSub private storage (XEP-0223)
- "private": Private XML storage (XEP-0049)
- "local": Store in SàT database
@param profile_key: %(doc_profile_key)s
"""
assert storage_type in ('all', 'pubsub', 'private', 'local')
client = self.host.getClient(profile_key)
if storage_type in ('all', 'local'):
try:
del client.bookmarks_local[type_][location]
yield client.bookmarks_local.force(type_)
except KeyError:
debug("Bookmark is not present in local storage")
if storage_type in ('all', 'private'):
bookmarks = yield self._getServerBookmarks('private', client.profile)
try:
del bookmarks[type_][location]
bookmark_elt = self._dict2BookmarkElt(type_, bookmarks)
yield self._setServerBookmarks('private', bookmark_elt, client.profile)
except KeyError:
debug("Bookmark is not present in private storage")
if storage_type == 'pubsub':
raise NotImplementedError
def cmd_bookmark(self, mess_data, profile):
"""(Un)bookmark a MUC room
@command (group): [autojoin | remove]
- autojoin: join room automatically on connection
"""
debug("Catched bookmark command")
@ -327,7 +364,17 @@ class XEP_0048(object):
return True
options = mess_data["unparsed"].strip().split()
if options and options[0] not in ('autojoin', 'remove'):
txt_cmd.feedBack(_("Bad arguments"), mess_data, profile)
return False
room_jid = mess_data["to"].userhostJID()
if "remove" in options:
self.removeBookmark(XEP_0048.MUC_TYPE, room_jid, profile_key = profile)
txt_cmd.feedBack(_("All [%s] bookmarks are being removed") % room_jid.full(), mess_data, profile)
return False
data = { "name": room_jid.user,
"nick": client.jid.user,
"autojoin": "true" if "autojoin" in options else "false",