Mercurial > libervia-backend
annotate sat/plugins/plugin_xep_0060.py @ 3635:7bc443253b7c
merge branche "@"
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 28 Aug 2021 15:32:58 +0200 |
parents | 5d108ce026d7 |
children | 1cdb9d9fad6b |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
3 # SàT plugin for Publish-Subscribe (xep-0060) |
3479 | 4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
9 # (at your option) any later version. |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
14 # GNU Affero General Public License for more details. |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
3062
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
19 |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
20 from typing import Optional, List, Tuple |
3062
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
21 from collections import namedtuple |
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
22 import urllib.request, urllib.parse, urllib.error |
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
23 from functools import reduce |
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
24 from zope.interface import implementer |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
25 from twisted.words.xish import domish |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
26 from twisted.words.protocols.jabber import jid, error |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
27 from twisted.internet import reactor, defer |
1449
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
28 from wokkel import disco |
1777 | 29 from wokkel import data_form |
2413
70399d1acb47
tmp: removed sat.tmp hierarchy and fixed references to it as it is now an independant sat_tmp repository
Goffi <goffi@goffi.org>
parents:
2393
diff
changeset
|
30 # XXX: sat_tmp.wokkel.pubsub is actually use instead of wokkel version |
70399d1acb47
tmp: removed sat.tmp hierarchy and fixed references to it as it is now an independant sat_tmp repository
Goffi <goffi@goffi.org>
parents:
2393
diff
changeset
|
31 # mam and rsm come from sat_tmp.wokkel too |
1449
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
32 from wokkel import pubsub |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
33 from wokkel import rsm |
1777 | 34 from wokkel import mam |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
35 from sat.core.i18n import _ |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
36 from sat.core.constants import Const as C |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
37 from sat.core.log import getLogger |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
38 from sat.core.core_types import SatXMPPEntity |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
39 from sat.core import exceptions |
3588
2c7a52a62be3
plugin XEP-0060: events callbacks can now be sync or async
Goffi <goffi@goffi.org>
parents:
3587
diff
changeset
|
40 from sat.tools import utils |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
41 from sat.tools import sat_defer |
3394
23af257ae780
plugin XEP-0060: use `xml_tools.parse` instead of `wokkel.generic.parseXml`:
Goffi <goffi@goffi.org>
parents:
3312
diff
changeset
|
42 from sat.tools import xml_tools |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
43 from sat.tools.common import data_format |
3062
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
44 |
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
45 |
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
46 log = getLogger(__name__) |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 PLUGIN_INFO = { |
3028 | 49 C.PI_NAME: "Publish-Subscribe", |
50 C.PI_IMPORT_NAME: "XEP-0060", | |
51 C.PI_TYPE: "XEP", | |
52 C.PI_PROTOCOLS: ["XEP-0060"], | |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
53 C.PI_DEPENDENCIES: [], |
3028 | 54 C.PI_RECOMMENDATIONS: ["XEP-0059", "XEP-0313"], |
55 C.PI_MAIN: "XEP_0060", | |
56 C.PI_HANDLER: "yes", | |
57 C.PI_DESCRIPTION: _("""Implementation of PubSub Protocol"""), | |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 } |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 |
1777 | 60 UNSPECIFIED = "unspecified error" |
61 | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
62 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
63 Extra = namedtuple("Extra", ("rsm_request", "extra")) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
64 # rsm_request is the rsm.RSMRequest build with rsm_ prefixed keys, or None |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
65 # extra is a potentially empty dict |
2769
9282b289b964
plugin XEP-0060: set a 30s timeout on items get
Goffi <goffi@goffi.org>
parents:
2760
diff
changeset
|
66 TIMEOUT = 30 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
67 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
68 class XEP_0060(object): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
69 OPT_ACCESS_MODEL = "pubsub#access_model" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
70 OPT_PERSIST_ITEMS = "pubsub#persist_items" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
71 OPT_MAX_ITEMS = "pubsub#max_items" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
72 OPT_DELIVER_PAYLOADS = "pubsub#deliver_payloads" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
73 OPT_SEND_ITEM_SUBSCRIBE = "pubsub#send_item_subscribe" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
74 OPT_NODE_TYPE = "pubsub#node_type" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
75 OPT_SUBSCRIPTION_TYPE = "pubsub#subscription_type" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
76 OPT_SUBSCRIPTION_DEPTH = "pubsub#subscription_depth" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
77 OPT_ROSTER_GROUPS_ALLOWED = "pubsub#roster_groups_allowed" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
78 OPT_PUBLISH_MODEL = "pubsub#publish_model" |
3468
36cac8e6f57d
plugin XEP-0060: added constants for overwrite policy configuration option
Goffi <goffi@goffi.org>
parents:
3467
diff
changeset
|
79 OPT_OVERWRITE_POLICY = "pubsub#overwrite_policy" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
80 ACCESS_OPEN = "open" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
81 ACCESS_PRESENCE = "presence" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
82 ACCESS_ROSTER = "roster" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
83 ACCESS_PUBLISHER_ROSTER = "publisher-roster" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
84 ACCESS_AUTHORIZE = "authorize" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
85 ACCESS_WHITELIST = "whitelist" |
3451
f37e6e78db12
plugin XEP-0060: add constants for common values of publish model
Goffi <goffi@goffi.org>
parents:
3394
diff
changeset
|
86 PUBLISH_MODEL_PUBLISHERS = "publishers" |
f37e6e78db12
plugin XEP-0060: add constants for common values of publish model
Goffi <goffi@goffi.org>
parents:
3394
diff
changeset
|
87 PUBLISH_MODEL_SUBSCRIBERS = "subscribers" |
f37e6e78db12
plugin XEP-0060: add constants for common values of publish model
Goffi <goffi@goffi.org>
parents:
3394
diff
changeset
|
88 PUBLISH_MODEL_OPEN = "open" |
3468
36cac8e6f57d
plugin XEP-0060: added constants for overwrite policy configuration option
Goffi <goffi@goffi.org>
parents:
3467
diff
changeset
|
89 OWPOL_ORIGINAL = "original_publisher" |
36cac8e6f57d
plugin XEP-0060: added constants for overwrite policy configuration option
Goffi <goffi@goffi.org>
parents:
3467
diff
changeset
|
90 OWPOL_ANY_PUB = "any_publisher" |
2647
1bf7e89fded0
plugin XEP-0060: added singleton ID ("current")
Goffi <goffi@goffi.org>
parents:
2643
diff
changeset
|
91 ID_SINGLETON = "current" |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
92 EXTRA_PUBLISH_OPTIONS = "publish_options" |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
93 EXTRA_ON_PRECOND_NOT_MET = "on_precondition_not_met" |
3597
5d108ce026d7
plugin pubsub cache: Pubsub Caching implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
94 # extra disco needed for RSM, cf. XEP-0060 § 6.5.4 |
5d108ce026d7
plugin pubsub cache: Pubsub Caching implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
95 DISCO_RSM = "http://jabber.org/protocol/pubsub#rsm" |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 def __init__(self, host): |
3028 | 98 log.info(_("PubSub plugin initialization")) |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 self.host = host |
3028 | 100 self._rsm = host.plugins.get("XEP-0059") |
101 self._mam = host.plugins.get("XEP-0313") | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
102 self._node_cb = {} # dictionnary of callbacks for node (key: node, value: list of callbacks) |
1449
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
103 self.rt_sessions = sat_defer.RTDeferredSessions() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
104 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
105 "psNodeCreate", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
106 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
107 in_sign="ssa{ss}s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
108 out_sign="s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
109 method=self._createNode, |
3028 | 110 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
111 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
112 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
113 "psNodeConfigurationGet", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
114 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
115 in_sign="sss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
116 out_sign="a{ss}", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
117 method=self._getNodeConfiguration, |
3028 | 118 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
119 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
120 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
121 "psNodeConfigurationSet", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
122 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
123 in_sign="ssa{ss}s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
124 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
125 method=self._setNodeConfiguration, |
3028 | 126 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
127 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
128 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
129 "psNodeAffiliationsGet", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
130 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
131 in_sign="sss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
132 out_sign="a{ss}", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
133 method=self._getNodeAffiliations, |
3028 | 134 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
135 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
136 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
137 "psNodeAffiliationsSet", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
138 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
139 in_sign="ssa{ss}s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
140 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
141 method=self._setNodeAffiliations, |
3028 | 142 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
143 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
144 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
145 "psNodeSubscriptionsGet", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
146 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
147 in_sign="sss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
148 out_sign="a{ss}", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
149 method=self._getNodeSubscriptions, |
3028 | 150 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
151 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
152 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
153 "psNodeSubscriptionsSet", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
154 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
155 in_sign="ssa{ss}s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
156 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
157 method=self._setNodeSubscriptions, |
3028 | 158 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
159 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
160 host.bridge.addMethod( |
2801
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
161 "psNodePurge", |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
162 ".plugin", |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
163 in_sign="sss", |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
164 out_sign="", |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
165 method=self._purgeNode, |
3028 | 166 async_=True, |
2801
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
167 ) |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
168 host.bridge.addMethod( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
169 "psNodeDelete", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
170 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
171 in_sign="sss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
172 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
173 method=self._deleteNode, |
3028 | 174 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
175 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
176 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
177 "psNodeWatchAdd", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
178 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
179 in_sign="sss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
180 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
181 method=self._addWatch, |
3028 | 182 async_=False, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
183 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
184 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
185 "psNodeWatchRemove", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
186 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
187 in_sign="sss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
188 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
189 method=self._removeWatch, |
3028 | 190 async_=False, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
191 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
192 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
193 "psAffiliationsGet", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
194 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
195 in_sign="sss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
196 out_sign="a{ss}", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
197 method=self._getAffiliations, |
3028 | 198 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
199 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
200 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
201 "psItemsGet", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
202 ".plugin", |
3586
5f65f4e9f8cb
plugin XEP-0060: getItems extra is now serialised dict
Goffi <goffi@goffi.org>
parents:
3584
diff
changeset
|
203 in_sign="ssiassss", |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
204 out_sign="s", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
205 method=self._getItems, |
3028 | 206 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
207 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
208 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
209 "psItemSend", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
210 ".plugin", |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3069
diff
changeset
|
211 in_sign="ssssss", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
212 out_sign="s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
213 method=self._sendItem, |
3028 | 214 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
215 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
216 host.bridge.addMethod( |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
217 "psItemsSend", |
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
218 ".plugin", |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3069
diff
changeset
|
219 in_sign="ssasss", |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
220 out_sign="as", |
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
221 method=self._sendItems, |
3028 | 222 async_=True, |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
223 ) |
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
224 host.bridge.addMethod( |
3467
5901a7170528
plugin XEP-0060: renamed `psRetractItem(s)` to `psItem(s)Retract` for consistency.
Goffi <goffi@goffi.org>
parents:
3451
diff
changeset
|
225 "psItemRetract", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
226 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
227 in_sign="sssbs", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
228 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
229 method=self._retractItem, |
3028 | 230 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
231 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
232 host.bridge.addMethod( |
3467
5901a7170528
plugin XEP-0060: renamed `psRetractItem(s)` to `psItem(s)Retract` for consistency.
Goffi <goffi@goffi.org>
parents:
3451
diff
changeset
|
233 "psItemsRetract", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
234 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
235 in_sign="ssasbs", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
236 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
237 method=self._retractItems, |
3028 | 238 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
239 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
240 host.bridge.addMethod( |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
241 "psItemRename", |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
242 ".plugin", |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
243 in_sign="sssss", |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
244 out_sign="", |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
245 method=self._renameItem, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
246 async_=True, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
247 ) |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
248 host.bridge.addMethod( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
249 "psSubscribe", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
250 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
251 in_sign="ssa{ss}s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
252 out_sign="s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
253 method=self._subscribe, |
3028 | 254 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
255 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
256 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
257 "psUnsubscribe", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
258 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
259 in_sign="sss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
260 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
261 method=self._unsubscribe, |
3028 | 262 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
263 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
264 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
265 "psSubscriptionsGet", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
266 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
267 in_sign="sss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
268 out_sign="aa{ss}", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
269 method=self._subscriptions, |
3028 | 270 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
271 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
272 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
273 "psSubscribeToMany", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
274 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
275 in_sign="a(ss)sa{ss}s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
276 out_sign="s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
277 method=self._subscribeToMany, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
278 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
279 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
280 "psGetSubscribeRTResult", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
281 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
282 in_sign="ss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
283 out_sign="(ua(sss))", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
284 method=self._manySubscribeRTResult, |
3028 | 285 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
286 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
287 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
288 "psGetFromMany", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
289 ".plugin", |
3586
5f65f4e9f8cb
plugin XEP-0060: getItems extra is now serialised dict
Goffi <goffi@goffi.org>
parents:
3584
diff
changeset
|
290 in_sign="a(ss)iss", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
291 out_sign="s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
292 method=self._getFromMany, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
293 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
294 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
295 "psGetFromManyRTResult", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
296 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
297 in_sign="ss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
298 out_sign="(ua(sssasa{ss}))", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
299 method=self._getFromManyRTResult, |
3028 | 300 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
301 ) |
2444
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
302 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
303 # high level observer method |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
304 host.bridge.addSignal( |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2801
diff
changeset
|
305 "psEvent", ".plugin", signature="ssssss" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
306 ) # args: category, service(jid), node, type (C.PS_ITEMS, C.PS_DELETE), data, profile |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
307 |
2444
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
308 # low level observer method, used if service/node is in watching list (see psNodeWatch* methods) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
309 host.bridge.addSignal( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
310 "psEventRaw", ".plugin", signature="sssass" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
311 ) # args: service(jid), node, type (C.PS_ITEMS, C.PS_DELETE), list of item_xml, profile |
2444
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
312 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
313 def getHandler(self, client): |
1420
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
314 client.pubsub_client = SatPubSubClient(self.host, self) |
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
315 return client.pubsub_client |
1282
74d558e6c9fd
plugin XEP-0060: free SatPubSubClient instance on profile disconnection
souliane <souliane@mailoo.org>
parents:
1268
diff
changeset
|
316 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
317 @defer.inlineCallbacks |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
318 def profileConnected(self, client): |
2444
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
319 client.pubsub_watching = set() |
2459
a9c092bf4ee9
plugin XEP-0060: added an config option to set pubsub service
Goffi <goffi@goffi.org>
parents:
2444
diff
changeset
|
320 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
321 client.pubsub_service = jid.JID( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
322 self.host.memory.getConfig("", "pubsub_service") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
323 ) |
2459
a9c092bf4ee9
plugin XEP-0060: added an config option to set pubsub service
Goffi <goffi@goffi.org>
parents:
2444
diff
changeset
|
324 except RuntimeError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
325 log.info( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
326 _( |
3028 | 327 "Can't retrieve pubsub_service from conf, we'll use first one that we find" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
328 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
329 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
330 client.pubsub_service = yield self.host.findServiceEntity( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
331 client, "pubsub", "service" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
332 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
333 |
1483
0f0889028eea
plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents:
1459
diff
changeset
|
334 def getFeatures(self, profile): |
0f0889028eea
plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents:
1459
diff
changeset
|
335 try: |
0f0889028eea
plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents:
1459
diff
changeset
|
336 client = self.host.getClient(profile) |
0f0889028eea
plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents:
1459
diff
changeset
|
337 except exceptions.ProfileNotSetError: |
0f0889028eea
plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents:
1459
diff
changeset
|
338 return {} |
0f0889028eea
plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents:
1459
diff
changeset
|
339 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
340 return { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
341 "service": client.pubsub_service.full() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
342 if client.pubsub_service is not None |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
343 else "" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
344 } |
1483
0f0889028eea
plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents:
1459
diff
changeset
|
345 except AttributeError: |
0f0889028eea
plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents:
1459
diff
changeset
|
346 if self.host.isConnected(profile): |
0f0889028eea
plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents:
1459
diff
changeset
|
347 log.debug("Profile is not connected, service is not checked yet") |
0f0889028eea
plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents:
1459
diff
changeset
|
348 else: |
0f0889028eea
plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents:
1459
diff
changeset
|
349 log.error("Service should be available !") |
0f0889028eea
plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents:
1459
diff
changeset
|
350 return {} |
0f0889028eea
plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents:
1459
diff
changeset
|
351 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
352 def parseExtra(self, extra): |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
353 """Parse extra dictionnary |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
354 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
355 used bridge's extra dictionnaries |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
356 @param extra(dict): extra data used to configure request |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
357 @return(Extra): filled Extra instance |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
358 """ |
2484 | 359 if extra is None: |
360 rsm_request = None | |
361 extra = {} | |
362 else: | |
2760
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
363 # order-by |
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
364 if C.KEY_ORDER_BY in extra: |
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
365 # FIXME: we temporarily manage only one level of ordering |
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
366 # we need to switch to a fully serialised extra data |
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
367 # to be able to encode a whole ordered list |
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
368 extra[C.KEY_ORDER_BY] = [extra.pop(C.KEY_ORDER_BY)] |
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
369 |
1777 | 370 # rsm |
2702
6555e9835ff8
plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents:
2647
diff
changeset
|
371 if self._rsm is None: |
6555e9835ff8
plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents:
2647
diff
changeset
|
372 rsm_request = None |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
373 else: |
2702
6555e9835ff8
plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents:
2647
diff
changeset
|
374 rsm_request = self._rsm.parseExtra(extra) |
1777 | 375 |
376 # mam | |
2702
6555e9835ff8
plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents:
2647
diff
changeset
|
377 if self._mam is None: |
6555e9835ff8
plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents:
2647
diff
changeset
|
378 mam_request = None |
6555e9835ff8
plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents:
2647
diff
changeset
|
379 else: |
6555e9835ff8
plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents:
2647
diff
changeset
|
380 mam_request = self._mam.parseExtra(extra, with_rsm=False) |
1777 | 381 |
2702
6555e9835ff8
plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents:
2647
diff
changeset
|
382 if mam_request is not None: |
3028 | 383 assert "mam" not in extra |
384 extra["mam"] = mam_request | |
2760
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
385 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
386 return Extra(rsm_request, extra) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
387 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
388 def addManagedNode(self, node, **kwargs): |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
389 """Add a handler for a node |
1420
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
390 |
1760
30efe084471c
plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents:
1678
diff
changeset
|
391 @param node(unicode): node to monitor |
30efe084471c
plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents:
1678
diff
changeset
|
392 all node *prefixed* with this one will be triggered |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
393 @param **kwargs: method(s) to call when the node is found |
2305
972e33507609
plugin XEP-0060: addManagedNode callbacks now use client syntax instead of profile
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
394 the method must be named after PubSub constants in lower case |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
395 and suffixed with "_cb" |
2305
972e33507609
plugin XEP-0060: addManagedNode callbacks now use client syntax instead of profile
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
396 e.g.: "items_cb" for C.PS_ITEMS, "delete_cb" for C.PS_DELETE |
3597
5d108ce026d7
plugin pubsub cache: Pubsub Caching implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
397 note: only C.PS_ITEMS and C.PS_DELETE are implemented so far |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
398 """ |
1760
30efe084471c
plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents:
1678
diff
changeset
|
399 assert node is not None |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
400 assert kwargs |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
401 callbacks = self._node_cb.setdefault(node, {}) |
3028 | 402 for event, cb in kwargs.items(): |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
403 event_name = event[:-3] |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
404 assert event_name in C.PS_EVENTS |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
405 callbacks.setdefault(event_name, []).append(cb) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
406 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
407 def removeManagedNode(self, node, *args): |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
408 """Add a handler for a node |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
409 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
410 @param node(unicode): node to monitor |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
411 @param *args: callback(s) to remove |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
412 """ |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
413 assert args |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
414 try: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
415 registred_cb = self._node_cb[node] |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
416 except KeyError: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
417 pass |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
418 else: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
419 for callback in args: |
3028 | 420 for event, cb_list in registred_cb.items(): |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
421 try: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
422 cb_list.remove(callback) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
423 except ValueError: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
424 pass |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
425 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
426 log.debug( |
3028 | 427 "removed callback {cb} for event {event} on node {node}".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
428 cb=callback, event=event, node=node |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
429 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
430 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
431 if not cb_list: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
432 del registred_cb[event] |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
433 if not registred_cb: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
434 del self._node_cb[node] |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
435 return |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
436 log.error( |
3028 | 437 "Trying to remove inexistant callback {cb} for node {node}".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
438 cb=callback, node=node |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
439 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
440 ) |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
441 |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
442 # def listNodes(self, service, nodeIdentifier='', profile=C.PROF_KEY_NONE): |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
443 # """Retrieve the name of the nodes that are accessible on the target service. |
1242
f584fbda4773
plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents:
1219
diff
changeset
|
444 |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
445 # @param service (JID): target service |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
446 # @param nodeIdentifier (str): the parent node name (leave empty to retrieve first-level nodes) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
447 # @param profile (str): %(doc_profile)s |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
448 # @return: deferred which fire a list of nodes |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
449 # """ |
2148
a543eda2c923
core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
450 # client = self.host.getClient(profile) |
a543eda2c923
core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
451 # d = self.host.getDiscoItems(client, service, nodeIdentifier) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
452 # d.addCallback(lambda result: [item.getAttribute('node') for item in result.toElement().children if item.hasAttribute('node')]) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
453 # return d |
1242
f584fbda4773
plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents:
1219
diff
changeset
|
454 |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
455 # def listSubscribedNodes(self, service, nodeIdentifier='', filter_='subscribed', profile=C.PROF_KEY_NONE): |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
456 # """Retrieve the name of the nodes to which the profile is subscribed on the target service. |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
457 |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
458 # @param service (JID): target service |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
459 # @param nodeIdentifier (str): the parent node name (leave empty to retrieve all subscriptions) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
460 # @param filter_ (str): filter the result according to the given subscription type: |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
461 # - None: do not filter |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
462 # - 'pending': subscription has not been approved yet by the node owner |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
463 # - 'unconfigured': subscription options have not been configured yet |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
464 # - 'subscribed': subscription is complete |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
465 # @param profile (str): %(doc_profile)s |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
466 # @return: Deferred list[str] |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
467 # """ |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
468 # d = self.subscriptions(service, nodeIdentifier, profile_key=profile) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
469 # d.addCallback(lambda subs: [sub.getAttribute('node') for sub in subs if sub.getAttribute('subscription') == filter_]) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
470 # return d |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
471 |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3069
diff
changeset
|
472 def _sendItem(self, service, nodeIdentifier, payload, item_id=None, extra_ser="", |
2776
838f53730ce4
plugin pubsub admin: pubsub administrator first draft:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
473 profile_key=C.PROF_KEY_NONE): |
1420
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
474 client = self.host.getClient(profile_key) |
2272
b5befe7722d3
plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents:
2226
diff
changeset
|
475 service = None if not service else jid.JID(service) |
3394
23af257ae780
plugin XEP-0060: use `xml_tools.parse` instead of `wokkel.generic.parseXml`:
Goffi <goffi@goffi.org>
parents:
3312
diff
changeset
|
476 payload = xml_tools.parse(payload) |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3069
diff
changeset
|
477 extra = data_format.deserialise(extra_ser) |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
478 d = defer.ensureDeferred(self.sendItem( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
479 client, service, nodeIdentifier, payload, item_id or None, extra |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
480 )) |
3028 | 481 d.addCallback(lambda ret: ret or "") |
2272
b5befe7722d3
plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents:
2226
diff
changeset
|
482 return d |
b5befe7722d3
plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents:
2226
diff
changeset
|
483 |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3069
diff
changeset
|
484 def _sendItems(self, service, nodeIdentifier, items, extra_ser=None, |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
485 profile_key=C.PROF_KEY_NONE): |
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
486 client = self.host.getClient(profile_key) |
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
487 service = None if not service else jid.JID(service) |
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
488 try: |
3394
23af257ae780
plugin XEP-0060: use `xml_tools.parse` instead of `wokkel.generic.parseXml`:
Goffi <goffi@goffi.org>
parents:
3312
diff
changeset
|
489 items = [xml_tools.parse(item) for item in items] |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
490 except Exception as e: |
3028 | 491 raise exceptions.DataError(_("Can't parse items: {msg}").format( |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
492 msg=e)) |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3069
diff
changeset
|
493 extra = data_format.deserialise(extra_ser) |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
494 return defer.ensureDeferred(self.sendItems( |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
495 client, service, nodeIdentifier, items, extra |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
496 )) |
2272
b5befe7722d3
plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents:
2226
diff
changeset
|
497 |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
498 async def sendItem( |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
499 self, client, service, nodeIdentifier, payload, item_id=None, extra=None |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
500 ): |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
501 """High level method to send one item |
2272
b5befe7722d3
plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents:
2226
diff
changeset
|
502 |
b5befe7722d3
plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents:
2226
diff
changeset
|
503 @param service(jid.JID, None): service to send the item to |
b5befe7722d3
plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents:
2226
diff
changeset
|
504 None to use PEP |
b5befe7722d3
plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents:
2226
diff
changeset
|
505 @param NodeIdentifier(unicode): PubSub node to use |
3272
4c98f4972db5
plugin XEP-0060: fixed payload parsing in sendItem
Goffi <goffi@goffi.org>
parents:
3213
diff
changeset
|
506 @param payload(domish.Element): payload of the item to send |
2272
b5befe7722d3
plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents:
2226
diff
changeset
|
507 @param item_id(unicode, None): id to use or None to create one |
b5befe7722d3
plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents:
2226
diff
changeset
|
508 @param extra(dict, None): extra option, not used yet |
b5befe7722d3
plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents:
2226
diff
changeset
|
509 @return (unicode, None): id of the created item |
b5befe7722d3
plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents:
2226
diff
changeset
|
510 """ |
3272
4c98f4972db5
plugin XEP-0060: fixed payload parsing in sendItem
Goffi <goffi@goffi.org>
parents:
3213
diff
changeset
|
511 assert isinstance(payload, domish.Element) |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
512 item_elt = domish.Element((pubsub.NS_PUBSUB, 'item')) |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
513 if item_id is not None: |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
514 item_elt['id'] = item_id |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
515 item_elt.addChild(payload) |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
516 published_ids = await self.sendItems( |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
517 client, |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
518 service, |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
519 nodeIdentifier, |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
520 [item_elt], |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
521 extra |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
522 ) |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
523 try: |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
524 return published_ids[0] |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
525 except IndexError: |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
526 return item_id |
2272
b5befe7722d3
plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents:
2226
diff
changeset
|
527 |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
528 async def sendItems(self, client, service, nodeIdentifier, items, extra=None): |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
529 """High level method to send several items at once |
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
530 |
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
531 @param service(jid.JID, None): service to send the item to |
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
532 None to use PEP |
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
533 @param NodeIdentifier(unicode): PubSub node to use |
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
534 @param items(list[domish.Element]): whole item elements to send, |
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
535 "id" will be used if set |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3069
diff
changeset
|
536 @param extra(dict, None): extra options. Key can be: |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
537 - self.EXTRA_PUBLISH_OPTIONS(dict): publish options, cf. XEP-0060 § 7.1.5 |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
538 the dict maps option name to value(s) |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
539 - self.EXTRA_ON_PRECOND_NOT_MET(str): policy to have when publishing is |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
540 failing du to failing precondition. Value can be: |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
541 * raise (default): raise the exception |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
542 * publish_without_options: re-publish without the publish-options. |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
543 A warning will be logged showing that the publish-options could not |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
544 be used |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
545 @return (list[unicode]): ids of the created items |
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
546 """ |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3069
diff
changeset
|
547 if extra is None: |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3069
diff
changeset
|
548 extra = {} |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
549 parsed_items = [] |
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
550 for item in items: |
3028 | 551 if item.name != 'item': |
552 raise exceptions.DataError(_("Invalid item: {xml}").format(item.toXml())) | |
553 item_id = item.getAttribute("id") | |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
554 parsed_items.append(pubsub.Item(id=item_id, payload=item.firstChildElement())) |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
555 publish_options = extra.get(self.EXTRA_PUBLISH_OPTIONS) |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
556 try: |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
557 iq_result = await self.publish( |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
558 client, service, nodeIdentifier, parsed_items, options=publish_options) |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
559 except error.StanzaError as e: |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
560 if ((e.condition == 'conflict' and e.appCondition |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
561 and e.appCondition.name == 'precondition-not-met' |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
562 and publish_options is not None)): |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
563 # this usually happens when publish-options can't be set |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
564 policy = extra.get(self.EXTRA_ON_PRECOND_NOT_MET, 'raise') |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
565 if policy == 'raise': |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
566 raise e |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
567 elif policy == 'publish_without_options': |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
568 log.warning(_( |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
569 "Can't use publish-options ({options}) on node {node}, " |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
570 "re-publishing without them: {reason}").format( |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
571 options=', '.join(f'{k} = {v}' |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
572 for k,v in publish_options.items()), |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
573 node=nodeIdentifier, |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
574 reason=e, |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
575 ) |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
576 ) |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
577 iq_result = await self.publish( |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
578 client, service, nodeIdentifier, parsed_items) |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
579 else: |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
580 raise exceptions.InternalError( |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
581 f"Invalid policy in extra's {self.EXTRA_ON_PRECOND_NOT_MET!r}: " |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
582 f"{policy}" |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
583 ) |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
584 else: |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
585 raise e |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
586 try: |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
587 return [item['id'] |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
588 for item in iq_result.pubsub.publish.elements(pubsub.NS_PUBSUB, 'item')] |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
589 except AttributeError: |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
590 return [] |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
591 |
3589
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
592 async def publish( |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
593 self, |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
594 client: SatXMPPEntity, |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
595 service: jid.JID, |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
596 nodeIdentifier: str, |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
597 items: Optional[List[domish.Element]] = None, |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
598 options: Optional[dict] = None |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
599 ) -> List[str]: |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
600 published_ids = await client.pubsub_client.publish( |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3069
diff
changeset
|
601 service, nodeIdentifier, items, client.pubsub_client.parent.jid, |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3069
diff
changeset
|
602 options=options |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
603 ) |
286
3b382fa0ac28
plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents:
283
diff
changeset
|
604 |
3589
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
605 await self.host.trigger.asyncPoint( |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
606 "XEP-0060_publish", client, service, nodeIdentifier, items, options, |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
607 published_ids |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
608 ) |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
609 return published_ids |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
610 |
1777 | 611 def _unwrapMAMMessage(self, message_elt): |
612 try: | |
3062
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
613 item_elt = reduce( |
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
614 lambda elt, ns_name: next(elt.elements(*ns_name)), |
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
615 (message_elt, |
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
616 (mam.NS_MAM, "result"), |
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
617 (C.NS_FORWARD, "forwarded"), |
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
618 (C.NS_CLIENT, "message"), |
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
619 ("http://jabber.org/protocol/pubsub#event", "event"), |
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
620 ("http://jabber.org/protocol/pubsub#event", "items"), |
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
621 ("http://jabber.org/protocol/pubsub#event", "item"), |
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
622 )) |
1777 | 623 except StopIteration: |
3028 | 624 raise exceptions.DataError("Can't find Item in MAM message element") |
1777 | 625 return item_elt |
626 | |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
627 def serialiseItems(self, items_data): |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
628 items, metadata = items_data |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
629 metadata['items'] = items |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
630 return data_format.serialise(metadata) |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
631 |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
632 def _getItems(self, service="", node="", max_items=10, item_ids=None, sub_id=None, |
3586
5f65f4e9f8cb
plugin XEP-0060: getItems extra is now serialised dict
Goffi <goffi@goffi.org>
parents:
3584
diff
changeset
|
633 extra="", profile_key=C.PROF_KEY_NONE): |
2185
dd53d7a3219a
plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents:
2148
diff
changeset
|
634 """Get items from pubsub node |
dd53d7a3219a
plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents:
2148
diff
changeset
|
635 |
dd53d7a3219a
plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents:
2148
diff
changeset
|
636 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit |
dd53d7a3219a
plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents:
2148
diff
changeset
|
637 """ |
2360
72cbb6478f97
plugin XEP-0060: use client instead of profile_key in getItems
Goffi <goffi@goffi.org>
parents:
2352
diff
changeset
|
638 client = self.host.getClient(profile_key) |
2185
dd53d7a3219a
plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents:
2148
diff
changeset
|
639 service = jid.JID(service) if service else None |
dd53d7a3219a
plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents:
2148
diff
changeset
|
640 max_items = None if max_items == C.NO_LIMIT else max_items |
3586
5f65f4e9f8cb
plugin XEP-0060: getItems extra is now serialised dict
Goffi <goffi@goffi.org>
parents:
3584
diff
changeset
|
641 extra = self.parseExtra(data_format.deserialise(extra)) |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
642 d = defer.ensureDeferred(self.getItems( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
643 client, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
644 service, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
645 node or None, |
3591
d830c11eeef3
plugin XEP-0277: ignore `max_items` if `rsm_request` is set
Goffi <goffi@goffi.org>
parents:
3590
diff
changeset
|
646 max_items, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
647 item_ids, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
648 sub_id or None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
649 extra.rsm_request, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
650 extra.extra, |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
651 )) |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2801
diff
changeset
|
652 d.addCallback(self.transItemsData) |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
653 d.addCallback(self.serialiseItems) |
2185
dd53d7a3219a
plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents:
2148
diff
changeset
|
654 return d |
dd53d7a3219a
plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents:
2148
diff
changeset
|
655 |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
656 async def getItems( |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
657 self, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
658 client: SatXMPPEntity, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
659 service: Optional[jid.JID], |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
660 node: str, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
661 max_items: Optional[int] = None, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
662 item_ids: Optional[List[str]] = None, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
663 sub_id: Optional[str] = None, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
664 rsm_request: Optional[rsm.RSMRequest] = None, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
665 extra: Optional[dict] = None |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
666 ) -> Tuple[List[dict], dict]: |
1268
bb30bf3ae932
plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents:
1267
diff
changeset
|
667 """Retrieve pubsub items from a node. |
bb30bf3ae932
plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents:
1267
diff
changeset
|
668 |
1865
fc6eeacf31bc
plugin XEP-0277: service can be None in mbGet, resulting in a request on default pubsub service of profile (i.e. profile's PEP)
Goffi <goffi@goffi.org>
parents:
1854
diff
changeset
|
669 @param service (JID, None): pubsub service. |
1268
bb30bf3ae932
plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents:
1267
diff
changeset
|
670 @param node (str): node id. |
bb30bf3ae932
plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents:
1267
diff
changeset
|
671 @param max_items (int): optional limit on the number of retrieved items. |
2758
f4070693814a
plugin XEP-0060: fixed MAM return value on getItems():
Goffi <goffi@goffi.org>
parents:
2718
diff
changeset
|
672 @param item_ids (list[str]): identifiers of the items to be retrieved (can't be |
f4070693814a
plugin XEP-0060: fixed MAM return value on getItems():
Goffi <goffi@goffi.org>
parents:
2718
diff
changeset
|
673 used with rsm_request). |
1268
bb30bf3ae932
plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents:
1267
diff
changeset
|
674 @param sub_id (str): optional subscription identifier. |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
675 @param rsm_request (rsm.RSMRequest): RSM request data |
1268
bb30bf3ae932
plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents:
1267
diff
changeset
|
676 @return: a deferred couple (list[dict], dict) containing: |
bb30bf3ae932
plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents:
1267
diff
changeset
|
677 - list of items |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
678 - metadata with the following keys: |
2718
bb6adaa580ee
plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents:
2702
diff
changeset
|
679 - rsm_first, rsm_last, rsm_count, rsm_index: first, last, count and index |
bb6adaa580ee
plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents:
2702
diff
changeset
|
680 value of RSMResponse |
1903
29564cec913f
plugin XEP-0060: service, node and uri are added to metadata when doing a getItems
Goffi <goffi@goffi.org>
parents:
1865
diff
changeset
|
681 - service, node: service and node used |
1268
bb30bf3ae932
plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents:
1267
diff
changeset
|
682 """ |
2319
e715a29c4f9b
plugin XEP-0060: remove max_items when item_ids is set on getItems
Goffi <goffi@goffi.org>
parents:
2314
diff
changeset
|
683 if item_ids and max_items is not None: |
e715a29c4f9b
plugin XEP-0060: remove max_items when item_ids is set on getItems
Goffi <goffi@goffi.org>
parents:
2314
diff
changeset
|
684 max_items = None |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
685 if rsm_request and item_ids: |
3028 | 686 raise ValueError("items_id can't be used with rsm") |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
687 if extra is None: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
688 extra = {} |
3589
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
689 cont, ret = await self.host.trigger.asyncReturnPoint( |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
690 "XEP-0060_getItems", client, service, node, max_items, item_ids, sub_id, |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
691 rsm_request, extra |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
692 ) |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
693 if not cont: |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
694 return ret |
1777 | 695 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
696 mam_query = extra["mam"] |
1777 | 697 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
698 d = client.pubsub_client.items( |
2760
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
699 service = service, |
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
700 nodeIdentifier = node, |
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
701 maxItems = max_items, |
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
702 subscriptionIdentifier = sub_id, |
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
703 sender = None, |
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
704 itemIdentifiers = item_ids, |
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
705 orderBy = extra.get(C.KEY_ORDER_BY), |
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
706 rsm_request = rsm_request |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
707 ) |
2758
f4070693814a
plugin XEP-0060: fixed MAM return value on getItems():
Goffi <goffi@goffi.org>
parents:
2718
diff
changeset
|
708 # we have no MAM data here, so we add None |
2911
cd391ea847cb
tools (sat_defer), plugin XEP-0060: added a function "stanza2NotFound" to convert item-not-found StanzaError to exceptions.NotFound in an errback
Goffi <goffi@goffi.org>
parents:
2807
diff
changeset
|
709 d.addErrback(sat_defer.stanza2NotFound) |
2769
9282b289b964
plugin XEP-0060: set a 30s timeout on items get
Goffi <goffi@goffi.org>
parents:
2760
diff
changeset
|
710 d.addTimeout(TIMEOUT, reactor) |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
711 items, rsm_response = await d |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
712 mam_response = None |
1777 | 713 else: |
714 # if mam is requested, we have to do a totally different query | |
715 if self._mam is None: | |
3028 | 716 raise exceptions.NotFound("MAM (XEP-0313) plugin is not available") |
1777 | 717 if max_items is not None: |
3028 | 718 raise exceptions.DataError("max_items parameter can't be used with MAM") |
1777 | 719 if item_ids: |
3028 | 720 raise exceptions.DataError("items_ids parameter can't be used with MAM") |
1777 | 721 if mam_query.node is None: |
722 mam_query.node = node | |
723 elif mam_query.node != node: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
724 raise exceptions.DataError( |
3028 | 725 "MAM query node is incoherent with getItems's node" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
726 ) |
1777 | 727 if mam_query.rsm is None: |
728 mam_query.rsm = rsm_request | |
729 else: | |
730 if mam_query.rsm != rsm_request: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
731 raise exceptions.DataError( |
3028 | 732 "Conflict between RSM request and MAM's RSM request" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
733 ) |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
734 items, rsm_response, mam_response = await self._mam.getArchives( |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
735 client, mam_query, service, self._unwrapMAMMessage |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
736 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
737 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
738 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
739 subscribe = C.bool(extra["subscribe"]) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
740 except KeyError: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
741 subscribe = False |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
742 |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
743 if subscribe: |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
744 try: |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
745 await self.subscribe(client, service, node) |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
746 except error.StanzaError as e: |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
747 log.warning( |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
748 f"Could not subscribe to node {node} on service {service}: {e}" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
749 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
750 |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
751 # TODO: handle mam_response |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
752 service_jid = service if service else client.jid.userhostJID() |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
753 metadata = { |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
754 "service": service_jid, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
755 "node": node, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
756 "uri": self.getNodeURI(service_jid, node), |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
757 } |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
758 if mam_response is not None: |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
759 # mam_response is a dict with "complete" and "stable" keys |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
760 # we can put them directly in metadata |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
761 metadata.update(mam_response) |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
762 if rsm_request is not None and rsm_response is not None: |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
763 metadata['rsm'] = rsm_response.toDict() |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
764 if mam_response is None: |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
765 index = rsm_response.index |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
766 count = rsm_response.count |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
767 if index is None or count is None: |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
768 # we don't have enough information to know if the data is complete |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
769 # or not |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
770 metadata["complete"] = None |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
771 else: |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
772 # normally we have a strict equality here but XEP-0059 states |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
773 # that index MAY be approximative, so just in case… |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
774 metadata["complete"] = index + len(items) >= count |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3272
diff
changeset
|
775 |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
776 return (items, metadata) |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
777 |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
778 # @defer.inlineCallbacks |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
779 # def getItemsFromMany(self, service, data, max_items=None, sub_id=None, rsm=None, profile_key=C.PROF_KEY_NONE): |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
780 # """Massively retrieve pubsub items from many nodes. |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
781 # @param service (JID): target service. |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
782 # @param data (dict): dictionnary binding some arbitrary keys to the node identifiers. |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
783 # @param max_items (int): optional limit on the number of retrieved items *per node*. |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
784 # @param sub_id (str): optional subscription identifier. |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
785 # @param rsm (dict): RSM request data |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
786 # @param profile_key (str): %(doc_profile_key)s |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
787 # @return: a deferred dict with: |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
788 # - key: a value in (a subset of) data.keys() |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
789 # - couple (list[dict], dict) containing: |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
790 # - list of items |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
791 # - RSM response data |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
792 # """ |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
793 # client = self.host.getClient(profile_key) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
794 # found_nodes = yield self.listNodes(service, profile=client.profile) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
795 # d_dict = {} |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
796 # for publisher, node in data.items(): |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
797 # if node not in found_nodes: |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
798 # log.debug(u"Skip the items retrieval for [{node}]: node doesn't exist".format(node=node)) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
799 # continue # avoid pubsub "item-not-found" error |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
800 # d_dict[publisher] = self.getItems(service, node, max_items, None, sub_id, rsm, client.profile) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
801 # defer.returnValue(d_dict) |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
802 |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
803 def getOptions(self, service, nodeIdentifier, subscriber, subscriptionIdentifier=None, |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
804 profile_key=C.PROF_KEY_NONE): |
1420
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
805 client = self.host.getClient(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
806 return client.pubsub_client.getOptions( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
807 service, nodeIdentifier, subscriber, subscriptionIdentifier |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
808 ) |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
809 |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
810 def setOptions(self, service, nodeIdentifier, subscriber, options, |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
811 subscriptionIdentifier=None, profile_key=C.PROF_KEY_NONE): |
1420
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
812 client = self.host.getClient(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
813 return client.pubsub_client.setOptions( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
814 service, nodeIdentifier, subscriber, options, subscriptionIdentifier |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
815 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
816 |
2218
6a2fa651d7fa
plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents:
2206
diff
changeset
|
817 def _createNode(self, service_s, nodeIdentifier, options, profile_key): |
1420
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
818 client = self.host.getClient(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
819 return self.createNode( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
820 client, jid.JID(service_s) if service_s else None, nodeIdentifier, options |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
821 ) |
2218
6a2fa651d7fa
plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents:
2206
diff
changeset
|
822 |
6a2fa651d7fa
plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents:
2206
diff
changeset
|
823 def createNode(self, client, service, nodeIdentifier=None, options=None): |
6a2fa651d7fa
plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents:
2206
diff
changeset
|
824 """Create a new node |
6a2fa651d7fa
plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents:
2206
diff
changeset
|
825 |
6a2fa651d7fa
plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents:
2206
diff
changeset
|
826 @param service(jid.JID): PubSub service, |
6a2fa651d7fa
plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents:
2206
diff
changeset
|
827 @param NodeIdentifier(unicode, None): node name |
6a2fa651d7fa
plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents:
2206
diff
changeset
|
828 use None to create instant node (identifier will be returned by this method) |
6a2fa651d7fa
plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents:
2206
diff
changeset
|
829 @param option(dict[unicode, unicode], None): node configuration options |
6a2fa651d7fa
plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents:
2206
diff
changeset
|
830 @return (unicode): identifier of the created node (may be different from requested name) |
6a2fa651d7fa
plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents:
2206
diff
changeset
|
831 """ |
2393
8ed4ac10cb5e
plugin tickets import: create comments nodes with open access/publishing
Goffi <goffi@goffi.org>
parents:
2389
diff
changeset
|
832 # TODO: if pubsub service doesn't hande publish-options, configure it in a second time |
1420
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
833 return client.pubsub_client.createNode(service, nodeIdentifier, options) |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
834 |
2389
5675af905725
plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents:
2360
diff
changeset
|
835 @defer.inlineCallbacks |
5675af905725
plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents:
2360
diff
changeset
|
836 def createIfNewNode(self, client, service, nodeIdentifier, options=None): |
5675af905725
plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents:
2360
diff
changeset
|
837 """Helper method similar to createNode, but will not fail in case of conflict""" |
5675af905725
plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents:
2360
diff
changeset
|
838 try: |
5675af905725
plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents:
2360
diff
changeset
|
839 yield self.createNode(client, service, nodeIdentifier, options) |
5675af905725
plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents:
2360
diff
changeset
|
840 except error.StanzaError as e: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
841 if e.condition == "conflict": |
2389
5675af905725
plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents:
2360
diff
changeset
|
842 pass |
5675af905725
plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents:
2360
diff
changeset
|
843 else: |
5675af905725
plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents:
2360
diff
changeset
|
844 raise e |
5675af905725
plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents:
2360
diff
changeset
|
845 |
2196
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
846 def _getNodeConfiguration(self, service_s, nodeIdentifier, profile_key): |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
847 client = self.host.getClient(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
848 d = self.getConfiguration( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
849 client, jid.JID(service_s) if service_s else None, nodeIdentifier |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
850 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
851 |
2196
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
852 def serialize(form): |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
853 # FIXME: better more generic dataform serialisation should be available in SàT |
3028 | 854 return {f.var: str(f.value) for f in list(form.fields.values())} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
855 |
2196
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
856 d.addCallback(serialize) |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
857 return d |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
858 |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
859 def getConfiguration(self, client, service, nodeIdentifier): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
860 request = pubsub.PubSubRequest("configureGet") |
2196
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
861 request.recipient = service |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
862 request.nodeIdentifier = nodeIdentifier |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
863 |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
864 def cb(iq): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
865 form = data_form.findForm(iq.pubsub.configure, pubsub.NS_PUBSUB_NODE_CONFIG) |
2196
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
866 form.typeCheck() |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
867 return form |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
868 |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
869 d = request.send(client.xmlstream) |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
870 d.addCallback(cb) |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
871 return d |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
872 |
2198
44f12990e275
plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents:
2196
diff
changeset
|
873 def _setNodeConfiguration(self, service_s, nodeIdentifier, options, profile_key): |
44f12990e275
plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents:
2196
diff
changeset
|
874 client = self.host.getClient(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
875 d = self.setConfiguration( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
876 client, jid.JID(service_s) if service_s else None, nodeIdentifier, options |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
877 ) |
2198
44f12990e275
plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents:
2196
diff
changeset
|
878 return d |
44f12990e275
plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents:
2196
diff
changeset
|
879 |
44f12990e275
plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents:
2196
diff
changeset
|
880 def setConfiguration(self, client, service, nodeIdentifier, options): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
881 request = pubsub.PubSubRequest("configureSet") |
2198
44f12990e275
plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents:
2196
diff
changeset
|
882 request.recipient = service |
44f12990e275
plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents:
2196
diff
changeset
|
883 request.nodeIdentifier = nodeIdentifier |
44f12990e275
plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents:
2196
diff
changeset
|
884 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
885 form = data_form.Form( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
886 formType="submit", formNamespace=pubsub.NS_PUBSUB_NODE_CONFIG |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
887 ) |
2198
44f12990e275
plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents:
2196
diff
changeset
|
888 form.makeFields(options) |
44f12990e275
plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents:
2196
diff
changeset
|
889 request.options = form |
44f12990e275
plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents:
2196
diff
changeset
|
890 |
44f12990e275
plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents:
2196
diff
changeset
|
891 d = request.send(client.xmlstream) |
44f12990e275
plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents:
2196
diff
changeset
|
892 return d |
44f12990e275
plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents:
2196
diff
changeset
|
893 |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
894 def _getAffiliations(self, service_s, nodeIdentifier, profile_key): |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
895 client = self.host.getClient(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
896 d = self.getAffiliations( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
897 client, jid.JID(service_s) if service_s else None, nodeIdentifier or None |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
898 ) |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
899 return d |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
900 |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
901 def getAffiliations(self, client, service, nodeIdentifier=None): |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
902 """Retrieve affiliations of an entity |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
903 |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
904 @param nodeIdentifier(unicode, None): node to get affiliation from |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
905 None to get all nodes affiliations for this service |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
906 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
907 request = pubsub.PubSubRequest("affiliations") |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
908 request.recipient = service |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
909 request.nodeIdentifier = nodeIdentifier |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
910 |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
911 def cb(iq_elt): |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
912 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
913 affiliations_elt = next( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
914 iq_elt.pubsub.elements((pubsub.NS_PUBSUB, "affiliations")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
915 ) |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
916 except StopIteration: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
917 raise ValueError( |
3028 | 918 _("Invalid result: missing <affiliations> element: {}").format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
919 iq_elt.toXml |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
920 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
921 ) |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
922 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
923 return { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
924 e["node"]: e["affiliation"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
925 for e in affiliations_elt.elements((pubsub.NS_PUBSUB, "affiliation")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
926 } |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
927 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
928 raise ValueError( |
3028 | 929 _("Invalid result: bad <affiliation> element: {}").format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
930 iq_elt.toXml |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
931 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
932 ) |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
933 |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
934 d = request.send(client.xmlstream) |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
935 d.addCallback(cb) |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
936 return d |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
937 |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
938 def _getNodeAffiliations(self, service_s, nodeIdentifier, profile_key): |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
939 client = self.host.getClient(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
940 d = self.getNodeAffiliations( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
941 client, jid.JID(service_s) if service_s else None, nodeIdentifier |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
942 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
943 d.addCallback( |
3028 | 944 lambda affiliations: {j.full(): a for j, a in affiliations.items()} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
945 ) |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
946 return d |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
947 |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
948 def getNodeAffiliations(self, client, service, nodeIdentifier): |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
949 """Retrieve affiliations of a node owned by profile""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
950 request = pubsub.PubSubRequest("affiliationsGet") |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
951 request.recipient = service |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
952 request.nodeIdentifier = nodeIdentifier |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
953 |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
954 def cb(iq_elt): |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
955 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
956 affiliations_elt = next( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
957 iq_elt.pubsub.elements((pubsub.NS_PUBSUB_OWNER, "affiliations")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
958 ) |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
959 except StopIteration: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
960 raise ValueError( |
3028 | 961 _("Invalid result: missing <affiliations> element: {}").format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
962 iq_elt.toXml |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
963 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
964 ) |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
965 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
966 return { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
967 jid.JID(e["jid"]): e["affiliation"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
968 for e in affiliations_elt.elements( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
969 (pubsub.NS_PUBSUB_OWNER, "affiliation") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
970 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
971 } |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
972 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
973 raise ValueError( |
3028 | 974 _("Invalid result: bad <affiliation> element: {}").format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
975 iq_elt.toXml |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
976 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
977 ) |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
978 |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
979 d = request.send(client.xmlstream) |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
980 d.addCallback(cb) |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
981 return d |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
982 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
983 def _setNodeAffiliations( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
984 self, service_s, nodeIdentifier, affiliations, profile_key=C.PROF_KEY_NONE |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
985 ): |
2206
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
986 client = self.host.getClient(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
987 affiliations = { |
3028 | 988 jid.JID(jid_): affiliation for jid_, affiliation in affiliations.items() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
989 } |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
990 d = self.setNodeAffiliations( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
991 client, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
992 jid.JID(service_s) if service_s else None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
993 nodeIdentifier, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
994 affiliations, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
995 ) |
2206
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
996 return d |
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
997 |
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
998 def setNodeAffiliations(self, client, service, nodeIdentifier, affiliations): |
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
999 """Update affiliations of a node owned by profile |
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
1000 |
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
1001 @param affiliations(dict[jid.JID, unicode]): affiliations to set |
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
1002 check https://xmpp.org/extensions/xep-0060.html#affiliations for a list of possible affiliations |
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
1003 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1004 request = pubsub.PubSubRequest("affiliationsSet") |
2206
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
1005 request.recipient = service |
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
1006 request.nodeIdentifier = nodeIdentifier |
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
1007 request.affiliations = affiliations |
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
1008 d = request.send(client.xmlstream) |
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
1009 return d |
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
1010 |
2801
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1011 def _purgeNode(self, service_s, nodeIdentifier, profile_key): |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1012 client = self.host.getClient(profile_key) |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1013 return self.purgeNode( |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1014 client, jid.JID(service_s) if service_s else None, nodeIdentifier |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1015 ) |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1016 |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1017 def purgeNode(self, client, service, nodeIdentifier): |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1018 return client.pubsub_client.purgeNode(service, nodeIdentifier) |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1019 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
1020 def _deleteNode(self, service_s, nodeIdentifier, profile_key): |
2218
6a2fa651d7fa
plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents:
2206
diff
changeset
|
1021 client = self.host.getClient(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1022 return self.deleteNode( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1023 client, jid.JID(service_s) if service_s else None, nodeIdentifier |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1024 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
1025 |
2218
6a2fa651d7fa
plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents:
2206
diff
changeset
|
1026 def deleteNode(self, client, service, nodeIdentifier): |
1420
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
1027 return client.pubsub_client.deleteNode(service, nodeIdentifier) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1028 |
2444
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1029 def _addWatch(self, service_s, node, profile_key): |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1030 """watch modifications on a node |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1031 |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1032 This method should only be called from bridge |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1033 """ |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1034 client = self.host.getClient(profile_key) |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1035 service = jid.JID(service_s) if service_s else client.jid.userhostJID() |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1036 client.pubsub_watching.add((service, node)) |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1037 |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1038 def _removeWatch(self, service_s, node, profile_key): |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1039 """remove a node watch |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1040 |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1041 This method should only be called from bridge |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1042 """ |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1043 client = self.host.getClient(profile_key) |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1044 service = jid.JID(service_s) if service_s else client.jid.userhostJID() |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1045 client.pubsub_watching.remove((service, node)) |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1046 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1047 def _retractItem( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1048 self, service_s, nodeIdentifier, itemIdentifier, notify, profile_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1049 ): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1050 return self._retractItems( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1051 service_s, nodeIdentifier, (itemIdentifier,), notify, profile_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1052 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
1053 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1054 def _retractItems( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1055 self, service_s, nodeIdentifier, itemIdentifiers, notify, profile_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1056 ): |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1057 client = self.host.getClient(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1058 return self.retractItems( |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1059 client, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1060 jid.JID(service_s) if service_s else None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1061 nodeIdentifier, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1062 itemIdentifiers, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1063 notify, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1064 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
1065 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1066 def retractItems( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1067 self, |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1068 client, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1069 service, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1070 nodeIdentifier, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1071 itemIdentifiers, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1072 notify=True, |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1073 ): |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1074 return client.pubsub_client.retractItems( |
3590
1269c2d788be
plugin XEP-0060: fix notification handling in `retractItems`
Goffi <goffi@goffi.org>
parents:
3589
diff
changeset
|
1075 service, nodeIdentifier, itemIdentifiers, notify=notify |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1076 ) |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1077 |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1078 def _renameItem( |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1079 self, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1080 service, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1081 node, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1082 item_id, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1083 new_id, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1084 profile_key=C.PROF_KEY_NONE, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1085 ): |
1420
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
1086 client = self.host.getClient(profile_key) |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1087 service = jid.JID(service) if service else None |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1088 return defer.ensureDeferred(self.renameItem( |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1089 client, service, node, item_id, new_id |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1090 )) |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1091 |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1092 async def renameItem( |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1093 self, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1094 client: SatXMPPEntity, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1095 service: Optional[jid.JID], |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1096 node: str, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1097 item_id: str, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1098 new_id: str |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1099 ) -> None: |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1100 """Rename an item by recreating it then deleting it |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1101 |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1102 we have to recreate then delete because there is currently no rename operation |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1103 with PubSub |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1104 """ |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1105 if not item_id or not new_id: |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1106 raise ValueError("item_id and new_id must not be empty") |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1107 # retract must be done last, so if something goes wrong, the exception will stop |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1108 # the workflow and no accidental delete should happen |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1109 item_elt = (await self.getItems(client, service, node, item_ids=[item_id]))[0][0] |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1110 await self.sendItem(client, service, node, item_elt.firstChildElement(), new_id) |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1111 await self.retractItems(client, service, node, [item_id]) |
745
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
704
diff
changeset
|
1112 |
2442
b8ffb7f8056b
plugin XEP-0060: added "options" argument to psSubscribe, and return subscription id if present
Goffi <goffi@goffi.org>
parents:
2432
diff
changeset
|
1113 def _subscribe(self, service, nodeIdentifier, options, profile_key=C.PROF_KEY_NONE): |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1114 client = self.host.getClient(profile_key) |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1115 service = None if not service else jid.JID(service) |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1116 d = defer.ensureDeferred( |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1117 self.subscribe(client, service, nodeIdentifier, options=options or None) |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1118 ) |
3028 | 1119 d.addCallback(lambda subscription: subscription.subscriptionIdentifier or "") |
2442
b8ffb7f8056b
plugin XEP-0060: added "options" argument to psSubscribe, and return subscription id if present
Goffi <goffi@goffi.org>
parents:
2432
diff
changeset
|
1120 return d |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1121 |
3589
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1122 async def subscribe( |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1123 self, |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1124 client: SatXMPPEntity, |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1125 service: jid.JID, |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1126 nodeIdentifier: str, |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1127 sub_jid: Optional[jid.JID] = None, |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1128 options: Optional[dict] = None |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1129 ) -> pubsub.Subscription: |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
1130 # TODO: reimplement a subscribtion cache, checking that we have not subscription before trying to subscribe |
3589
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1131 subscription = await client.pubsub_client.subscribe( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1132 service, nodeIdentifier, sub_jid or client.jid.userhostJID(), options=options |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1133 ) |
3589
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1134 await self.host.trigger.asyncPoint( |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1135 "XEP-0060_subscribe", client, service, nodeIdentifier, sub_jid, options, |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1136 subscription |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1137 ) |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1138 return subscription |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1139 |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1140 def _unsubscribe(self, service, nodeIdentifier, profile_key=C.PROF_KEY_NONE): |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1141 client = self.host.getClient(profile_key) |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1142 service = None if not service else jid.JID(service) |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1143 return defer.ensureDeferred(self.unsubscribe(client, service, nodeIdentifier)) |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1144 |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1145 async def unsubscribe( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1146 self, |
3589
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1147 client: SatXMPPEntity, |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1148 service: jid.JID, |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1149 nodeIdentifier: str, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1150 sub_jid=None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1151 subscriptionIdentifier=None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1152 sender=None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1153 ): |
3589
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1154 await client.pubsub_client.unsubscribe( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1155 service, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1156 nodeIdentifier, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1157 sub_jid or client.jid.userhostJID(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1158 subscriptionIdentifier, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1159 sender, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1160 ) |
3589
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1161 await self.host.trigger.asyncPoint( |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1162 "XEP-0060_unsubscribe", client, service, nodeIdentifier, sub_jid, |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1163 subscriptionIdentifier, sender |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1164 ) |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1165 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1166 def _subscriptions(self, service, nodeIdentifier="", profile_key=C.PROF_KEY_NONE): |
1420
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
1167 client = self.host.getClient(profile_key) |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1168 service = None if not service else jid.JID(service) |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1169 |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1170 def gotSubscriptions(subscriptions): |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1171 # we replace pubsub.Subscription instance by dict that we can serialize |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1172 for idx, sub in enumerate(subscriptions): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1173 sub_dict = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1174 "node": sub.nodeIdentifier, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1175 "subscriber": sub.subscriber.full(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1176 "state": sub.state, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1177 } |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1178 if sub.subscriptionIdentifier is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1179 sub_dict["id"] = sub.subscriptionIdentifier |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1180 subscriptions[idx] = sub_dict |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
1181 |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1182 return subscriptions |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1183 |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1184 d = self.subscriptions(client, service, nodeIdentifier or None) |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1185 d.addCallback(gotSubscriptions) |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1186 return d |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1187 |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1188 def subscriptions(self, client, service, nodeIdentifier=None): |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1189 """retrieve subscriptions from a service |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1190 |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1191 @param service(jid.JID): PubSub service |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1192 @param nodeIdentifier(unicode, None): node to check |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1193 None to get all subscriptions |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1194 """ |
1420
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
1195 return client.pubsub_client.subscriptions(service, nodeIdentifier) |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
1196 |
1829
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
1197 ## misc tools ## |
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
1198 |
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
1199 def getNodeURI(self, service, node, item=None): |
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
1200 """Return XMPP URI of a PubSub node |
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
1201 |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1202 @param service(jid.JID): PubSub service |
1829
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
1203 @param node(unicode): node |
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
1204 @return (unicode): URI of the node |
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
1205 """ |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3272
diff
changeset
|
1206 # FIXME: deprecated, use sat.tools.common.uri instead |
1904
614f3abb2c69
plugin XEP-0060: fixed traceback if service was None
Goffi <goffi@goffi.org>
parents:
1903
diff
changeset
|
1207 assert service is not None |
1854
3c0bb714a80b
plugin XEP-0060: fixed bad xmpp: URI generation in getNodeURI
Goffi <goffi@goffi.org>
parents:
1829
diff
changeset
|
1208 # XXX: urllib.urlencode use "&" to separate value, while XMPP URL (cf. RFC 5122) |
3c0bb714a80b
plugin XEP-0060: fixed bad xmpp: URI generation in getNodeURI
Goffi <goffi@goffi.org>
parents:
1829
diff
changeset
|
1209 # use ";" as a separator. So if more than one value is used in query_data, |
3c0bb714a80b
plugin XEP-0060: fixed bad xmpp: URI generation in getNodeURI
Goffi <goffi@goffi.org>
parents:
1829
diff
changeset
|
1210 # urlencode MUST NOT BE USED. |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1211 query_data = [("node", node.encode("utf-8"))] |
1829
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
1212 if item is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1213 query_data.append(("item", item.encode("utf-8"))) |
1854
3c0bb714a80b
plugin XEP-0060: fixed bad xmpp: URI generation in getNodeURI
Goffi <goffi@goffi.org>
parents:
1829
diff
changeset
|
1214 return "xmpp:{service}?;{query}".format( |
3028 | 1215 service=service.userhost(), query=urllib.parse.urlencode(query_data) |
1216 ) | |
1829
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
1217 |
1449
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1218 ## methods to manage several stanzas/jids at once ## |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1219 |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1220 # generic # |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1221 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1222 def getRTResults( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1223 self, session_id, on_success=None, on_error=None, profile=C.PROF_KEY_NONE |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1224 ): |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1225 return self.rt_sessions.getResults(session_id, on_success, on_error, profile) |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1226 |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3272
diff
changeset
|
1227 def transItemsData(self, items_data, item_cb=lambda item: item.toXml()): |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2801
diff
changeset
|
1228 """Helper method to transform result from [getItems] |
1451
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1229 |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1230 the items_data must be a tuple(list[domish.Element], dict[unicode, unicode]) |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3272
diff
changeset
|
1231 as returned by [getItems]. |
1451
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1232 @param items_data(tuple): tuple returned by [getItems] |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1233 @param item_cb(callable): method to transform each item |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1234 @return (tuple): a serialised form ready to go throught bridge |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1235 """ |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1236 items, metadata = items_data |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3272
diff
changeset
|
1237 items = [item_cb(item) for item in items] |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2801
diff
changeset
|
1238 |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3272
diff
changeset
|
1239 return (items, metadata) |
1451
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1240 |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3272
diff
changeset
|
1241 def transItemsDataD(self, items_data, item_cb): |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2801
diff
changeset
|
1242 """Helper method to transform result from [getItems], deferred version |
1451
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1243 |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1244 the items_data must be a tuple(list[domish.Element], dict[unicode, unicode]) |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1245 as returned by [getItems]. metadata values are then casted to unicode and |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3272
diff
changeset
|
1246 each item is passed to items_cb. |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2801
diff
changeset
|
1247 An errback is added to item_cb, and when it is fired the value is filtered from |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2801
diff
changeset
|
1248 final items |
1451
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1249 @param items_data(tuple): tuple returned by [getItems] |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1250 @param item_cb(callable): method to transform each item (must return a deferred) |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3272
diff
changeset
|
1251 @return (tuple): a deferred which fire a dict which can be serialised to go |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3272
diff
changeset
|
1252 throught bridge |
1451
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1253 """ |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1254 items, metadata = items_data |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1255 |
3069
73db9db8b9e1
plugin XEP-0277: fixed comments URLs parsing
Goffi <goffi@goffi.org>
parents:
3062
diff
changeset
|
1256 def eb(failure_): |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3272
diff
changeset
|
1257 log.warning(f"Error while parsing item: {failure_.value}") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1258 |
1451
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1259 d = defer.gatherResults([item_cb(item).addErrback(eb) for item in items]) |
3492
fa796612adad
plugin XEP-0277: better resilience to broken items:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1260 d.addCallback(lambda parsed_items: ( |
fa796612adad
plugin XEP-0277: better resilience to broken items:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1261 [i for i in parsed_items if i is not None], |
fa796612adad
plugin XEP-0277: better resilience to broken items:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1262 metadata |
fa796612adad
plugin XEP-0277: better resilience to broken items:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1263 )) |
1451
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1264 return d |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1265 |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1266 def serDList(self, results, failure_result=None): |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1267 """Serialise a DeferredList result |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1268 |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1269 @param results: DeferredList results |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1270 @param failure_result: value to use as value for failed Deferred |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1271 (default: empty tuple) |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1272 @return (list): list with: |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1273 - failure: empty in case of success, else error message |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1274 - result |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1275 """ |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1276 if failure_result is None: |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1277 failure_result = () |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1278 return [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1279 ("", result) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1280 if success |
3028 | 1281 else (str(result.result) or UNSPECIFIED, failure_result) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1282 for success, result in results |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1283 ] |
1451
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1284 |
1449
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1285 # subscribe # |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1286 |
2338
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1287 def _getNodeSubscriptions(self, service_s, nodeIdentifier, profile_key): |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1288 client = self.host.getClient(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1289 d = self.getNodeSubscriptions( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1290 client, jid.JID(service_s) if service_s else None, nodeIdentifier |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1291 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1292 d.addCallback( |
3028 | 1293 lambda subscriptions: {j.full(): a for j, a in subscriptions.items()} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1294 ) |
2338
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1295 return d |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1296 |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1297 def getNodeSubscriptions(self, client, service, nodeIdentifier): |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1298 """Retrieve subscriptions to a node |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1299 |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1300 @param nodeIdentifier(unicode): node to get subscriptions from |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1301 """ |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1302 if not nodeIdentifier: |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1303 raise exceptions.DataError("node identifier can't be empty") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1304 request = pubsub.PubSubRequest("subscriptionsGet") |
2338
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1305 request.recipient = service |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1306 request.nodeIdentifier = nodeIdentifier |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1307 |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1308 def cb(iq_elt): |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1309 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1310 subscriptions_elt = next( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1311 iq_elt.pubsub.elements((pubsub.NS_PUBSUB, "subscriptions")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1312 ) |
2338
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1313 except StopIteration: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1314 raise ValueError( |
3028 | 1315 _("Invalid result: missing <subscriptions> element: {}").format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1316 iq_elt.toXml |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1317 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1318 ) |
2338
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1319 except AttributeError as e: |
3028 | 1320 raise ValueError(_("Invalid result: {}").format(e)) |
2338
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1321 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1322 return { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1323 jid.JID(s["jid"]): s["subscription"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1324 for s in subscriptions_elt.elements( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1325 (pubsub.NS_PUBSUB, "subscription") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1326 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1327 } |
2338
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1328 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1329 raise ValueError( |
3028 | 1330 _("Invalid result: bad <subscription> element: {}").format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1331 iq_elt.toXml |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1332 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1333 ) |
2338
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1334 |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1335 d = request.send(client.xmlstream) |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1336 d.addCallback(cb) |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1337 return d |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1338 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1339 def _setNodeSubscriptions( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1340 self, service_s, nodeIdentifier, subscriptions, profile_key=C.PROF_KEY_NONE |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1341 ): |
2338
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1342 client = self.host.getClient(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1343 subscriptions = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1344 jid.JID(jid_): subscription |
3028 | 1345 for jid_, subscription in subscriptions.items() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1346 } |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1347 d = self.setNodeSubscriptions( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1348 client, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1349 jid.JID(service_s) if service_s else None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1350 nodeIdentifier, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1351 subscriptions, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1352 ) |
2338
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1353 return d |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1354 |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1355 def setNodeSubscriptions(self, client, service, nodeIdentifier, subscriptions): |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1356 """Set or update subscriptions of a node owned by profile |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1357 |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1358 @param subscriptions(dict[jid.JID, unicode]): subscriptions to set |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1359 check https://xmpp.org/extensions/xep-0060.html#substates for a list of possible subscriptions |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1360 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1361 request = pubsub.PubSubRequest("subscriptionsSet") |
2338
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1362 request.recipient = service |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1363 request.nodeIdentifier = nodeIdentifier |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1364 request.subscriptions = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1365 pubsub.Subscription(nodeIdentifier, jid_, state) |
3028 | 1366 for jid_, state in subscriptions.items() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1367 } |
2338
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1368 d = request.send(client.xmlstream) |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1369 return d |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1370 |
1449
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1371 def _manySubscribeRTResult(self, session_id, profile_key=C.PROF_KEY_DEFAULT): |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1372 """Get real-time results for subcribeToManu session |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1373 |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1374 @param session_id: id of the real-time deferred session |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1375 @param return (tuple): (remaining, results) where: |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1376 - remaining is the number of still expected results |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1377 - results is a list of tuple(unicode, unicode, bool, unicode) with: |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1378 - service: pubsub service |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1379 - and node: pubsub node |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1380 - failure(unicode): empty string in case of success, error message else |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1381 @param profile_key: %(doc_profile_key)s |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1382 """ |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1383 profile = self.host.getClient(profile_key).profile |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1384 d = self.rt_sessions.getResults( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1385 session_id, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1386 on_success=lambda result: "", |
3028 | 1387 on_error=lambda failure: str(failure.value), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1388 profile=profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1389 ) |
1449
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1390 # we need to convert jid.JID to unicode with full() to serialise it for the bridge |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1391 d.addCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1392 lambda ret: ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1393 ret[0], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1394 [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1395 (service.full(), node, "" if success else failure or UNSPECIFIED) |
3028 | 1396 for (service, node), (success, failure) in ret[1].items() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1397 ], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1398 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1399 ) |
1449
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1400 return d |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1401 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1402 def _subscribeToMany( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1403 self, node_data, subscriber=None, options=None, profile_key=C.PROF_KEY_NONE |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1404 ): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1405 return self.subscribeToMany( |
3028 | 1406 [(jid.JID(service), str(node)) for service, node in node_data], |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1407 jid.JID(subscriber), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1408 options, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1409 profile_key, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1410 ) |
1449
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1411 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1412 def subscribeToMany( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1413 self, node_data, subscriber, options=None, profile_key=C.PROF_KEY_NONE |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1414 ): |
1449
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1415 """Subscribe to several nodes at once. |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1416 |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1417 @param node_data (iterable[tuple]): iterable of tuple (service, node) where: |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1418 - service (jid.JID) is the pubsub service |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1419 - node (unicode) is the node to subscribe to |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1420 @param subscriber (jid.JID): optional subscription identifier. |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1421 @param options (dict): subscription options |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1422 @param profile_key (str): %(doc_profile_key)s |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1423 @return (str): RT Deferred session id |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1424 """ |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1425 client = self.host.getClient(profile_key) |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1426 deferreds = {} |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1427 for service, node in node_data: |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1428 deferreds[(service, node)] = defer.ensureDeferred( |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1429 client.pubsub_client.subscribe( |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1430 service, node, subscriber, options=options |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1431 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1432 ) |
1449
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1433 return self.rt_sessions.newSession(deferreds, client.profile) |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1434 # found_nodes = yield self.listNodes(service, profile=client.profile) |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1435 # subscribed_nodes = yield self.listSubscribedNodes(service, profile=client.profile) |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1436 # d_list = [] |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1437 # for nodeIdentifier in (set(nodeIdentifiers) - set(subscribed_nodes)): |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1438 # if nodeIdentifier not in found_nodes: |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1439 # log.debug(u"Skip the subscription to [{node}]: node doesn't exist".format(node=nodeIdentifier)) |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1440 # continue # avoid sat-pubsub "SubscriptionExists" error |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1441 # d_list.append(client.pubsub_client.subscribe(service, nodeIdentifier, sub_jid or client.pubsub_client.parent.jid.userhostJID(), options=options)) |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1442 # defer.returnValue(d_list) |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1443 |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1444 # get # |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1445 |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1446 def _getFromManyRTResult(self, session_id, profile_key=C.PROF_KEY_DEFAULT): |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1447 """Get real-time results for getFromMany session |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1448 |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1449 @param session_id: id of the real-time deferred session |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1450 @param profile_key: %(doc_profile_key)s |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1451 @param return (tuple): (remaining, results) where: |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1452 - remaining is the number of still expected results |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1453 - results is a list of tuple with |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1454 - service (unicode): pubsub service |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1455 - node (unicode): pubsub node |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1456 - failure (unicode): empty string in case of success, error message else |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1457 - items (list[s]): raw XML of items |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1458 - metadata(dict): serialised metadata |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1459 """ |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1460 profile = self.host.getClient(profile_key).profile |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1461 d = self.rt_sessions.getResults( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1462 session_id, |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2801
diff
changeset
|
1463 on_success=lambda result: ("", self.transItemsData(result)), |
3028 | 1464 on_error=lambda failure: (str(failure.value) or UNSPECIFIED, ([], {})), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1465 profile=profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1466 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1467 d.addCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1468 lambda ret: ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1469 ret[0], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1470 [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1471 (service.full(), node, failure, items, metadata) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1472 for (service, node), (success, (failure, (items, metadata))) in ret[ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1473 1 |
3028 | 1474 ].items() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1475 ], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1476 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1477 ) |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1478 return d |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1479 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1480 def _getFromMany( |
3586
5f65f4e9f8cb
plugin XEP-0060: getItems extra is now serialised dict
Goffi <goffi@goffi.org>
parents:
3584
diff
changeset
|
1481 self, node_data, max_item=10, extra="", profile_key=C.PROF_KEY_NONE |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1482 ): |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1483 """ |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1484 @param max_item(int): maximum number of item to get, C.NO_LIMIT for no limit |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1485 """ |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1486 max_item = None if max_item == C.NO_LIMIT else max_item |
3586
5f65f4e9f8cb
plugin XEP-0060: getItems extra is now serialised dict
Goffi <goffi@goffi.org>
parents:
3584
diff
changeset
|
1487 extra = self.parseExtra(data_format.deserialise(extra)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1488 return self.getFromMany( |
3028 | 1489 [(jid.JID(service), str(node)) for service, node in node_data], |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1490 max_item, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1491 extra.rsm_request, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1492 extra.extra, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1493 profile_key, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1494 ) |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1495 |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2801
diff
changeset
|
1496 def getFromMany(self, node_data, max_item=None, rsm_request=None, extra=None, |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2801
diff
changeset
|
1497 profile_key=C.PROF_KEY_NONE): |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1498 """Get items from many nodes at once |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1499 |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1500 @param node_data (iterable[tuple]): iterable of tuple (service, node) where: |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1501 - service (jid.JID) is the pubsub service |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1502 - node (unicode) is the node to get items from |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1503 @param max_items (int): optional limit on the number of retrieved items. |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1504 @param rsm_request (RSMRequest): RSM request data |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1505 @param profile_key (unicode): %(doc_profile_key)s |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1506 @return (str): RT Deferred session id |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1507 """ |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1508 client = self.host.getClient(profile_key) |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1509 deferreds = {} |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1510 for service, node in node_data: |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1511 deferreds[(service, node)] = defer.ensureDeferred(self.getItems( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1512 client, service, node, max_item, rsm_request=rsm_request, extra=extra |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1513 )) |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1514 return self.rt_sessions.newSession(deferreds, client.profile) |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1515 |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1516 |
3028 | 1517 @implementer(disco.IDisco) |
1267
ea692d51a0ee
plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
1261
diff
changeset
|
1518 class SatPubSubClient(rsm.PubSubClient): |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1519 |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1520 def __init__(self, host, parent_plugin): |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
1521 self.host = host |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1522 self.parent_plugin = parent_plugin |
1267
ea692d51a0ee
plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
1261
diff
changeset
|
1523 rsm.PubSubClient.__init__(self) |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1524 |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1525 def connectionInitialized(self): |
1267
ea692d51a0ee
plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
1261
diff
changeset
|
1526 rsm.PubSubClient.connectionInitialized(self) |
745
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
704
diff
changeset
|
1527 |
1760
30efe084471c
plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents:
1678
diff
changeset
|
1528 def _getNodeCallbacks(self, node, event): |
30efe084471c
plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents:
1678
diff
changeset
|
1529 """Generate callbacks from given node and event |
30efe084471c
plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents:
1678
diff
changeset
|
1530 |
30efe084471c
plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents:
1678
diff
changeset
|
1531 @param node(unicode): node used for the item |
30efe084471c
plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents:
1678
diff
changeset
|
1532 any registered node which prefix the node will match |
30efe084471c
plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents:
1678
diff
changeset
|
1533 @param event(unicode): one of C.PS_ITEMS, C.PS_RETRACT, C.PS_DELETE |
30efe084471c
plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents:
1678
diff
changeset
|
1534 @return (iterator[callable]): callbacks for this node/event |
30efe084471c
plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents:
1678
diff
changeset
|
1535 """ |
3028 | 1536 for registered_node, callbacks_dict in self.parent_plugin._node_cb.items(): |
1760
30efe084471c
plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents:
1678
diff
changeset
|
1537 if not node.startswith(registered_node): |
30efe084471c
plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents:
1678
diff
changeset
|
1538 continue |
30efe084471c
plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents:
1678
diff
changeset
|
1539 try: |
30efe084471c
plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents:
1678
diff
changeset
|
1540 for callback in callbacks_dict[event]: |
30efe084471c
plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents:
1678
diff
changeset
|
1541 yield callback |
30efe084471c
plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents:
1678
diff
changeset
|
1542 except KeyError: |
30efe084471c
plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents:
1678
diff
changeset
|
1543 continue |
30efe084471c
plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents:
1678
diff
changeset
|
1544 |
2760
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
1545 |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1546 def itemsReceived(self, event): |
3028 | 1547 log.debug("Pubsub items received") |
1760
30efe084471c
plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents:
1678
diff
changeset
|
1548 for callback in self._getNodeCallbacks(event.nodeIdentifier, C.PS_ITEMS): |
3588
2c7a52a62be3
plugin XEP-0060: events callbacks can now be sync or async
Goffi <goffi@goffi.org>
parents:
3587
diff
changeset
|
1549 d = utils.asDeferred(callback, self.parent, event) |
2c7a52a62be3
plugin XEP-0060: events callbacks can now be sync or async
Goffi <goffi@goffi.org>
parents:
3587
diff
changeset
|
1550 d.addErrback(lambda f: log.error( |
2c7a52a62be3
plugin XEP-0060: events callbacks can now be sync or async
Goffi <goffi@goffi.org>
parents:
3587
diff
changeset
|
1551 f"Error while running items event callback {callback}: {f}" |
2c7a52a62be3
plugin XEP-0060: events callbacks can now be sync or async
Goffi <goffi@goffi.org>
parents:
3587
diff
changeset
|
1552 )) |
2444
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1553 client = self.parent |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1554 if (event.sender, event.nodeIdentifier) in client.pubsub_watching: |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1555 raw_items = [i.toXml() for i in event.items] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1556 self.host.bridge.psEventRaw( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1557 event.sender.full(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1558 event.nodeIdentifier, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1559 C.PS_ITEMS, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1560 raw_items, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1561 client.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1562 ) |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1563 |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1564 def deleteReceived(self, event): |
3028 | 1565 log.debug(("Publish node deleted")) |
1760
30efe084471c
plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents:
1678
diff
changeset
|
1566 for callback in self._getNodeCallbacks(event.nodeIdentifier, C.PS_DELETE): |
3588
2c7a52a62be3
plugin XEP-0060: events callbacks can now be sync or async
Goffi <goffi@goffi.org>
parents:
3587
diff
changeset
|
1567 d = utils.asDeferred(callback, self.parent, event) |
2c7a52a62be3
plugin XEP-0060: events callbacks can now be sync or async
Goffi <goffi@goffi.org>
parents:
3587
diff
changeset
|
1568 d.addErrback(lambda f: log.error( |
2c7a52a62be3
plugin XEP-0060: events callbacks can now be sync or async
Goffi <goffi@goffi.org>
parents:
3587
diff
changeset
|
1569 f"Error while running delete event callback {callback}: {f}" |
2c7a52a62be3
plugin XEP-0060: events callbacks can now be sync or async
Goffi <goffi@goffi.org>
parents:
3587
diff
changeset
|
1570 )) |
2444
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1571 client = self.parent |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1572 if (event.sender, event.nodeIdentifier) in client.pubsub_watching: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1573 self.host.bridge.psEventRaw( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1574 event.sender.full(), event.nodeIdentifier, C.PS_DELETE, [], client.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1575 ) |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
1576 |
3587
2715da5b2aa7
plugin XEP-0060: handle purge notifications
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
1577 def purgeReceived(self, event): |
2715da5b2aa7
plugin XEP-0060: handle purge notifications
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
1578 log.debug(("Publish node purged")) |
2715da5b2aa7
plugin XEP-0060: handle purge notifications
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
1579 for callback in self._getNodeCallbacks(event.nodeIdentifier, C.PS_PURGE): |
2715da5b2aa7
plugin XEP-0060: handle purge notifications
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
1580 d = utils.asDeferred(callback, self.parent, event) |
2715da5b2aa7
plugin XEP-0060: handle purge notifications
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
1581 d.addErrback(lambda f: log.error( |
2715da5b2aa7
plugin XEP-0060: handle purge notifications
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
1582 f"Error while running purge event callback {callback}: {f}" |
2715da5b2aa7
plugin XEP-0060: handle purge notifications
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
1583 )) |
2715da5b2aa7
plugin XEP-0060: handle purge notifications
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
1584 client = self.parent |
2715da5b2aa7
plugin XEP-0060: handle purge notifications
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
1585 if (event.sender, event.nodeIdentifier) in client.pubsub_watching: |
2715da5b2aa7
plugin XEP-0060: handle purge notifications
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
1586 self.host.bridge.psEventRaw( |
2715da5b2aa7
plugin XEP-0060: handle purge notifications
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
1587 event.sender.full(), event.nodeIdentifier, C.PS_PURGE, [], client.profile |
2715da5b2aa7
plugin XEP-0060: handle purge notifications
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
1588 ) |
2715da5b2aa7
plugin XEP-0060: handle purge notifications
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
1589 |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
1590 def subscriptions(self, service, nodeIdentifier, sender=None): |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
1591 """Return the list of subscriptions to the given service and node. |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1592 |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
1593 @param service: The publish subscribe service to retrieve the subscriptions from. |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
1594 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>} |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
1595 @param nodeIdentifier: The identifier of the node (leave empty to retrieve all subscriptions). |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
1596 @type nodeIdentifier: C{unicode} |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1597 @return (list[pubsub.Subscription]): list of subscriptions |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
1598 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1599 request = pubsub.PubSubRequest("subscriptions") |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
1600 request.recipient = service |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
1601 request.nodeIdentifier = nodeIdentifier |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
1602 request.sender = sender |
1267
ea692d51a0ee
plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
1261
diff
changeset
|
1603 d = request.send(self.xmlstream) |
ea692d51a0ee
plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
1261
diff
changeset
|
1604 |
ea692d51a0ee
plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
1261
diff
changeset
|
1605 def cb(iq): |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1606 subs = [] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1607 for subscription_elt in iq.pubsub.subscriptions.elements( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1608 pubsub.NS_PUBSUB, "subscription" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1609 ): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1610 subscription = pubsub.Subscription( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1611 subscription_elt["node"], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1612 jid.JID(subscription_elt["jid"]), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1613 subscription_elt["subscription"], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1614 subscriptionIdentifier=subscription_elt.getAttribute("subid"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1615 ) |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1616 subs.append(subscription) |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1617 return subs |
1267
ea692d51a0ee
plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
1261
diff
changeset
|
1618 |
ea692d51a0ee
plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
1261
diff
changeset
|
1619 return d.addCallback(cb) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1620 |
2801
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1621 def purgeNode(self, service, nodeIdentifier): |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1622 """Purge a node (i.e. delete all items from it) |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1623 |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1624 @param service(jid.JID, None): service to send the item to |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1625 None to use PEP |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1626 @param NodeIdentifier(unicode): PubSub node to use |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1627 """ |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1628 # TODO: propose this upstream and remove it once merged |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1629 request = pubsub.PubSubRequest('purge') |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1630 request.recipient = service |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1631 request.nodeIdentifier = nodeIdentifier |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1632 return request.send(self.xmlstream) |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1633 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1634 def getDiscoInfo(self, requestor, service, nodeIdentifier=""): |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
1635 disco_info = [] |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
1636 self.host.trigger.point("PubSub Disco Info", disco_info, self.parent.profile) |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
1637 return disco_info |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
1638 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1639 def getDiscoItems(self, requestor, service, nodeIdentifier=""): |
1259
633fcd13a7dc
plugin pubsub: fixed a bug introducted in revision 318eab3f93f8: getDiscoItems handler method which is called on disco items request, was calling getDiscoItems from host, which do a request itself, resulting in an infinite items request loop.
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
1640 return [] |