jp: added bookmarks subcommands
This commit is contained in:
parent
643aa4dfb7
commit
9dcec3eab7
1 changed files with 188 additions and 0 deletions
|
|
@ -58,6 +58,9 @@ class XEP_0048(object):
|
|||
self.__bm_save_id = host.registerCallback(self._bookmarksSaveCb, with_data=True)
|
||||
host.importMenu((D_("Communication"), D_("bookmarks")), self._bookmarksMenu, security_limit=0, help_string=D_("Use and manage bookmarks"))
|
||||
self.__selected_id = host.registerCallback(self._bookmarkSelectedCb, with_data=True)
|
||||
host.bridge.addMethod("bookmarksList", ".plugin", in_sign='sss', out_sign='a{sa{sa{ss}}}', method=self._bookmarksList, async=True)
|
||||
host.bridge.addMethod("bookmarksRemove", ".plugin", in_sign='ssss', out_sign='', method=self._bookmarksRemove, async=True)
|
||||
host.bridge.addMethod("bookmarksAdd", ".plugin", in_sign='ssa{ss}ss', out_sign='', method=self._bookmarksAdd, async=True)
|
||||
try:
|
||||
self.private_plg = self.host.plugins["XEP-0049"]
|
||||
except KeyError:
|
||||
|
|
@ -291,6 +294,8 @@ class XEP_0048(object):
|
|||
@param profile_key: %(doc_profile_key)s
|
||||
"""
|
||||
assert storage_type in ('auto', 'pubsub', 'private', 'local')
|
||||
if type_ == XEP_0048.URL_TYPE and {'autojoin', 'nick'}.intersection(data.keys()):
|
||||
raise ValueError("autojoin or nick can't be used with URLs")
|
||||
client = self.host.getClient(profile_key)
|
||||
if storage_type == 'auto':
|
||||
if client.bookmarks_pubsub is not None:
|
||||
|
|
@ -348,6 +353,70 @@ class XEP_0048(object):
|
|||
if storage_type == 'pubsub':
|
||||
raise NotImplementedError
|
||||
|
||||
def _bookmarksList(self, type_, storage_location, profile_key=C.PROF_KEY_NONE):
|
||||
"""Return stored bookmarks
|
||||
|
||||
@param type_: bookmark type, one of:
|
||||
- XEP_0048.MUC_TYPE: Multi-User chat room
|
||||
- XEP_0048.URL_TYPE: web page URL
|
||||
@param storage_location: can be:
|
||||
- 'all'
|
||||
- 'local'
|
||||
- 'private'
|
||||
- 'pubsub'
|
||||
@param profile_key: %(doc_profile_key)s
|
||||
@param return (dict): (key: storage_location, value dict) with:
|
||||
- value (dict): (key: bookmark_location, value: bookmark data)
|
||||
"""
|
||||
client = self.host.getClient(profile_key)
|
||||
ret = {}
|
||||
ret_d = defer.succeed(ret)
|
||||
|
||||
def fillBookmarks(dummy, _storage_location):
|
||||
bookmarks_ori = getattr(client, "bookmarks_" + _storage_location)
|
||||
if bookmarks_ori is None:
|
||||
return ret
|
||||
data = bookmarks_ori[type_]
|
||||
for bookmark in data:
|
||||
ret[_storage_location][bookmark.full()] = data[bookmark].copy()
|
||||
return ret
|
||||
|
||||
for _storage_location in ('local', 'private', 'pubsub'):
|
||||
if storage_location in ('all', _storage_location):
|
||||
ret[_storage_location] = {}
|
||||
if _storage_location in ('private',):
|
||||
# we update distant bookmarks, just in case an other client added something
|
||||
d = self._getServerBookmarks(_storage_location, client.profile)
|
||||
else:
|
||||
d = defer.succeed(None)
|
||||
d.addCallback(fillBookmarks, _storage_location)
|
||||
ret_d.addCallback(lambda dummy: d)
|
||||
|
||||
return ret_d
|
||||
|
||||
def _bookmarksRemove(self, type_, location, storage_location, profile_key=C.PROF_KEY_NONE):
|
||||
"""Return stored bookmarks
|
||||
|
||||
@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_location: 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
|
||||
"""
|
||||
if type_ == XEP_0048.MUC_TYPE:
|
||||
location = jid.JID(location)
|
||||
return self.removeBookmark(type_, location, storage_location, profile_key)
|
||||
|
||||
def _bookmarksAdd(self, type_, location, data, storage_type="auto", profile_key=C.PROF_KEY_NONE):
|
||||
if type_ == XEP_0048.MUC_TYPE:
|
||||
location = jid.JID(location)
|
||||
return self.addBookmark(type_, location, data, storage_type, profile_key)
|
||||
|
||||
def cmd_bookmark(self, mess_data, profile):
|
||||
"""(Un)bookmark a MUC room
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue