Mercurial > libervia-backend
annotate src/plugins/plugin_xep_0048.py @ 1992:d5befe7253aa
plugin XEP-0045: fixed typo in text commands
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 02 Jul 2016 20:55:31 +0200 |
parents | a2bc5089c2eb |
children | 1d3f73e065e1 |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
1 #!/usr/bin/env python2 |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # SAT plugin for Bookmarks (xep-0048) |
1766 | 5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org) |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 from sat.core.i18n import _, D_ |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 from sat.core import exceptions |
983
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
22 from sat.core.constants import Const as C |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from sat.memory.persistent import PersistentBinaryDict |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from sat.tools import xml_tools |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
989
diff
changeset
|
25 from sat.core.log import getLogger |
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
989
diff
changeset
|
26 log = getLogger(__name__) |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from twisted.words.xish import domish |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from twisted.words.protocols.jabber import jid |
989
93359853e4bc
plugins XEP-0048, XEP-0049: feature is not checked anymore before using private XML storage, as feature announcement is not mandatory in XEP-0049
Goffi <goffi@goffi.org>
parents:
986
diff
changeset
|
29 from twisted.words.protocols.jabber.error import StanzaError |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 from twisted.internet import defer |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 NS_BOOKMARKS = 'storage:bookmarks' |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 PLUGIN_INFO = { |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 "name": "Bookmarks", |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 "import_name": "XEP-0048", |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 "type": "XEP", |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 "protocols": ["XEP-0048"], |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 "dependencies": ["XEP-0045"], |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 "recommendations": ["XEP-0049"], |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 "main": "XEP_0048", |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 "handler": "no", |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 "description": _("""Implementation of bookmarks""") |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 } |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 class XEP_0048(object): |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 MUC_TYPE = 'muc' |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 URL_TYPE = 'url' |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 MUC_KEY = 'jid' |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 URL_KEY = 'url' |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 MUC_ATTRS = ('autojoin', 'name') |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 URL_ATTRS = ('name',) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 def __init__(self, host): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
989
diff
changeset
|
57 log.info(_("Bookmarks plugin initialization")) |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 self.host = host |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 # self.__menu_id = host.registerCallback(self._bookmarksMenu, with_data=True) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 self.__bm_save_id = host.registerCallback(self._bookmarksSaveCb, with_data=True) |
1707
94c450972346
primitivus and plugins: renamed a few menus:
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
61 host.importMenu((D_("Groups"), D_("Bookmarks")), self._bookmarksMenu, security_limit=0, help_string=D_("Use and manage bookmarks")) |
984
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
62 self.__selected_id = host.registerCallback(self._bookmarkSelectedCb, with_data=True) |
986 | 63 host.bridge.addMethod("bookmarksList", ".plugin", in_sign='sss', out_sign='a{sa{sa{ss}}}', method=self._bookmarksList, async=True) |
64 host.bridge.addMethod("bookmarksRemove", ".plugin", in_sign='ssss', out_sign='', method=self._bookmarksRemove, async=True) | |
65 host.bridge.addMethod("bookmarksAdd", ".plugin", in_sign='ssa{ss}ss', out_sign='', method=self._bookmarksAdd, async=True) | |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 try: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 self.private_plg = self.host.plugins["XEP-0049"] |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 except KeyError: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 self.private_plg = None |
983
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
70 try: |
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
71 self.host.plugins[C.TEXT_CMDS].registerTextCommands(self) |
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
72 except KeyError: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
989
diff
changeset
|
73 log.info(_("Text commands not available")) |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 @defer.inlineCallbacks |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 def profileConnected(self, profile): |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 client = self.host.getClient(profile) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 local = client.bookmarks_local = PersistentBinaryDict(NS_BOOKMARKS, profile) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 yield local.load() |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 if not local: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 local[XEP_0048.MUC_TYPE] = dict() |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 local[XEP_0048.URL_TYPE] = dict() |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 private = yield self._getServerBookmarks('private', profile) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 pubsub = client.bookmarks_pubsub = None |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 for bookmarks in (local, private, pubsub): |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 if bookmarks is not None: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 for (room_jid, data) in bookmarks[XEP_0048.MUC_TYPE].items(): |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 if data.get('autojoin', 'false') == 'true': |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 nick = data.get('nick', client.jid.user) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
91 self.host.plugins['XEP-0045'].join(client, room_jid, nick, {}) |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 @defer.inlineCallbacks |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 def _getServerBookmarks(self, storage_type, profile): |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 """Get distants bookmarks |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 update also the client.bookmarks_[type] key, with None if service is not available |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 @param storage_type: storage type, can be: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 - 'private': XEP-0049 storage |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 - 'pubsub': XEP-0223 storage |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 @param profile: %(doc_profile)s |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 @return: data dictionary, or None if feature is not available |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 """ |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 client = self.host.getClient(profile) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 if storage_type == 'private': |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 try: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 bookmarks_private_xml = yield self.private_plg.privateXMLGet('storage', NS_BOOKMARKS, profile) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 data = client.bookmarks_private = self._bookmarkElt2Dict(bookmarks_private_xml) |
989
93359853e4bc
plugins XEP-0048, XEP-0049: feature is not checked anymore before using private XML storage, as feature announcement is not mandatory in XEP-0049
Goffi <goffi@goffi.org>
parents:
986
diff
changeset
|
109 except (StanzaError, AttributeError): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
989
diff
changeset
|
110 log.info(_("Private XML storage not available")) |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 data = client.bookmarks_private = None |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 elif storage_type == 'pubsub': |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 raise NotImplementedError |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 else: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 raise ValueError("storage_type must be 'private' or 'pubsub'") |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 defer.returnValue(data) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 @defer.inlineCallbacks |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 def _setServerBookmarks(self, storage_type, bookmarks_elt, profile): |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 """Save bookmarks on server |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 @param storage_type: storage type, can be: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 - 'private': XEP-0049 storage |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 - 'pubsub': XEP-0223 storage |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 @param bookmarks_elt (domish.Element): bookmarks XML |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 @param profile: %(doc_profile)s |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 """ |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 if storage_type == 'private': |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 yield self.private_plg.privateXMLStore(bookmarks_elt, profile) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 elif storage_type == 'pubsub': |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 raise NotImplementedError |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 else: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 raise ValueError("storage_type must be 'private' or 'pubsub'") |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 def _bookmarkElt2Dict(self, storage_elt): |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 """Parse bookmarks to get dictionary |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 @param storage_elt (domish.Element): bookmarks storage |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 @return (dict): bookmark data (key: bookmark type, value: list) where key can be: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 - XEP_0048.MUC_TYPE |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 - XEP_0048.URL_TYPE |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 - value (dict): data as for addBookmark |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 """ |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 conf_data = {} |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 url_data = {} |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 conference_elts = storage_elt.elements(NS_BOOKMARKS, 'conference') |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 for conference_elt in conference_elts: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 try: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 room_jid = jid.JID(conference_elt[XEP_0048.MUC_KEY]) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 except KeyError: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
989
diff
changeset
|
151 log.warning ("invalid bookmark found, igoring it:\n%s" % conference_elt.toXml()) |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 continue |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 data = conf_data[room_jid] = {} |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 for attr in XEP_0048.MUC_ATTRS: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 if conference_elt.hasAttribute(attr): |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 data[attr] = conference_elt[attr] |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 try: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 data['nick'] = unicode(conference_elt.elements(NS_BOOKMARKS, 'nick').next()) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 except StopIteration: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 pass |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 # TODO: manage password (need to be secured, see XEP-0049 §4) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 url_elts = storage_elt.elements(NS_BOOKMARKS, 'url') |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 for url_elt in url_elts: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 try: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 url = url_elt[XEP_0048.URL_KEY] |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 except KeyError: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
989
diff
changeset
|
170 log.warning ("invalid bookmark found, igoring it:\n%s" % url_elt.toXml()) |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 continue |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 data = url_data[url] = {} |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 for attr in XEP_0048.URL_ATTRS: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 if url_elt.hasAttribute(attr): |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 data[attr] = url_elt[attr] |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 return {XEP_0048.MUC_TYPE: conf_data, XEP_0048.URL_TYPE: url_data} |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 def _dict2BookmarkElt(self, type_, data): |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 """Construct a bookmark element from a data dict |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 @param data (dict): bookmark data (key: bookmark type, value: list) where key can be: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 - XEP_0048.MUC_TYPE |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 - XEP_0048.URL_TYPE |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 - value (dict): data as for addBookmark |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 @return (domish.Element): bookmark element |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 """ |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 rooms_data = data.get(XEP_0048.MUC_TYPE, {}) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 urls_data = data.get(XEP_0048.URL_TYPE, {}) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 storage_elt = domish.Element((NS_BOOKMARKS, 'storage')) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 for room_jid in rooms_data: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 conference_elt = storage_elt.addElement('conference') |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 conference_elt[XEP_0048.MUC_KEY] = room_jid.full() |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 for attr in XEP_0048.MUC_ATTRS: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 try: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
195 conference_elt[attr] = rooms_data[room_jid][attr] |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 except KeyError: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
197 pass |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 try: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 conference_elt.addElement('nick', content=rooms_data[room_jid]['nick']) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 except KeyError: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 pass |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 for url in urls_data: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 url_elt = storage_elt.addElement('url') |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 url_elt[XEP_0048.URL_KEY] = url |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 for attr in XEP_0048.URL_ATTRS: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 try: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 url_elt[attr] = url[attr] |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 except KeyError: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 pass |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 return storage_elt |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 |
984
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
214 def _bookmarkSelectedCb(self, data, profile): |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
215 try: |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
216 room_jid_s, nick = data['index'].split(' ', 1) |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
217 room_jid = jid.JID(room_jid_s) |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
218 except (KeyError, RuntimeError): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
989
diff
changeset
|
219 log.warning(_("No room jid selected")) |
984
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
220 return {} |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
221 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
222 client = self.host.getClient(profile) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
223 d = self.host.plugins['XEP-0045'].join(client, room_jid, nick, {}) |
984
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
224 def join_eb(failure): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
225 log.warning(u"Error while trying to join room: {}".format(failure)) |
984
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
226 # FIXME: failure are badly managed in plugin XEP-0045. Plugin XEP-0045 need to be fixed before managing errors correctly here |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
227 return {} |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
228 d.addCallbacks(lambda dummy: {}, join_eb) |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
229 return d |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
230 |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 def _bookmarksMenu(self, data, profile): |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 """ XMLUI activated by menu: return Gateways UI |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
233 @param profile: %(doc_profile)s |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
234 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
235 """ |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 client = self.host.getClient(profile) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 xmlui = xml_tools.XMLUI(title=_('Bookmarks manager')) |
984
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
238 adv_list = xmlui.changeContainer('advanced_list', columns=3, selectable='single', callback_id=self.__selected_id) |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
239 for bookmarks in (client.bookmarks_local, client.bookmarks_private, client.bookmarks_pubsub): |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
240 if bookmarks is None: |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
241 continue |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
242 for (room_jid, data) in sorted(bookmarks[XEP_0048.MUC_TYPE].items(), key=lambda item: item[1].get('name',item[0].user)): |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
243 room_jid_s = room_jid.full() |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
244 adv_list.setRowIndex(u'%s %s' % (room_jid_s, data.get('nick') or client.jid.user)) |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
245 xmlui.addText(data.get('name','')) |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
246 xmlui.addJid(room_jid) |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
247 if data.get('autojoin', 'false') == 'true': |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
248 xmlui.addText('autojoin') |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
249 else: |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
250 xmlui.addEmpty() |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
251 adv_list.end() |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
252 xmlui.addDivider('dash') |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 xmlui.addText(_("add a bookmark")) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
254 xmlui.changeContainer("pairs") |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
255 xmlui.addLabel(_('Name')) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
256 xmlui.addString('name') |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
257 xmlui.addLabel(_('jid')) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
258 xmlui.addString('jid') |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
259 xmlui.addLabel(_('Nickname')) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
260 xmlui.addString('nick', client.jid.user) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
261 xmlui.addLabel(_('Autojoin')) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
262 xmlui.addBool('autojoin') |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
263 xmlui.changeContainer("vertical") |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
264 xmlui.addButton(self.__bm_save_id, _("Save"), ('name', 'jid', 'nick', 'autojoin')) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
265 return {'xmlui': xmlui.toXml()} |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
266 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
267 def _bookmarksSaveCb(self, data, profile): |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
268 bm_data = xml_tools.XMLUIResult2DataFormResult(data) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
269 try: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
270 location = jid.JID(bm_data.pop('jid')) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
271 except KeyError: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
272 raise exceptions.InternalError("Can't find mandatory key") |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
273 d = self.addBookmark(XEP_0048.MUC_TYPE, location, bm_data, profile_key=profile) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
274 d.addCallback(lambda dummy: {}) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
275 return d |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
276 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
277 @defer.inlineCallbacks |
983
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
278 def addBookmark(self, type_, location, data, storage_type="auto", profile_key=C.PROF_KEY_NONE): |
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
279 """Store a new bookmark |
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
280 |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
281 @param type_: bookmark type, one of: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
282 - XEP_0048.MUC_TYPE: Multi-User chat room |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
283 - XEP_0048.URL_TYPE: web page URL |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
284 @param location: dependeding on type_, can be a MUC room jid or an url |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
285 @param data (dict): depending on type_, can contains the following keys: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
286 - name: human readable name of the bookmark |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
287 - nick: user preferred room nick (default to user part of profile's jid) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
288 - autojoin: "true" if room must be automatically joined on connection |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
289 - password: unused yet TODO |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
290 @param storage_type: where the bookmark will be stored, can be: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
291 - "auto": find best available option: pubsub, private, local in that order |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
292 - "pubsub": PubSub private storage (XEP-0223) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
293 - "private": Private XML storage (XEP-0049) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
294 - "local": Store in SàT database |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
295 @param profile_key: %(doc_profile_key)s |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
296 """ |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
297 assert storage_type in ('auto', 'pubsub', 'private', 'local') |
986 | 298 if type_ == XEP_0048.URL_TYPE and {'autojoin', 'nick'}.intersection(data.keys()): |
299 raise ValueError("autojoin or nick can't be used with URLs") | |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
300 client = self.host.getClient(profile_key) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
301 if storage_type == 'auto': |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
302 if client.bookmarks_pubsub is not None: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
303 storage_type = 'pubsub' |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
304 elif client.bookmarks_private is not None: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
305 storage_type = 'private' |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
306 else: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
307 storage_type = 'local' |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
989
diff
changeset
|
308 log.warning(_("Bookmarks will be local only")) |
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
989
diff
changeset
|
309 log.info(_('Type selected for "auto" storage: %s') % storage_type) |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
310 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
311 if storage_type == 'local': |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
312 client.bookmarks_local[type_][location] = data |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
313 yield client.bookmarks_local.force(type_) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
314 else: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
315 bookmarks = yield self._getServerBookmarks(storage_type, client.profile) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
316 bookmarks[type_][location] = data |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
317 bookmark_elt = self._dict2BookmarkElt(type_, bookmarks) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
318 yield self._setServerBookmarks(storage_type, bookmark_elt, client.profile) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
319 |
985
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
320 @defer.inlineCallbacks |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
321 def removeBookmark(self, type_, location, storage_type="all", profile_key=C.PROF_KEY_NONE): |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
322 """Remove a stored bookmark |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
323 |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
324 @param type_: bookmark type, one of: |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
325 - XEP_0048.MUC_TYPE: Multi-User chat room |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
326 - XEP_0048.URL_TYPE: web page URL |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
327 @param location: dependeding on type_, can be a MUC room jid or an url |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
328 @param storage_type: where the bookmark is stored, can be: |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
329 - "all": remove from everywhere |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
330 - "pubsub": PubSub private storage (XEP-0223) |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
331 - "private": Private XML storage (XEP-0049) |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
332 - "local": Store in SàT database |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
333 @param profile_key: %(doc_profile_key)s |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
334 """ |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
335 assert storage_type in ('all', 'pubsub', 'private', 'local') |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
336 client = self.host.getClient(profile_key) |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
337 |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
338 if storage_type in ('all', 'local'): |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
339 try: |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
340 del client.bookmarks_local[type_][location] |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
341 yield client.bookmarks_local.force(type_) |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
342 except KeyError: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
989
diff
changeset
|
343 log.debug("Bookmark is not present in local storage") |
985
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
344 |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
345 if storage_type in ('all', 'private'): |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
346 bookmarks = yield self._getServerBookmarks('private', client.profile) |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
347 try: |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
348 del bookmarks[type_][location] |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
349 bookmark_elt = self._dict2BookmarkElt(type_, bookmarks) |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
350 yield self._setServerBookmarks('private', bookmark_elt, client.profile) |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
351 except KeyError: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
989
diff
changeset
|
352 log.debug("Bookmark is not present in private storage") |
985
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
353 |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
354 if storage_type == 'pubsub': |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
355 raise NotImplementedError |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
356 |
986 | 357 def _bookmarksList(self, type_, storage_location, profile_key=C.PROF_KEY_NONE): |
358 """Return stored bookmarks | |
359 | |
360 @param type_: bookmark type, one of: | |
361 - XEP_0048.MUC_TYPE: Multi-User chat room | |
362 - XEP_0048.URL_TYPE: web page URL | |
363 @param storage_location: can be: | |
364 - 'all' | |
365 - 'local' | |
366 - 'private' | |
367 - 'pubsub' | |
368 @param profile_key: %(doc_profile_key)s | |
369 @param return (dict): (key: storage_location, value dict) with: | |
370 - value (dict): (key: bookmark_location, value: bookmark data) | |
371 """ | |
372 client = self.host.getClient(profile_key) | |
373 ret = {} | |
374 ret_d = defer.succeed(ret) | |
375 | |
376 def fillBookmarks(dummy, _storage_location): | |
377 bookmarks_ori = getattr(client, "bookmarks_" + _storage_location) | |
378 if bookmarks_ori is None: | |
379 return ret | |
380 data = bookmarks_ori[type_] | |
381 for bookmark in data: | |
382 ret[_storage_location][bookmark.full()] = data[bookmark].copy() | |
383 return ret | |
384 | |
385 for _storage_location in ('local', 'private', 'pubsub'): | |
386 if storage_location in ('all', _storage_location): | |
387 ret[_storage_location] = {} | |
388 if _storage_location in ('private',): | |
389 # we update distant bookmarks, just in case an other client added something | |
390 d = self._getServerBookmarks(_storage_location, client.profile) | |
391 else: | |
392 d = defer.succeed(None) | |
393 d.addCallback(fillBookmarks, _storage_location) | |
394 ret_d.addCallback(lambda dummy: d) | |
395 | |
396 return ret_d | |
397 | |
398 def _bookmarksRemove(self, type_, location, storage_location, profile_key=C.PROF_KEY_NONE): | |
399 """Return stored bookmarks | |
400 | |
401 @param type_: bookmark type, one of: | |
402 - XEP_0048.MUC_TYPE: Multi-User chat room | |
403 - XEP_0048.URL_TYPE: web page URL | |
404 @param location: dependeding on type_, can be a MUC room jid or an url | |
405 @param storage_location: can be: | |
406 - "all": remove from everywhere | |
407 - "pubsub": PubSub private storage (XEP-0223) | |
408 - "private": Private XML storage (XEP-0049) | |
409 - "local": Store in SàT database | |
410 @param profile_key: %(doc_profile_key)s | |
411 """ | |
412 if type_ == XEP_0048.MUC_TYPE: | |
413 location = jid.JID(location) | |
414 return self.removeBookmark(type_, location, storage_location, profile_key) | |
415 | |
416 def _bookmarksAdd(self, type_, location, data, storage_type="auto", profile_key=C.PROF_KEY_NONE): | |
417 if type_ == XEP_0048.MUC_TYPE: | |
418 location = jid.JID(location) | |
419 return self.addBookmark(type_, location, data, storage_type, profile_key) | |
420 | |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
421 def cmd_bookmark(self, client, mess_data): |
985
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
422 """(Un)bookmark a MUC room |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
423 |
985
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
424 @command (group): [autojoin | remove] |
983
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
425 - autojoin: join room automatically on connection |
1373
6d0e01809893
plugin text commands: minor docstrings improvments
Goffi <goffi@goffi.org>
parents:
1371
diff
changeset
|
426 - remove: remove bookmark(s) for this room |
983
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
427 """ |
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
428 txt_cmd = self.host.plugins[C.TEXT_CMDS] |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
429 |
983
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
430 options = mess_data["unparsed"].strip().split() |
985
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
431 if options and options[0] not in ('autojoin', 'remove'): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
432 txt_cmd.feedBack(client, _("Bad arguments"), mess_data) |
985
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
433 return False |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
434 |
983
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
435 room_jid = mess_data["to"].userhostJID() |
985
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
436 |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
437 if "remove" in options: |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
438 self.removeBookmark(XEP_0048.MUC_TYPE, room_jid, profile_key = client.profile) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
439 txt_cmd.feedBack(client, _("All [%s] bookmarks are being removed") % room_jid.full(), mess_data) |
985
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
440 return False |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
441 |
983
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
442 data = { "name": room_jid.user, |
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
443 "nick": client.jid.user, |
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
444 "autojoin": "true" if "autojoin" in options else "false", |
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
445 } |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
446 self.addBookmark(XEP_0048.MUC_TYPE, room_jid, data, profile_key=client.profile) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
447 txt_cmd.feedBack(client, _("Bookmark added"), mess_data) |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
448 |
983
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
449 return False |