Mercurial > libervia-backend
annotate src/plugins/plugin_xep_0048.py @ 2291:c05000d00dbb
plugin events, invitations + jp (event/create, invitation/invitee/invite): several emails addresses can now be specified for a single invitation:
if several addresses are specified, the same invitation (same ID and data) is sent to all the addresses
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 30 Jun 2017 00:04:47 +0200 |
parents | 33c8c4973743 |
children | 8b37a62336c3 |
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 = { |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
36 C.PI_NAME: "Bookmarks", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
37 C.PI_IMPORT_NAME: "XEP-0048", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
38 C.PI_TYPE: "XEP", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
39 C.PI_PROTOCOLS: ["XEP-0048"], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
40 C.PI_DEPENDENCIES: ["XEP-0045"], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
41 C.PI_RECOMMENDATIONS: ["XEP-0049"], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
42 C.PI_MAIN: "XEP_0048", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
43 C.PI_HANDLER: "no", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
44 C.PI_DESCRIPTION: _("""Implementation of bookmarks""") |
982
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 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
76 def profileConnected(self, client): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
77 local = client.bookmarks_local = PersistentBinaryDict(NS_BOOKMARKS, client.profile) |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 yield local.load() |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 if not local: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 local[XEP_0048.MUC_TYPE] = dict() |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 local[XEP_0048.URL_TYPE] = dict() |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
82 private = yield self._getServerBookmarks('private', client.profile) |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 pubsub = client.bookmarks_pubsub = None |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 for bookmarks in (local, private, pubsub): |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 if bookmarks is not None: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 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
|
88 if data.get('autojoin', 'false') == 'true': |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 nick = data.get('nick', client.jid.user) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
90 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
|
91 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 @defer.inlineCallbacks |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 def _getServerBookmarks(self, storage_type, profile): |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 """Get distants bookmarks |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 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
|
97 @param storage_type: storage type, can be: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 - 'private': XEP-0049 storage |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 - 'pubsub': XEP-0223 storage |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 @param profile: %(doc_profile)s |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 @return: data dictionary, or None if feature is not available |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 """ |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 client = self.host.getClient(profile) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 if storage_type == 'private': |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 try: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 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
|
107 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
|
108 except (StanzaError, AttributeError): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
989
diff
changeset
|
109 log.info(_("Private XML storage not available")) |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 data = client.bookmarks_private = None |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 elif storage_type == 'pubsub': |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 raise NotImplementedError |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 else: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 raise ValueError("storage_type must be 'private' or 'pubsub'") |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 defer.returnValue(data) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 @defer.inlineCallbacks |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 def _setServerBookmarks(self, storage_type, bookmarks_elt, profile): |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 """Save bookmarks on server |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 @param storage_type: storage type, can be: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 - 'private': XEP-0049 storage |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 - 'pubsub': XEP-0223 storage |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 @param bookmarks_elt (domish.Element): bookmarks XML |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 @param profile: %(doc_profile)s |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 """ |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 if storage_type == 'private': |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 yield self.private_plg.privateXMLStore(bookmarks_elt, profile) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 elif storage_type == 'pubsub': |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 raise NotImplementedError |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 else: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 raise ValueError("storage_type must be 'private' or 'pubsub'") |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 def _bookmarkElt2Dict(self, storage_elt): |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 """Parse bookmarks to get dictionary |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 @param storage_elt (domish.Element): bookmarks storage |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 @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
|
138 - XEP_0048.MUC_TYPE |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 - XEP_0048.URL_TYPE |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 - value (dict): data as for addBookmark |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 """ |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 conf_data = {} |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 url_data = {} |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 conference_elts = storage_elt.elements(NS_BOOKMARKS, 'conference') |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 for conference_elt in conference_elts: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 try: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 room_jid = jid.JID(conference_elt[XEP_0048.MUC_KEY]) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 except KeyError: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
989
diff
changeset
|
150 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
|
151 continue |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 data = conf_data[room_jid] = {} |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 for attr in XEP_0048.MUC_ATTRS: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 if conference_elt.hasAttribute(attr): |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 data[attr] = conference_elt[attr] |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 try: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 data['nick'] = unicode(conference_elt.elements(NS_BOOKMARKS, 'nick').next()) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 except StopIteration: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 pass |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 # 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
|
163 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 url_elts = storage_elt.elements(NS_BOOKMARKS, 'url') |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 for url_elt in url_elts: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 try: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 url = url_elt[XEP_0048.URL_KEY] |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 except KeyError: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
989
diff
changeset
|
169 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
|
170 continue |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 data = url_data[url] = {} |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 for attr in XEP_0048.URL_ATTRS: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 if url_elt.hasAttribute(attr): |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 data[attr] = url_elt[attr] |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 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
|
177 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 def _dict2BookmarkElt(self, type_, data): |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 """Construct a bookmark element from a data dict |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 @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
|
181 - XEP_0048.MUC_TYPE |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 - XEP_0048.URL_TYPE |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 - value (dict): data as for addBookmark |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 @return (domish.Element): bookmark element |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 """ |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 rooms_data = data.get(XEP_0048.MUC_TYPE, {}) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 urls_data = data.get(XEP_0048.URL_TYPE, {}) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 storage_elt = domish.Element((NS_BOOKMARKS, 'storage')) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 for room_jid in rooms_data: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 conference_elt = storage_elt.addElement('conference') |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 conference_elt[XEP_0048.MUC_KEY] = room_jid.full() |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 for attr in XEP_0048.MUC_ATTRS: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 try: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 conference_elt[attr] = rooms_data[room_jid][attr] |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
195 except KeyError: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 pass |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
197 try: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 conference_elt.addElement('nick', content=rooms_data[room_jid]['nick']) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 except KeyError: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 pass |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 for url in urls_data: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 url_elt = storage_elt.addElement('url') |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 url_elt[XEP_0048.URL_KEY] = url |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 for attr in XEP_0048.URL_ATTRS: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 try: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 url_elt[attr] = url[attr] |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 except KeyError: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 pass |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 return storage_elt |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 |
984
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
213 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
|
214 try: |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
215 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
|
216 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
|
217 except (KeyError, RuntimeError): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
989
diff
changeset
|
218 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
|
219 return {} |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
220 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
221 client = self.host.getClient(profile) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
222 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
|
223 def join_eb(failure): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
224 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
|
225 # 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
|
226 return {} |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
227 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
|
228 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
|
229 |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 def _bookmarksMenu(self, data, profile): |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 """ XMLUI activated by menu: return Gateways UI |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 @param profile: %(doc_profile)s |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
233 |
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 client = self.host.getClient(profile) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 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
|
237 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
|
238 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
|
239 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
|
240 continue |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
241 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
|
242 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
|
243 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
|
244 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
|
245 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
|
246 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
|
247 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
|
248 else: |
df8e1b557125
plugin XEP-0048: added list of bookmarks in XMLUI, selecting one join the room
Goffi <goffi@goffi.org>
parents:
983
diff
changeset
|
249 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
|
250 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
|
251 xmlui.addDivider('dash') |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 xmlui.addText(_("add a bookmark")) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 xmlui.changeContainer("pairs") |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
254 xmlui.addLabel(_('Name')) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
255 xmlui.addString('name') |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
256 xmlui.addLabel(_('jid')) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
257 xmlui.addString('jid') |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
258 xmlui.addLabel(_('Nickname')) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
259 xmlui.addString('nick', client.jid.user) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
260 xmlui.addLabel(_('Autojoin')) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
261 xmlui.addBool('autojoin') |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
262 xmlui.changeContainer("vertical") |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
263 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
|
264 return {'xmlui': xmlui.toXml()} |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
265 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
266 def _bookmarksSaveCb(self, data, profile): |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
267 bm_data = xml_tools.XMLUIResult2DataFormResult(data) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
268 try: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
269 location = jid.JID(bm_data.pop('jid')) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
270 except KeyError: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
271 raise exceptions.InternalError("Can't find mandatory key") |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
272 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
|
273 d.addCallback(lambda dummy: {}) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
274 return d |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
275 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
276 @defer.inlineCallbacks |
983
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
277 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
|
278 """Store a new bookmark |
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
279 |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
280 @param type_: bookmark type, one of: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
281 - XEP_0048.MUC_TYPE: Multi-User chat room |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
282 - XEP_0048.URL_TYPE: web page URL |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
283 @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
|
284 @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
|
285 - name: human readable name of the bookmark |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
286 - 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
|
287 - autojoin: "true" if room must be automatically joined on connection |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
288 - password: unused yet TODO |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
289 @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
|
290 - "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
|
291 - "pubsub": PubSub private storage (XEP-0223) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
292 - "private": Private XML storage (XEP-0049) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
293 - "local": Store in SàT database |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
294 @param profile_key: %(doc_profile_key)s |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
295 """ |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
296 assert storage_type in ('auto', 'pubsub', 'private', 'local') |
986 | 297 if type_ == XEP_0048.URL_TYPE and {'autojoin', 'nick'}.intersection(data.keys()): |
298 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
|
299 client = self.host.getClient(profile_key) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
300 if storage_type == 'auto': |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
301 if client.bookmarks_pubsub is not None: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
302 storage_type = 'pubsub' |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
303 elif client.bookmarks_private is not None: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
304 storage_type = 'private' |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
305 else: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
306 storage_type = 'local' |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
989
diff
changeset
|
307 log.warning(_("Bookmarks will be local only")) |
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
989
diff
changeset
|
308 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
|
309 |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
310 if storage_type == 'local': |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
311 client.bookmarks_local[type_][location] = data |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
312 yield client.bookmarks_local.force(type_) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
313 else: |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
314 bookmarks = yield self._getServerBookmarks(storage_type, client.profile) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
315 bookmarks[type_][location] = data |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
316 bookmark_elt = self._dict2BookmarkElt(type_, bookmarks) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
317 yield self._setServerBookmarks(storage_type, bookmark_elt, client.profile) |
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
318 |
985
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
319 @defer.inlineCallbacks |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
320 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
|
321 """Remove a stored bookmark |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
322 |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
323 @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
|
324 - 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
|
325 - 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
|
326 @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
|
327 @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
|
328 - "all": remove from everywhere |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
329 - "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
|
330 - "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
|
331 - "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
|
332 @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
|
333 """ |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
334 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
|
335 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
|
336 |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
337 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
|
338 try: |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
339 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
|
340 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
|
341 except KeyError: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
989
diff
changeset
|
342 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
|
343 |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
344 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
|
345 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
|
346 try: |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
347 del bookmarks[type_][location] |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
348 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
|
349 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
|
350 except KeyError: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
989
diff
changeset
|
351 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
|
352 |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
353 if storage_type == 'pubsub': |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
354 raise NotImplementedError |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
355 |
986 | 356 def _bookmarksList(self, type_, storage_location, profile_key=C.PROF_KEY_NONE): |
357 """Return stored bookmarks | |
358 | |
359 @param type_: bookmark type, one of: | |
360 - XEP_0048.MUC_TYPE: Multi-User chat room | |
361 - XEP_0048.URL_TYPE: web page URL | |
362 @param storage_location: can be: | |
363 - 'all' | |
364 - 'local' | |
365 - 'private' | |
366 - 'pubsub' | |
367 @param profile_key: %(doc_profile_key)s | |
368 @param return (dict): (key: storage_location, value dict) with: | |
369 - value (dict): (key: bookmark_location, value: bookmark data) | |
370 """ | |
371 client = self.host.getClient(profile_key) | |
372 ret = {} | |
373 ret_d = defer.succeed(ret) | |
374 | |
375 def fillBookmarks(dummy, _storage_location): | |
376 bookmarks_ori = getattr(client, "bookmarks_" + _storage_location) | |
377 if bookmarks_ori is None: | |
378 return ret | |
379 data = bookmarks_ori[type_] | |
380 for bookmark in data: | |
381 ret[_storage_location][bookmark.full()] = data[bookmark].copy() | |
382 return ret | |
383 | |
384 for _storage_location in ('local', 'private', 'pubsub'): | |
385 if storage_location in ('all', _storage_location): | |
386 ret[_storage_location] = {} | |
387 if _storage_location in ('private',): | |
388 # we update distant bookmarks, just in case an other client added something | |
389 d = self._getServerBookmarks(_storage_location, client.profile) | |
390 else: | |
391 d = defer.succeed(None) | |
392 d.addCallback(fillBookmarks, _storage_location) | |
393 ret_d.addCallback(lambda dummy: d) | |
394 | |
395 return ret_d | |
396 | |
397 def _bookmarksRemove(self, type_, location, storage_location, profile_key=C.PROF_KEY_NONE): | |
398 """Return stored bookmarks | |
399 | |
400 @param type_: bookmark type, one of: | |
401 - XEP_0048.MUC_TYPE: Multi-User chat room | |
402 - XEP_0048.URL_TYPE: web page URL | |
403 @param location: dependeding on type_, can be a MUC room jid or an url | |
404 @param storage_location: can be: | |
405 - "all": remove from everywhere | |
406 - "pubsub": PubSub private storage (XEP-0223) | |
407 - "private": Private XML storage (XEP-0049) | |
408 - "local": Store in SàT database | |
409 @param profile_key: %(doc_profile_key)s | |
410 """ | |
411 if type_ == XEP_0048.MUC_TYPE: | |
412 location = jid.JID(location) | |
413 return self.removeBookmark(type_, location, storage_location, profile_key) | |
414 | |
415 def _bookmarksAdd(self, type_, location, data, storage_type="auto", profile_key=C.PROF_KEY_NONE): | |
416 if type_ == XEP_0048.MUC_TYPE: | |
417 location = jid.JID(location) | |
418 return self.addBookmark(type_, location, data, storage_type, profile_key) | |
419 | |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
420 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
|
421 """(Un)bookmark a MUC room |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
422 |
985
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
423 @command (group): [autojoin | remove] |
983
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
424 - autojoin: join room automatically on connection |
1373
6d0e01809893
plugin text commands: minor docstrings improvments
Goffi <goffi@goffi.org>
parents:
1371
diff
changeset
|
425 - remove: remove bookmark(s) for this room |
983
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
426 """ |
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
427 txt_cmd = self.host.plugins[C.TEXT_CMDS] |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
428 |
983
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
429 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
|
430 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
|
431 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
|
432 return False |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
433 |
983
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
434 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
|
435 |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
436 if "remove" in options: |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
437 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
|
438 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
|
439 return False |
9ebdba4ab907
plugin XEP-0048: bookmarks deletion + added "delete" option for /bookmark command
Goffi <goffi@goffi.org>
parents:
984
diff
changeset
|
440 |
983
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
441 data = { "name": room_jid.user, |
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
442 "nick": client.jid.user, |
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
443 "autojoin": "true" if "autojoin" in options else "false", |
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
444 } |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
445 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
|
446 txt_cmd.feedBack(client, _("Bookmark added"), mess_data) |
982
0e80ee1fe9af
plugin XEP-0048: bookmarks (first draft)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
447 |
983
c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
Goffi <goffi@goffi.org>
parents:
982
diff
changeset
|
448 return False |