Mercurial > libervia-backend
annotate sat/plugins/plugin_xep_0277.py @ 3905:92482cc80d0b
tools (common/date_utils) handle timestamp and `in` + `delta2human`:
regex used to parse datetimes has been improved to handle a unix time (which can be used
with `+ <delta>` or `- <delta>`), and the `in <delta>` (e.g. `in 6 days`).
`DEFAULT_DATETIME` has been removed as dateutil use current date by default, which is the
expected behaviour.
Add `delta2human` method which convert the difference of 2 unix times to a human friendly
approximate text.
rel 372
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 22 Sep 2022 00:01:48 +0200 |
parents | 37a1193d90db |
children | 6c5f0fbc519b |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
3 # SAT plugin for microblogging over XMPP (xep-0277) |
3479 | 4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
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. |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
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. |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
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/>. |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
19 import time |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
20 import dateutil |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
21 import calendar |
3502
6132d363f0e9
plugin XEP-0277: user friendly ID:
Goffi <goffi@goffi.org>
parents:
3493
diff
changeset
|
22 from secrets import token_urlsafe |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
23 from typing import Optional, Dict, Union, Any |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
24 from functools import partial |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
25 |
3502
6132d363f0e9
plugin XEP-0277: user friendly ID:
Goffi <goffi@goffi.org>
parents:
3493
diff
changeset
|
26 import shortuuid |
6132d363f0e9
plugin XEP-0277: user friendly ID:
Goffi <goffi@goffi.org>
parents:
3493
diff
changeset
|
27 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
28 from twisted.words.protocols.jabber import jid, error |
2341
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
29 from twisted.words.protocols.jabber.xmlstream import XMPPHandler |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
30 from twisted.words.xish import domish |
706
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
31 from twisted.internet import defer |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
32 from twisted.python import failure |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
33 |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
34 # XXX: sat_tmp.wokkel.pubsub is actually used instead of wokkel version |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
35 from wokkel import pubsub |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
36 from wokkel import disco, iwokkel |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
37 from zope.interface import implementer |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
38 |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
39 from sat.core.i18n import _ |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
40 from sat.core.constants import Const as C |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
41 from sat.core.log import getLogger |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
42 from sat.core import exceptions |
3680
68f2a9c171d1
plugin XEP-0277: import `SatXMPPEntity` from core_types
Goffi <goffi@goffi.org>
parents:
3661
diff
changeset
|
43 from sat.core.core_types import SatXMPPEntity |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
44 from sat.tools import xml_tools |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
45 from sat.tools import sat_defer |
1935
1128feb54180
core: removed pyfeed and xe dependencies:
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
46 from sat.tools import utils |
1919
d3354c80bd1f
core (tools): moved common to a separate package, and put data method in a data_format module
Goffi <goffi@goffi.org>
parents:
1913
diff
changeset
|
47 from sat.tools.common import data_format |
2480
dc55b854ccf3
plugin XEP-0277: use shortuuid instead of uuid + use item's XMPP URI for atom ID
Goffi <goffi@goffi.org>
parents:
2475
diff
changeset
|
48 from sat.tools.common import uri as xmpp_uri |
3502
6132d363f0e9
plugin XEP-0277: user friendly ID:
Goffi <goffi@goffi.org>
parents:
3493
diff
changeset
|
49 from sat.tools.common import regex |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 |
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 |
3179
84a94b385760
bridge: messageSend's extra is now serialised
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
52 log = getLogger(__name__) |
84a94b385760
bridge: messageSend's extra is now serialised
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
53 |
84a94b385760
bridge: messageSend's extra is now serialised
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
54 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
55 NS_MICROBLOG = "urn:xmpp:microblog:0" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
56 NS_ATOM = "http://www.w3.org/2005/Atom" |
3598
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
57 NS_PUBSUB_EVENT = f"{pubsub.NS_PUBSUB}#event" |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
58 NS_COMMENT_PREFIX = f"{NS_MICROBLOG}:comments/" |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
59 |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 |
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 PLUGIN_INFO = { |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2117
diff
changeset
|
62 C.PI_NAME: "Microblogging over XMPP Plugin", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2117
diff
changeset
|
63 C.PI_IMPORT_NAME: "XEP-0277", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2117
diff
changeset
|
64 C.PI_TYPE: "XEP", |
3726
33d75cd3c371
plugin XEP-0060, XEP-0163, XEP-0277, text syntaxes: make those plugins usable with components
Goffi <goffi@goffi.org>
parents:
3724
diff
changeset
|
65 C.PI_MODES: C.PLUG_MODE_BOTH, |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2117
diff
changeset
|
66 C.PI_PROTOCOLS: ["XEP-0277"], |
2780
85d3240a400f
plugin text syntaxes: changed import name to TEXT_SYNTAX (better with underscore for autocompletion)
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
67 C.PI_DEPENDENCIES: ["XEP-0163", "XEP-0060", "TEXT_SYNTAXES"], |
3598
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
68 C.PI_RECOMMENDATIONS: ["XEP-0059", "EXTRA-PEP", "PUBSUB_CACHE"], |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2117
diff
changeset
|
69 C.PI_MAIN: "XEP_0277", |
2341
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
70 C.PI_HANDLER: "yes", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
71 C.PI_DESCRIPTION: _("""Implementation of microblogging Protocol"""), |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 } |
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
74 |
339
b0b773f432e5
plugin XEP-00277: setMicroblogAccess is now asynchronous
Goffi <goffi@goffi.org>
parents:
311
diff
changeset
|
75 class NodeAccessChangeException(Exception): |
b0b773f432e5
plugin XEP-00277: setMicroblogAccess is now asynchronous
Goffi <goffi@goffi.org>
parents:
311
diff
changeset
|
76 pass |
b0b773f432e5
plugin XEP-00277: setMicroblogAccess is now asynchronous
Goffi <goffi@goffi.org>
parents:
311
diff
changeset
|
77 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
78 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
79 class XEP_0277(object): |
1831
68c0dc13d821
plugin blog import, XEP-0277: progress + redirect:
Goffi <goffi@goffi.org>
parents:
1829
diff
changeset
|
80 namespace = NS_MICROBLOG |
3724
a0c08fcfe11e
plugin XEP-0277: various fixes + async:
Goffi <goffi@goffi.org>
parents:
3680
diff
changeset
|
81 NS_ATOM = NS_ATOM |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 |
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 def __init__(self, host): |
3028 | 84 log.info(_("Microblogging plugin initialization")) |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 self.host = host |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
86 host.registerNamespace("microblog", NS_MICROBLOG) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
87 self._p = self.host.plugins[ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
88 "XEP-0060" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
89 ] # this facilitate the access to pubsub plugin |
3598
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
90 ps_cache = self.host.plugins.get("PUBSUB_CACHE") |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
91 if ps_cache is not None: |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
92 ps_cache.registerAnalyser( |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
93 { |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
94 "name": "XEP-0277", |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
95 "node": NS_MICROBLOG, |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
96 "namespace": NS_ATOM, |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
97 "type": "blog", |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
98 "to_sync": True, |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
99 "parser": self.item2mbdata, |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
100 "match_cb": self._cacheNodeMatchCb, |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
101 } |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
102 ) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
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 self.host.plugins["XEP-0060"].addManagedNode( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
105 NS_MICROBLOG, items_cb=self._itemsReceived |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
106 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
107 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
108 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
109 "mbSend", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
110 ".plugin", |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
111 in_sign="ssss", |
3848
e9c380ef41c8
plugin XEP-0277: return ID of published item in `send` and bridge's `mbSend`
Goffi <goffi@goffi.org>
parents:
3840
diff
changeset
|
112 out_sign="s", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
113 method=self._mbSend, |
3028 | 114 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
115 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
116 host.bridge.addMethod( |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
117 "mbRepeat", |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
118 ".plugin", |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
119 in_sign="sssss", |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
120 out_sign="s", |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
121 method=self._mbRepeat, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
122 async_=True, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
123 ) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
124 host.bridge.addMethod( |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
125 "mbPreview", |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
126 ".plugin", |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
127 in_sign="ssss", |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
128 out_sign="s", |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
129 method=self._mbPreview, |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
130 async_=True, |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
131 ) |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
132 host.bridge.addMethod( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
133 "mbRetract", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
134 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
135 in_sign="ssss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
136 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
137 method=self._mbRetract, |
3028 | 138 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
139 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
140 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
141 "mbGet", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
142 ".plugin", |
3586
5f65f4e9f8cb
plugin XEP-0060: getItems extra is now serialised dict
Goffi <goffi@goffi.org>
parents:
3584
diff
changeset
|
143 in_sign="ssiasss", |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
144 out_sign="s", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
145 method=self._mbGet, |
3028 | 146 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
147 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
148 host.bridge.addMethod( |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
149 "mbRename", |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
150 ".plugin", |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
151 in_sign="sssss", |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
152 out_sign="", |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
153 method=self._mbRename, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
154 async_=True, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
155 ) |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
156 host.bridge.addMethod( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
157 "mbSetAccess", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
158 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
159 in_sign="ss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
160 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
161 method=self.mbSetAccess, |
3028 | 162 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
163 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
164 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
165 "mbSubscribeToMany", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
166 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
167 in_sign="sass", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
168 out_sign="s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
169 method=self._mbSubscribeToMany, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
170 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
171 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
172 "mbGetFromManyRTResult", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
173 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
174 in_sign="ss", |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
175 out_sign="(ua(sssasa{ss}))", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
176 method=self._mbGetFromManyRTResult, |
3028 | 177 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
178 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
179 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
180 "mbGetFromMany", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
181 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
182 in_sign="sasia{ss}s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
183 out_sign="s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
184 method=self._mbGetFromMany, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
185 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
186 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
187 "mbGetFromManyWithCommentsRTResult", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
188 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
189 in_sign="ss", |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
190 out_sign="(ua(sssa(sa(sssasa{ss}))a{ss}))", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
191 method=self._mbGetFromManyWithCommentsRTResult, |
3028 | 192 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
193 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
194 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
195 "mbGetFromManyWithComments", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
196 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
197 in_sign="sasiia{ss}a{ss}s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
198 out_sign="s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
199 method=self._mbGetFromManyWithComments, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
200 ) |
3762
becd7f1aa033
plugin XEP-0277: bridge method `mbIsCommentNode` + methods renaming
Goffi <goffi@goffi.org>
parents:
3761
diff
changeset
|
201 host.bridge.addMethod( |
becd7f1aa033
plugin XEP-0277: bridge method `mbIsCommentNode` + methods renaming
Goffi <goffi@goffi.org>
parents:
3761
diff
changeset
|
202 "mbIsCommentNode", |
becd7f1aa033
plugin XEP-0277: bridge method `mbIsCommentNode` + methods renaming
Goffi <goffi@goffi.org>
parents:
3761
diff
changeset
|
203 ".plugin", |
becd7f1aa033
plugin XEP-0277: bridge method `mbIsCommentNode` + methods renaming
Goffi <goffi@goffi.org>
parents:
3761
diff
changeset
|
204 in_sign="s", |
becd7f1aa033
plugin XEP-0277: bridge method `mbIsCommentNode` + methods renaming
Goffi <goffi@goffi.org>
parents:
3761
diff
changeset
|
205 out_sign="b", |
becd7f1aa033
plugin XEP-0277: bridge method `mbIsCommentNode` + methods renaming
Goffi <goffi@goffi.org>
parents:
3761
diff
changeset
|
206 method=self.isCommentNode, |
becd7f1aa033
plugin XEP-0277: bridge method `mbIsCommentNode` + methods renaming
Goffi <goffi@goffi.org>
parents:
3761
diff
changeset
|
207 ) |
302
9f3a6cf91668
plugin xep-0277: added getLastMicroblogs method
Goffi <goffi@goffi.org>
parents:
297
diff
changeset
|
208 |
2341
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
209 def getHandler(self, client): |
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
210 return XEP_0277_handler() |
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
211 |
3598
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
212 def _cacheNodeMatchCb( |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
213 self, |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
214 client: SatXMPPEntity, |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
215 analyse: dict, |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
216 ) -> None: |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
217 """Check is analysed node is a comment and fill analyse accordingly""" |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
218 if analyse["node"].startswith(NS_COMMENT_PREFIX): |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
219 analyse["subtype"] = "comment" |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
220 |
1656
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
221 def _checkFeaturesCb(self, available): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
222 return {"available": C.BOOL_TRUE} |
1656
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
223 |
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
224 def _checkFeaturesEb(self, fail): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
225 return {"available": C.BOOL_FALSE} |
1656
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
226 |
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
227 def getFeatures(self, profile): |
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
|
228 client = self.host.getClient(profile) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
229 d = self.host.checkFeatures(client, [], identity=("pubsub", "pep")) |
1656
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
230 d.addCallbacks(self._checkFeaturesCb, self._checkFeaturesEb) |
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
231 return d |
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
232 |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
233 ## plugin management methods ## |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
234 |
2305
972e33507609
plugin XEP-0060: addManagedNode callbacks now use client syntax instead of profile
Goffi <goffi@goffi.org>
parents:
2289
diff
changeset
|
235 def _itemsReceived(self, client, itemsEvent): |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
236 """Callback which manage items notifications (publish + retract)""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
237 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
238 def manageItem(data, event): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
239 self.host.bridge.psEvent( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
240 C.PS_MICROBLOG, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
241 itemsEvent.sender.full(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
242 itemsEvent.nodeIdentifier, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
243 event, |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
244 data_format.serialise(data), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
245 client.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
246 ) |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
247 |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
248 for item in itemsEvent.items: |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
249 if item.name == C.PS_ITEM: |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
250 # FIXME: service and node should be used here |
3341
13b91b7280bc
plugin XEP-0277: fixed item2mbdata call
Goffi <goffi@goffi.org>
parents:
3328
diff
changeset
|
251 self.item2mbdata(client, item, None, None).addCallbacks( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
252 manageItem, lambda failure: None, (C.PS_PUBLISH,) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
253 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
254 elif item.name == C.PS_RETRACT: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
255 manageItem({"id": item["id"]}, C.PS_RETRACT) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
256 else: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
257 raise exceptions.InternalError("Invalid event value") |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
258 |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
259 ## data/item transformation ## |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
260 |
707
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
261 @defer.inlineCallbacks |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
262 def item2mbdata( |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
263 self, |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
264 client: SatXMPPEntity, |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
265 item_elt: domish.Element, |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
266 service: Optional[jid.JID], |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
267 # FIXME: node is Optional until all calls to item2mbdata set properly service |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
268 # and node. Once done, the Optional must be removed here |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
269 node: Optional[str] |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
270 ) -> dict: |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
271 """Convert an XML Item to microblog data |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
272 |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
273 @param item_elt: microblog item element |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
274 @param service: PubSub service where the item has been retrieved |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
275 profile's PEP is used when service is None |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
276 @param node: PubSub node where the item has been retrieved |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
277 if None, "uri" won't be set |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
278 @return: microblog data |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
279 """ |
3763
b2ade5ecdbab
plugin XEP-0277: be sure to have `service` set in `item2mbdata` and `node` when provided
Goffi <goffi@goffi.org>
parents:
3762
diff
changeset
|
280 if service is None: |
b2ade5ecdbab
plugin XEP-0277: be sure to have `service` set in `item2mbdata` and `node` when provided
Goffi <goffi@goffi.org>
parents:
3762
diff
changeset
|
281 service = client.jid.userhostJID() |
b2ade5ecdbab
plugin XEP-0277: be sure to have `service` set in `item2mbdata` and `node` when provided
Goffi <goffi@goffi.org>
parents:
3762
diff
changeset
|
282 |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
283 extra: Dict[str, Any] = {} |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
284 microblog_data: Dict[str, Any] = { |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
285 "service": service.full(), |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
286 "extra": extra |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
287 } |
832
c4b22aedb7d7
plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
288 |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
289 def check_conflict(key, increment=False): |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
290 """Check if key is already in microblog data |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
291 |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
292 @param key(unicode): key to check |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
293 @param increment(bool): if suffix the key with an increment |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
294 instead of raising an exception |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
295 @raise exceptions.DataError: the key already exists |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
296 (not raised if increment is True) |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
297 """ |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
298 if key in microblog_data: |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
299 if not increment: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
300 raise failure.Failure( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
301 exceptions.DataError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
302 "key {} is already present for item {}" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
303 ).format(key, item_elt["id"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
304 ) |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
305 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
306 idx = 1 # the idx 0 is the key without suffix |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
307 fmt = "{}#{}" |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
308 new_key = fmt.format(key, idx) |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
309 while new_key in microblog_data: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
310 idx += 1 |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
311 new_key = fmt.format(key, idx) |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
312 key = new_key |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
313 return key |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
314 |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
315 @defer.inlineCallbacks |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
316 def parseElement(elem): |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
317 """Parse title/content elements and fill microblog_data accordingly""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
318 type_ = elem.getAttribute("type") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
319 if type_ == "xhtml": |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
320 data_elt = elem.firstChildElement() |
1709
c47ba491a85a
plugin XEP-0277: raise a failure if XHTML content is not wrapped in a <div/>
Goffi <goffi@goffi.org>
parents:
1708
diff
changeset
|
321 if data_elt is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
322 raise failure.Failure( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
323 exceptions.DataError( |
3028 | 324 "XHML content not wrapped in a <div/> element, this is not " |
325 "standard !" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
326 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
327 ) |
1822
aaf034bc6f7a
plugin XEP-0277: moved NS_XHTML namespace to constants + adapted parsing to new behaviour of ElementParser
Goffi <goffi@goffi.org>
parents:
1821
diff
changeset
|
328 if data_elt.uri != C.NS_XHTML: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
329 raise failure.Failure( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
330 exceptions.DataError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
331 _("Content of type XHTML must declare its namespace!") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
332 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
333 ) |
3028 | 334 key = check_conflict("{}_xhtml".format(elem.name)) |
1791 | 335 data = data_elt.toXml() |
2780
85d3240a400f
plugin text syntaxes: changed import name to TEXT_SYNTAX (better with underscore for autocompletion)
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
336 microblog_data[key] = yield self.host.plugins["TEXT_SYNTAXES"].cleanXHTML( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
337 data |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
338 ) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
339 else: |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
340 key = check_conflict(elem.name) |
3028 | 341 microblog_data[key] = str(elem) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
342 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
343 id_ = item_elt.getAttribute("id", "") # there can be no id for transient nodes |
3028 | 344 microblog_data["id"] = id_ |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
345 if item_elt.uri not in (pubsub.NS_PUBSUB, NS_PUBSUB_EVENT): |
3028 | 346 msg = "Unsupported namespace {ns} in pubsub item {id_}".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
347 ns=item_elt.uri, id_=id_ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
348 ) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
349 log.warning(msg) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
350 raise failure.Failure(exceptions.DataError(msg)) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
351 |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
352 try: |
3028 | 353 entry_elt = next(item_elt.elements(NS_ATOM, "entry")) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
354 except StopIteration: |
3028 | 355 msg = "No atom entry found in the pubsub item {}".format(id_) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
356 raise failure.Failure(exceptions.DataError(msg)) |
859
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
858
diff
changeset
|
357 |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
358 # uri |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
359 # FIXME: node should alway be set in the future, check FIXME in method signature |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
360 if node is not None: |
3763
b2ade5ecdbab
plugin XEP-0277: be sure to have `service` set in `item2mbdata` and `node` when provided
Goffi <goffi@goffi.org>
parents:
3762
diff
changeset
|
361 microblog_data["node"] = node |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
362 microblog_data['uri'] = xmpp_uri.buildXMPPUri( |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
363 "pubsub", |
3763
b2ade5ecdbab
plugin XEP-0277: be sure to have `service` set in `item2mbdata` and `node` when provided
Goffi <goffi@goffi.org>
parents:
3762
diff
changeset
|
364 path=service.full(), |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
365 node=node, |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
366 item=id_, |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
367 ) |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
368 |
2264
a8eaaac4d80f
plugin XEP-0277, tools/common/data_objects: language handling
Goffi <goffi@goffi.org>
parents:
2243
diff
changeset
|
369 # language |
a8eaaac4d80f
plugin XEP-0277, tools/common/data_objects: language handling
Goffi <goffi@goffi.org>
parents:
2243
diff
changeset
|
370 try: |
3028 | 371 microblog_data["language"] = entry_elt[(C.NS_XML, "lang")].strip() |
2264
a8eaaac4d80f
plugin XEP-0277, tools/common/data_objects: language handling
Goffi <goffi@goffi.org>
parents:
2243
diff
changeset
|
372 except KeyError: |
a8eaaac4d80f
plugin XEP-0277, tools/common/data_objects: language handling
Goffi <goffi@goffi.org>
parents:
2243
diff
changeset
|
373 pass |
a8eaaac4d80f
plugin XEP-0277, tools/common/data_objects: language handling
Goffi <goffi@goffi.org>
parents:
2243
diff
changeset
|
374 |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
375 # atom:id |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
376 try: |
3028 | 377 id_elt = next(entry_elt.elements(NS_ATOM, "id")) |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
378 except StopIteration: |
3028 | 379 msg = ("No atom id found in the pubsub item {}, this is not standard !" |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
380 .format(id_)) |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
381 log.warning(msg) |
3028 | 382 microblog_data["atom_id"] = "" |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
383 else: |
3028 | 384 microblog_data["atom_id"] = str(id_elt) |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
385 |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
386 # title/content(s) |
1708
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
387 |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
388 # FIXME: ATOM and XEP-0277 only allow 1 <title/> element |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
389 # but in the wild we have some blogs with several ones |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
390 # so we don't respect the standard for now (it doesn't break |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
391 # anything anyway), and we'll find a better option later |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
392 # try: |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
393 # title_elt = entry_elt.elements(NS_ATOM, 'title').next() |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
394 # except StopIteration: |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
395 # msg = u'No atom title found in the pubsub item {}'.format(id_) |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
396 # raise failure.Failure(exceptions.DataError(msg)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
397 title_elts = list(entry_elt.elements(NS_ATOM, "title")) |
1708
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
398 if not title_elts: |
3028 | 399 msg = "No atom title found in the pubsub item {}".format(id_) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
400 raise failure.Failure(exceptions.DataError(msg)) |
1708
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
401 for title_elt in title_elts: |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
402 yield parseElement(title_elt) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
403 |
1708
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
404 # FIXME: as for <title/>, Atom only authorise at most 1 content |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
405 # but XEP-0277 allows several ones. So for no we handle as |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
406 # if more than one can be present |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
407 for content_elt in entry_elt.elements(NS_ATOM, "content"): |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
408 yield parseElement(content_elt) |
859
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
858
diff
changeset
|
409 |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
410 # we check that text content is present |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
411 for key in ("title", "content"): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
412 if key not in microblog_data and ("{}_xhtml".format(key)) in microblog_data: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
413 log.warning( |
3028 | 414 "item {id_} provide a {key}_xhtml data but not a text one".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
415 id_=id_, key=key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
416 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
417 ) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
418 # ... and do the conversion if it's not |
2780
85d3240a400f
plugin text syntaxes: changed import name to TEXT_SYNTAX (better with underscore for autocompletion)
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
419 microblog_data[key] = yield self.host.plugins["TEXT_SYNTAXES"].convert( |
3028 | 420 microblog_data["{}_xhtml".format(key)], |
2780
85d3240a400f
plugin text syntaxes: changed import name to TEXT_SYNTAX (better with underscore for autocompletion)
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
421 self.host.plugins["TEXT_SYNTAXES"].SYNTAX_XHTML, |
85d3240a400f
plugin text syntaxes: changed import name to TEXT_SYNTAX (better with underscore for autocompletion)
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
422 self.host.plugins["TEXT_SYNTAXES"].SYNTAX_TEXT, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
423 False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
424 ) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
425 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
426 if "content" not in microblog_data: |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
427 # use the atom title data as the microblog body content |
3028 | 428 microblog_data["content"] = microblog_data["title"] |
429 del microblog_data["title"] | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
430 if "title_xhtml" in microblog_data: |
3028 | 431 microblog_data["content_xhtml"] = microblog_data["title_xhtml"] |
432 del microblog_data["title_xhtml"] | |
832
c4b22aedb7d7
plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
433 |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
434 # published/updated dates |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
435 try: |
3028 | 436 updated_elt = next(entry_elt.elements(NS_ATOM, "updated")) |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
437 except StopIteration: |
3028 | 438 msg = "No atom updated element found in the pubsub item {}".format(id_) |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
439 raise failure.Failure(exceptions.DataError(msg)) |
3028 | 440 microblog_data["updated"] = calendar.timegm( |
441 dateutil.parser.parse(str(updated_elt)).utctimetuple() | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
442 ) |
302
9f3a6cf91668
plugin xep-0277: added getLastMicroblogs method
Goffi <goffi@goffi.org>
parents:
297
diff
changeset
|
443 try: |
3028 | 444 published_elt = next(entry_elt.elements(NS_ATOM, "published")) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
445 except StopIteration: |
3028 | 446 microblog_data["published"] = microblog_data["updated"] |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
447 else: |
3028 | 448 microblog_data["published"] = calendar.timegm( |
449 dateutil.parser.parse(str(published_elt)).utctimetuple() | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
450 ) |
859
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
858
diff
changeset
|
451 |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
452 # links |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
453 comments = microblog_data['comments'] = [] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
454 for link_elt in entry_elt.elements(NS_ATOM, "link"): |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
455 rel = link_elt.getAttribute("rel") |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
456 if (rel == "replies" and link_elt.getAttribute("title") == "comments"): |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
457 uri = link_elt["href"] |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
458 comments_data = { |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
459 "uri": uri, |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
460 } |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
461 try: |
3763
b2ade5ecdbab
plugin XEP-0277: be sure to have `service` set in `item2mbdata` and `node` when provided
Goffi <goffi@goffi.org>
parents:
3762
diff
changeset
|
462 comment_service, comment_node = self.parseCommentUrl(uri) |
3069
73db9db8b9e1
plugin XEP-0277: fixed comments URLs parsing
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
463 except Exception as e: |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
464 log.warning(f"Can't parse comments url: {e}") |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
465 continue |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
466 else: |
3763
b2ade5ecdbab
plugin XEP-0277: be sure to have `service` set in `item2mbdata` and `node` when provided
Goffi <goffi@goffi.org>
parents:
3762
diff
changeset
|
467 comments_data["service"] = comment_service.full() |
b2ade5ecdbab
plugin XEP-0277: be sure to have `service` set in `item2mbdata` and `node` when provided
Goffi <goffi@goffi.org>
parents:
3762
diff
changeset
|
468 comments_data["node"] = comment_node |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
469 comments.append(comments_data) |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
470 elif rel == "via": |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
471 href = link_elt.getAttribute("href") |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
472 if not href: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
473 log.warning( |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
474 f'missing href in "via" <link> element: {link_elt.toXml()}' |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
475 ) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
476 continue |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
477 try: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
478 repeater_jid = jid.JID(item_elt["publisher"]) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
479 except (KeyError, RuntimeError): |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
480 try: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
481 # we look for stanza element which is at the root, meaning that it |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
482 # has not parent |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
483 top_elt = item_elt.parent |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
484 while top_elt.parent is not None: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
485 top_elt = top_elt.parent |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
486 repeater_jid = jid.JID(top_elt["from"]) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
487 except (AttributeError, RuntimeError): |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
488 # we should always have either the "publisher" attribute or the |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
489 # stanza available |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
490 log.error( |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
491 f"Can't find repeater of the post: {item_elt.toXml()}" |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
492 ) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
493 continue |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
494 |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
495 extra["repeated"] = { |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
496 "by": repeater_jid.full(), |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
497 "uri": href |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
498 } |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
499 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
500 title = link_elt.getAttribute("title", "") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
501 href = link_elt.getAttribute("href", "") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
502 log.warning( |
3028 | 503 "Unmanaged link element: rel={rel} title={title} href={href}".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
504 rel=rel, title=title, href=href |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
505 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
506 ) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
507 |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
508 # author |
3492
fa796612adad
plugin XEP-0277: better resilience to broken items:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
509 publisher = item_elt.getAttribute("publisher") |
859
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
858
diff
changeset
|
510 try: |
3028 | 511 author_elt = next(entry_elt.elements(NS_ATOM, "author")) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
512 except StopIteration: |
3028 | 513 log.debug("Can't find author element in item {}".format(id_)) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
514 else: |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
515 # name |
770
64dd7c0f4feb
plugin groupblog, XEP-0277: store both published and updated timestamps
souliane <souliane@mailoo.org>
parents:
745
diff
changeset
|
516 try: |
3028 | 517 name_elt = next(author_elt.elements(NS_ATOM, "name")) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
518 except StopIteration: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
519 log.warning( |
3028 | 520 "No name element found in author element of item {}".format(id_) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
521 ) |
3724
a0c08fcfe11e
plugin XEP-0277: various fixes + async:
Goffi <goffi@goffi.org>
parents:
3680
diff
changeset
|
522 author = None |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
523 else: |
3550
7df12ffa6620
plugin XEP-0277: "user" part of author jid is used for author name when later is missing
Goffi <goffi@goffi.org>
parents:
3548
diff
changeset
|
524 author = microblog_data["author"] = str(name_elt).strip() |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
525 # uri |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
526 try: |
3028 | 527 uri_elt = next(author_elt.elements(NS_ATOM, "uri")) |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
528 except StopIteration: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
529 log.debug( |
3028 | 530 "No uri element found in author element of item {}".format(id_) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
531 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
532 if publisher: |
3028 | 533 microblog_data["author_jid"] = publisher |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
534 else: |
3028 | 535 uri = str(uri_elt) |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
536 if uri.startswith("xmpp:"): |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
537 uri = uri[5:] |
3028 | 538 microblog_data["author_jid"] = uri |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
539 else: |
3028 | 540 microblog_data["author_jid"] = ( |
541 item_elt.getAttribute("publisher") or "" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
542 ) |
3550
7df12ffa6620
plugin XEP-0277: "user" part of author jid is used for author name when later is missing
Goffi <goffi@goffi.org>
parents:
3548
diff
changeset
|
543 if not author and microblog_data["author_jid"]: |
7df12ffa6620
plugin XEP-0277: "user" part of author jid is used for author name when later is missing
Goffi <goffi@goffi.org>
parents:
3548
diff
changeset
|
544 # FIXME: temporary workaround for missing author name, would be |
7df12ffa6620
plugin XEP-0277: "user" part of author jid is used for author name when later is missing
Goffi <goffi@goffi.org>
parents:
3548
diff
changeset
|
545 # better to use directly JID's identity (to be done from frontends?) |
7df12ffa6620
plugin XEP-0277: "user" part of author jid is used for author name when later is missing
Goffi <goffi@goffi.org>
parents:
3548
diff
changeset
|
546 try: |
7df12ffa6620
plugin XEP-0277: "user" part of author jid is used for author name when later is missing
Goffi <goffi@goffi.org>
parents:
3548
diff
changeset
|
547 microblog_data["author"] = jid.JID(microblog_data["author_jid"]).user |
7df12ffa6620
plugin XEP-0277: "user" part of author jid is used for author name when later is missing
Goffi <goffi@goffi.org>
parents:
3548
diff
changeset
|
548 except Exception as e: |
7df12ffa6620
plugin XEP-0277: "user" part of author jid is used for author name when later is missing
Goffi <goffi@goffi.org>
parents:
3548
diff
changeset
|
549 log.warning(f"No author name found, and can't parse author jid: {e}") |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
550 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
551 if not publisher: |
3028 | 552 log.debug("No publisher attribute, we can't verify author jid") |
553 microblog_data["author_jid_verified"] = False | |
1681
c6c835046681
plugin XEP-0277: minor fixes for publisher attribute
Goffi <goffi@goffi.org>
parents:
1680
diff
changeset
|
554 elif jid.JID(publisher).userhostJID() == jid.JID(uri).userhostJID(): |
3028 | 555 microblog_data["author_jid_verified"] = True |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
556 else: |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
557 if "repeated" not in extra: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
558 log.warning( |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
559 "item atom:uri differ from publisher attribute, spoofing " |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
560 "attempt ? atom:uri = {} publisher = {}".format( |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
561 uri, item_elt.getAttribute("publisher") |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
562 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
563 ) |
3028 | 564 microblog_data["author_jid_verified"] = False |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
565 # email |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
566 try: |
3028 | 567 email_elt = next(author_elt.elements(NS_ATOM, "email")) |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
568 except StopIteration: |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
569 pass |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
570 else: |
3028 | 571 microblog_data["author_email"] = str(email_elt) |
707
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
572 |
3493
b54bdd4ec507
plugin XEP-0277: be sure to have an `author_jid` set
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
573 if not microblog_data.get("author_jid"): |
b54bdd4ec507
plugin XEP-0277: be sure to have an `author_jid` set
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
574 if publisher: |
b54bdd4ec507
plugin XEP-0277: be sure to have an `author_jid` set
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
575 microblog_data["author_jid"] = publisher |
b54bdd4ec507
plugin XEP-0277: be sure to have an `author_jid` set
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
576 microblog_data["author_jid_verified"] = True |
b54bdd4ec507
plugin XEP-0277: be sure to have an `author_jid` set
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
577 else: |
b54bdd4ec507
plugin XEP-0277: be sure to have an `author_jid` set
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
578 iq_elt = xml_tools.findAncestor(item_elt, "iq", C.NS_CLIENT) |
b54bdd4ec507
plugin XEP-0277: be sure to have an `author_jid` set
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
579 microblog_data["author_jid"] = iq_elt["from"] |
b54bdd4ec507
plugin XEP-0277: be sure to have an `author_jid` set
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
580 microblog_data["author_jid_verified"] = False |
b54bdd4ec507
plugin XEP-0277: be sure to have an `author_jid` set
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
581 |
3492
fa796612adad
plugin XEP-0277: better resilience to broken items:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
582 # categories |
fa796612adad
plugin XEP-0277: better resilience to broken items:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
583 categories = [ |
fa796612adad
plugin XEP-0277: better resilience to broken items:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
584 category_elt.getAttribute("term", "") |
fa796612adad
plugin XEP-0277: better resilience to broken items:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
585 for category_elt in entry_elt.elements(NS_ATOM, "category") |
fa796612adad
plugin XEP-0277: better resilience to broken items:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
586 ] |
fa796612adad
plugin XEP-0277: better resilience to broken items:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
587 microblog_data["tags"] = categories |
1664
5d0ff155be1a
plugin XEP-0277: tags are handled through atom categories
Goffi <goffi@goffi.org>
parents:
1661
diff
changeset
|
588 |
1671
1895846fc9cb
plugin XEP-0277, group blog: added item2data trigger + group permission are parsed when receiving a new item
Goffi <goffi@goffi.org>
parents:
1664
diff
changeset
|
589 ## the trigger ## |
1895846fc9cb
plugin XEP-0277, group blog: added item2data trigger + group permission are parsed when receiving a new item
Goffi <goffi@goffi.org>
parents:
1664
diff
changeset
|
590 # if other plugins have things to add or change |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
591 yield self.host.trigger.point( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
592 "XEP-0277_item2data", item_elt, entry_elt, microblog_data |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
593 ) |
1671
1895846fc9cb
plugin XEP-0277, group blog: added item2data trigger + group permission are parsed when receiving a new item
Goffi <goffi@goffi.org>
parents:
1664
diff
changeset
|
594 |
707
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
595 defer.returnValue(microblog_data) |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
596 |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
597 async def data2entry(self, client, mb_data, item_id, service, node): |
306
169e7386650a
plugin xep-0277: bridge data is now converted in pubsub item in a separate function
Goffi <goffi@goffi.org>
parents:
304
diff
changeset
|
598 """Convert a data dict to en entry usable to create an item |
1419
be2df1ddea8e
plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
599 |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
600 @param mb_data: data dict as given by bridge method. |
2480
dc55b854ccf3
plugin XEP-0277: use shortuuid instead of uuid + use item's XMPP URI for atom ID
Goffi <goffi@goffi.org>
parents:
2475
diff
changeset
|
601 @param item_id(unicode): id of the item to use |
dc55b854ccf3
plugin XEP-0277: use shortuuid instead of uuid + use item's XMPP URI for atom ID
Goffi <goffi@goffi.org>
parents:
2475
diff
changeset
|
602 @param service(jid.JID, None): pubsub service where the item is sent |
dc55b854ccf3
plugin XEP-0277: use shortuuid instead of uuid + use item's XMPP URI for atom ID
Goffi <goffi@goffi.org>
parents:
2475
diff
changeset
|
603 Needed to construct Atom id |
dc55b854ccf3
plugin XEP-0277: use shortuuid instead of uuid + use item's XMPP URI for atom ID
Goffi <goffi@goffi.org>
parents:
2475
diff
changeset
|
604 @param node(unicode): pubsub node where the item is sent |
dc55b854ccf3
plugin XEP-0277: use shortuuid instead of uuid + use item's XMPP URI for atom ID
Goffi <goffi@goffi.org>
parents:
2475
diff
changeset
|
605 Needed to construct Atom id |
1419
be2df1ddea8e
plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
606 @return: deferred which fire domish.Element |
be2df1ddea8e
plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
607 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
608 entry_elt = domish.Element((NS_ATOM, "entry")) |
706
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
609 |
2264
a8eaaac4d80f
plugin XEP-0277, tools/common/data_objects: language handling
Goffi <goffi@goffi.org>
parents:
2243
diff
changeset
|
610 ## language ## |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
611 if "language" in mb_data: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
612 entry_elt[(C.NS_XML, "lang")] = mb_data["language"].strip() |
2264
a8eaaac4d80f
plugin XEP-0277, tools/common/data_objects: language handling
Goffi <goffi@goffi.org>
parents:
2243
diff
changeset
|
613 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
614 ## content and title ## |
2780
85d3240a400f
plugin text syntaxes: changed import name to TEXT_SYNTAX (better with underscore for autocompletion)
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
615 synt = self.host.plugins["TEXT_SYNTAXES"] |
832
c4b22aedb7d7
plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
616 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
617 for elem_name in ("title", "content"): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
618 for type_ in ["", "_rich", "_xhtml"]: |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
619 attr = "{}{}".format(elem_name, type_) |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
620 if attr in mb_data: |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
621 elem = entry_elt.addElement(elem_name) |
832
c4b22aedb7d7
plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
622 if type_: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
623 if type_ == "_rich": # convert input from current syntax to XHTML |
3724
a0c08fcfe11e
plugin XEP-0277: various fixes + async:
Goffi <goffi@goffi.org>
parents:
3680
diff
changeset
|
624 xml_content = await synt.convert( |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
625 mb_data[attr], synt.getCurrentSyntax(client.profile), "XHTML" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
626 ) |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
627 if "{}_xhtml".format(elem_name) in mb_data: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
628 raise failure.Failure( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
629 exceptions.DataError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
630 _( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
631 "Can't have xhtml and rich content at the same time" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
632 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
633 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
634 ) |
1817
7ef0f5f90862
core (xml_tools), plugin XEP-0277: ElementParser element now manage automatically the wrapping with <div/> element when needed + fixed content_xhtml/title_xhtml in XEP-0277
Goffi <goffi@goffi.org>
parents:
1814
diff
changeset
|
635 else: |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
636 xml_content = mb_data[attr] |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
637 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
638 div_elt = xml_tools.ElementParser()( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
639 xml_content, namespace=C.NS_XHTML |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
640 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
641 if ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
642 div_elt.name != "div" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
643 or div_elt.uri != C.NS_XHTML |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
644 or div_elt.attributes |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
645 ): |
1817
7ef0f5f90862
core (xml_tools), plugin XEP-0277: ElementParser element now manage automatically the wrapping with <div/> element when needed + fixed content_xhtml/title_xhtml in XEP-0277
Goffi <goffi@goffi.org>
parents:
1814
diff
changeset
|
646 # we need a wrapping <div/> at the top with XHTML namespace |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
647 wrap_div_elt = domish.Element((C.NS_XHTML, "div")) |
1817
7ef0f5f90862
core (xml_tools), plugin XEP-0277: ElementParser element now manage automatically the wrapping with <div/> element when needed + fixed content_xhtml/title_xhtml in XEP-0277
Goffi <goffi@goffi.org>
parents:
1814
diff
changeset
|
648 wrap_div_elt.addChild(div_elt) |
7ef0f5f90862
core (xml_tools), plugin XEP-0277: ElementParser element now manage automatically the wrapping with <div/> element when needed + fixed content_xhtml/title_xhtml in XEP-0277
Goffi <goffi@goffi.org>
parents:
1814
diff
changeset
|
649 div_elt = wrap_div_elt |
1802
fed95a6c56f8
plugin (xep-0277): avoid wrapping XML in an extra <div> in data2entry
Goffi <goffi@goffi.org>
parents:
1791
diff
changeset
|
650 elem.addChild(div_elt) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
651 elem["type"] = "xhtml" |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
652 if elem_name not in mb_data: |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
653 # there is raw text content, which is mandatory |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
654 # so we create one from xhtml content |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
655 elem_txt = entry_elt.addElement(elem_name) |
3724
a0c08fcfe11e
plugin XEP-0277: various fixes + async:
Goffi <goffi@goffi.org>
parents:
3680
diff
changeset
|
656 text_content = await self.host.plugins[ |
2780
85d3240a400f
plugin text syntaxes: changed import name to TEXT_SYNTAX (better with underscore for autocompletion)
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
657 "TEXT_SYNTAXES" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
658 ].convert( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
659 xml_content, |
2780
85d3240a400f
plugin text syntaxes: changed import name to TEXT_SYNTAX (better with underscore for autocompletion)
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
660 self.host.plugins["TEXT_SYNTAXES"].SYNTAX_XHTML, |
85d3240a400f
plugin text syntaxes: changed import name to TEXT_SYNTAX (better with underscore for autocompletion)
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
661 self.host.plugins["TEXT_SYNTAXES"].SYNTAX_TEXT, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
662 False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
663 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
664 elem_txt.addContent(text_content) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
665 elem_txt["type"] = "text" |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
666 |
832
c4b22aedb7d7
plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
667 else: # raw text only needs to be escaped to get HTML-safe sequence |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
668 elem.addContent(mb_data[attr]) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
669 elem["type"] = "text" |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
670 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
671 try: |
3028 | 672 next(entry_elt.elements(NS_ATOM, "title")) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
673 except StopIteration: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
674 # we have no title element which is mandatory |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
675 # so we transform content element to title |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
676 elems = list(entry_elt.elements(NS_ATOM, "content")) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
677 if not elems: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
678 raise exceptions.DataError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
679 "There must be at least one content or title element" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
680 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
681 for elem in elems: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
682 elem.name = "title" |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
683 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
684 ## author ## |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
685 author_elt = entry_elt.addElement("author") |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
686 try: |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
687 author_name = mb_data["author"] |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
688 except KeyError: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
689 # FIXME: must use better name |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
690 author_name = client.jid.user |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
691 author_elt.addElement("name", content=author_name) |
706
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
692 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
693 try: |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
694 author_jid_s = mb_data["author_jid"] |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
695 except KeyError: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
696 author_jid_s = client.jid.userhost() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
697 author_elt.addElement("uri", content="xmpp:{}".format(author_jid_s)) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
698 |
1820
3c8cf120a0fd
plugin XEP-0277: added missing author_email parsing
Goffi <goffi@goffi.org>
parents:
1817
diff
changeset
|
699 try: |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
700 author_jid_s = mb_data["author_email"] |
1820
3c8cf120a0fd
plugin XEP-0277: added missing author_email parsing
Goffi <goffi@goffi.org>
parents:
1817
diff
changeset
|
701 except KeyError: |
3c8cf120a0fd
plugin XEP-0277: added missing author_email parsing
Goffi <goffi@goffi.org>
parents:
1817
diff
changeset
|
702 pass |
3c8cf120a0fd
plugin XEP-0277: added missing author_email parsing
Goffi <goffi@goffi.org>
parents:
1817
diff
changeset
|
703 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
704 ## published/updated time ## |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
705 current_time = time.time() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
706 entry_elt.addElement( |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
707 "updated", content=utils.xmpp_date(float(mb_data.get("updated", current_time))) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
708 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
709 entry_elt.addElement( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
710 "published", |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
711 content=utils.xmpp_date(float(mb_data.get("published", current_time))), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
712 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
713 |
1664
5d0ff155be1a
plugin XEP-0277: tags are handled through atom categories
Goffi <goffi@goffi.org>
parents:
1661
diff
changeset
|
714 ## categories ## |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
715 for tag in mb_data.get('tags', []): |
1664
5d0ff155be1a
plugin XEP-0277: tags are handled through atom categories
Goffi <goffi@goffi.org>
parents:
1661
diff
changeset
|
716 category_elt = entry_elt.addElement("category") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
717 category_elt["term"] = tag |
1664
5d0ff155be1a
plugin XEP-0277: tags are handled through atom categories
Goffi <goffi@goffi.org>
parents:
1661
diff
changeset
|
718 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
719 ## id ## |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
720 entry_id = mb_data.get( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
721 "id", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
722 xmpp_uri.buildXMPPUri( |
3028 | 723 "pubsub", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
724 path=service.full() if service is not None else client.jid.userhost(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
725 node=node, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
726 item=item_id, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
727 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
728 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
729 entry_elt.addElement("id", content=entry_id) # |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
730 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
731 ## comments ## |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
732 for comments_data in mb_data.get('comments', []): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
733 link_elt = entry_elt.addElement("link") |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
734 # XXX: "uri" is set in self._manageComments if not already existing |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
735 link_elt["href"] = comments_data["uri"] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
736 link_elt["rel"] = "replies" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
737 link_elt["title"] = "comments" |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
738 |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
739 extra = mb_data.get("extra", {}) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
740 if "repeated" in extra: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
741 try: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
742 repeated = extra["repeated"] |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
743 link_elt = entry_elt.addElement("link") |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
744 link_elt["rel"] = "via" |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
745 link_elt["href"] = repeated["uri"] |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
746 except KeyError as e: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
747 log.warning( |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
748 f"invalid repeated element({e}): {extra['repeated']}" |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
749 ) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
750 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
751 ## final item building ## |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
752 item_elt = pubsub.Item(id=item_id, payload=entry_elt) |
1661
96ee986dab3c
plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents:
1656
diff
changeset
|
753 |
96ee986dab3c
plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents:
1656
diff
changeset
|
754 ## the trigger ## |
96ee986dab3c
plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents:
1656
diff
changeset
|
755 # if other plugins have things to add or change |
3724
a0c08fcfe11e
plugin XEP-0277: various fixes + async:
Goffi <goffi@goffi.org>
parents:
3680
diff
changeset
|
756 self.host.trigger.point( |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
757 "XEP-0277_data2entry", client, mb_data, entry_elt, item_elt |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
758 ) |
1661
96ee986dab3c
plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents:
1656
diff
changeset
|
759 |
3724
a0c08fcfe11e
plugin XEP-0277: various fixes + async:
Goffi <goffi@goffi.org>
parents:
3680
diff
changeset
|
760 return item_elt |
306
169e7386650a
plugin xep-0277: bridge data is now converted in pubsub item in a separate function
Goffi <goffi@goffi.org>
parents:
304
diff
changeset
|
761 |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
762 ## publish/preview ## |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
763 |
3762
becd7f1aa033
plugin XEP-0277: bridge method `mbIsCommentNode` + methods renaming
Goffi <goffi@goffi.org>
parents:
3761
diff
changeset
|
764 def isCommentNode(self, node: str) -> bool: |
3740
ea6fda69bb9f
plugin XEP-0277: methods to check is a node is a comments node and to get its parent
Goffi <goffi@goffi.org>
parents:
3726
diff
changeset
|
765 """Indicate if the node is prefixed with comments namespace""" |
3762
becd7f1aa033
plugin XEP-0277: bridge method `mbIsCommentNode` + methods renaming
Goffi <goffi@goffi.org>
parents:
3761
diff
changeset
|
766 return node.startswith(NS_COMMENT_PREFIX) |
3740
ea6fda69bb9f
plugin XEP-0277: methods to check is a node is a comments node and to get its parent
Goffi <goffi@goffi.org>
parents:
3726
diff
changeset
|
767 |
3762
becd7f1aa033
plugin XEP-0277: bridge method `mbIsCommentNode` + methods renaming
Goffi <goffi@goffi.org>
parents:
3761
diff
changeset
|
768 def getParentItem(self, item_id: str) -> str: |
3740
ea6fda69bb9f
plugin XEP-0277: methods to check is a node is a comments node and to get its parent
Goffi <goffi@goffi.org>
parents:
3726
diff
changeset
|
769 """Return parent of a comment node |
ea6fda69bb9f
plugin XEP-0277: methods to check is a node is a comments node and to get its parent
Goffi <goffi@goffi.org>
parents:
3726
diff
changeset
|
770 |
ea6fda69bb9f
plugin XEP-0277: methods to check is a node is a comments node and to get its parent
Goffi <goffi@goffi.org>
parents:
3726
diff
changeset
|
771 @param item_id: a comment node |
ea6fda69bb9f
plugin XEP-0277: methods to check is a node is a comments node and to get its parent
Goffi <goffi@goffi.org>
parents:
3726
diff
changeset
|
772 """ |
3762
becd7f1aa033
plugin XEP-0277: bridge method `mbIsCommentNode` + methods renaming
Goffi <goffi@goffi.org>
parents:
3761
diff
changeset
|
773 if not self.isCommentNode(item_id): |
3740
ea6fda69bb9f
plugin XEP-0277: methods to check is a node is a comments node and to get its parent
Goffi <goffi@goffi.org>
parents:
3726
diff
changeset
|
774 raise ValueError("This node is not a comment node") |
ea6fda69bb9f
plugin XEP-0277: methods to check is a node is a comments node and to get its parent
Goffi <goffi@goffi.org>
parents:
3726
diff
changeset
|
775 return item_id[len(NS_COMMENT_PREFIX):] |
ea6fda69bb9f
plugin XEP-0277: methods to check is a node is a comments node and to get its parent
Goffi <goffi@goffi.org>
parents:
3726
diff
changeset
|
776 |
1831
68c0dc13d821
plugin blog import, XEP-0277: progress + redirect:
Goffi <goffi@goffi.org>
parents:
1829
diff
changeset
|
777 def getCommentsNode(self, item_id): |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
778 """Generate comment node |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
779 |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
780 @param item_id(unicode): id of the parent item |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
781 @return (unicode): comment node to use |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
782 """ |
3598
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
783 return f"{NS_COMMENT_PREFIX}{item_id}" |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
784 |
1831
68c0dc13d821
plugin blog import, XEP-0277: progress + redirect:
Goffi <goffi@goffi.org>
parents:
1829
diff
changeset
|
785 def getCommentsService(self, client, parent_service=None): |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
786 """Get prefered PubSub service to create comment node |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
787 |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
788 @param pubsub_service(jid.JID, None): PubSub service of the parent item |
2433
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
789 @param return((D)jid.JID, None): PubSub service to use |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
790 """ |
2433
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
791 if parent_service is not None: |
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
792 if parent_service.user: |
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
793 # we are on a PEP |
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
794 if parent_service.host == client.jid.host: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
795 # it's our server, we use already found client.pubsub_service below |
2433
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
796 pass |
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
797 else: |
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
798 # other server, let's try to find a non PEP service there |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
799 d = self.host.findServiceEntity( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
800 client, "pubsub", "service", parent_service |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
801 ) |
2433
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
802 d.addCallback(lambda entity: entity or parent_service) |
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
803 else: |
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
804 # parent is already on a normal Pubsub service, we re-use it |
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
805 return defer.succeed(parent_service) |
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
806 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
807 return defer.succeed( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
808 client.pubsub_service if client.pubsub_service is not None else parent_service |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
809 ) |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
810 |
3740
ea6fda69bb9f
plugin XEP-0277: methods to check is a node is a comments node and to get its parent
Goffi <goffi@goffi.org>
parents:
3726
diff
changeset
|
811 async def _manageComments(self, client, mb_data, service, node, item_id, access=None): |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
812 """Check comments keys in mb_data and create comments node if necessary |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
813 |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
814 if a comments node metadata is set in the mb_data['comments'] list, it is used |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
815 otherwise it is generated (if allow_comments is True). |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
816 @param mb_data(dict): microblog mb_data |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
817 @param service(jid.JID, None): PubSub service of the parent item |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
818 @param node(unicode): node of the parent item |
2227
79d279d1ee88
plugin XEP-0277: comments node access model changes:
Goffi <goffi@goffi.org>
parents:
2218
diff
changeset
|
819 @param item_id(unicode): id of the parent item |
79d279d1ee88
plugin XEP-0277: comments node access model changes:
Goffi <goffi@goffi.org>
parents:
2218
diff
changeset
|
820 @param access(unicode, None): access model |
79d279d1ee88
plugin XEP-0277: comments node access model changes:
Goffi <goffi@goffi.org>
parents:
2218
diff
changeset
|
821 None to use same access model as parent item |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
822 """ |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
823 allow_comments = mb_data.pop("allow_comments", None) |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
824 if allow_comments is None: |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
825 if "comments" in mb_data: |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
826 mb_data["allow_comments"] = True |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
827 else: |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
828 # no comments set or requested, nothing to do |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
829 return |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
830 elif allow_comments == False: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
831 if "comments" in mb_data: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
832 log.warning( |
3028 | 833 "comments are not allowed but there is already a comments node, " |
834 "it may be lost: {uri}".format( | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
835 uri=mb_data["comments"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
836 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
837 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
838 del mb_data["comments"] |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
839 return |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
840 |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
841 # we have usually a single comment node, but the spec allow several, so we need to |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
842 # handle this in a list |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
843 if len(mb_data.setdefault('comments', [])) == 0: |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
844 # we need at least one comment node |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
845 comments_data = {} |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
846 mb_data['comments'].append({}) |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
847 |
2227
79d279d1ee88
plugin XEP-0277: comments node access model changes:
Goffi <goffi@goffi.org>
parents:
2218
diff
changeset
|
848 if access is None: |
79d279d1ee88
plugin XEP-0277: comments node access model changes:
Goffi <goffi@goffi.org>
parents:
2218
diff
changeset
|
849 # TODO: cache access models per service/node |
3740
ea6fda69bb9f
plugin XEP-0277: methods to check is a node is a comments node and to get its parent
Goffi <goffi@goffi.org>
parents:
3726
diff
changeset
|
850 parent_node_config = await self._p.getConfiguration(client, service, node) |
2227
79d279d1ee88
plugin XEP-0277: comments node access model changes:
Goffi <goffi@goffi.org>
parents:
2218
diff
changeset
|
851 access = parent_node_config.get(self._p.OPT_ACCESS_MODEL, self._p.ACCESS_OPEN) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
852 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
853 options = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
854 self._p.OPT_ACCESS_MODEL: access, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
855 self._p.OPT_PERSIST_ITEMS: 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
856 self._p.OPT_MAX_ITEMS: -1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
857 self._p.OPT_DELIVER_PAYLOADS: 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
858 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
859 # FIXME: would it make sense to restrict publish model to subscribers? |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
860 self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
861 } |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
862 |
1661
96ee986dab3c
plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents:
1656
diff
changeset
|
863 # if other plugins need to change the options |
3761
e0ff2f277e13
plugin XEP-0277: fix `await` trigger incorrectly used on a sync trigger
Goffi <goffi@goffi.org>
parents:
3740
diff
changeset
|
864 self.host.trigger.point("XEP-0277_comments", client, mb_data, options) |
1661
96ee986dab3c
plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents:
1656
diff
changeset
|
865 |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
866 for comments_data in mb_data['comments']: |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
867 uri = comments_data.get('uri') |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
868 comments_node = comments_data.get('node') |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
869 try: |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
870 comments_service = jid.JID(comments_data["service"]) |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
871 except KeyError: |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
872 comments_service = None |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
873 |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
874 if uri: |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
875 uri_service, uri_node = self.parseCommentUrl(uri) |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
876 if ((comments_node is not None and comments_node!=uri_node) |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
877 or (comments_service is not None and comments_service!=uri_service)): |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
878 raise ValueError( |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
879 f"Incoherence between comments URI ({uri}) and comments_service " |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
880 f"({comments_service}) or comments_node ({comments_node})") |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
881 comments_data['service'] = comments_service = uri_service |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
882 comments_data['node'] = comments_node = uri_node |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
883 else: |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
884 if not comments_node: |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
885 comments_node = self.getCommentsNode(item_id) |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
886 comments_data['node'] = comments_node |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
887 if comments_service is None: |
3740
ea6fda69bb9f
plugin XEP-0277: methods to check is a node is a comments node and to get its parent
Goffi <goffi@goffi.org>
parents:
3726
diff
changeset
|
888 comments_service = await self.getCommentsService(client, service) |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
889 if comments_service is None: |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
890 comments_service = client.jid.userhostJID() |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
891 comments_data['service'] = comments_service |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
892 |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
893 comments_data['uri'] = xmpp_uri.buildXMPPUri( |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
894 "pubsub", |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
895 path=comments_service.full(), |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
896 node=comments_node, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
897 ) |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
898 |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
899 try: |
3740
ea6fda69bb9f
plugin XEP-0277: methods to check is a node is a comments node and to get its parent
Goffi <goffi@goffi.org>
parents:
3726
diff
changeset
|
900 await self._p.createNode(client, comments_service, comments_node, options) |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
901 except error.StanzaError as e: |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
902 if e.condition == "conflict": |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
903 log.info( |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
904 "node {} already exists on service {}".format( |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
905 comments_node, comments_service |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
906 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
907 ) |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
908 else: |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
909 raise e |
1711
e5b569d0c2e7
plugin XEP-0277: don't try to create a new comments node if it already exists
souliane <souliane@mailoo.org>
parents:
1709
diff
changeset
|
910 else: |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
911 if access == self._p.ACCESS_WHITELIST: |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
912 # for whitelist access we need to copy affiliations from parent item |
3740
ea6fda69bb9f
plugin XEP-0277: methods to check is a node is a comments node and to get its parent
Goffi <goffi@goffi.org>
parents:
3726
diff
changeset
|
913 comments_affiliations = await self._p.getNodeAffiliations( |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
914 client, service, node |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
915 ) |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
916 # …except for "member", that we transform to publisher |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
917 # because we wants members to be able to write to comments |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
918 for jid_, affiliation in list(comments_affiliations.items()): |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
919 if affiliation == "member": |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
920 comments_affiliations[jid_] == "publisher" |
2286
330f8d4e2ad4
plugin XEP-0277: change affiliations for comments + fixes:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
921 |
3740
ea6fda69bb9f
plugin XEP-0277: methods to check is a node is a comments node and to get its parent
Goffi <goffi@goffi.org>
parents:
3726
diff
changeset
|
922 await self._p.setNodeAffiliations( |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
923 client, comments_service, comments_node, comments_affiliations |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
924 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
925 |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
926 def friendlyId(self, data): |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
927 """Generate a user friendly id from title or content""" |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
928 # TODO: rich content should be converted to plain text |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
929 id_base = regex.urlFriendlyText( |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
930 data.get('title') |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
931 or data.get('title_rich') |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
932 or data.get('content') |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
933 or data.get('content_rich') |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
934 or '' |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
935 ) |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
936 return f"{id_base}-{token_urlsafe(3)}" |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
937 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
938 def _mbSend(self, service, node, data, profile_key): |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
939 service = jid.JID(service) if service else None |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
940 node = node if node else NS_MICROBLOG |
2227
79d279d1ee88
plugin XEP-0277: comments node access model changes:
Goffi <goffi@goffi.org>
parents:
2218
diff
changeset
|
941 client = self.host.getClient(profile_key) |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
942 data = data_format.deserialise(data) |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
943 return defer.ensureDeferred(self.send(client, data, service, node)) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
944 |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
945 async def send( |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
946 self, |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
947 client: SatXMPPEntity, |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
948 data: dict, |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
949 service: Optional[jid.JID] = None, |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
950 node: Optional[str] = NS_MICROBLOG |
3848
e9c380ef41c8
plugin XEP-0277: return ID of published item in `send` and bridge's `mbSend`
Goffi <goffi@goffi.org>
parents:
3840
diff
changeset
|
951 ) -> Optional[str]: |
306
169e7386650a
plugin xep-0277: bridge data is now converted in pubsub item in a separate function
Goffi <goffi@goffi.org>
parents:
304
diff
changeset
|
952 """Send XEP-0277's microblog data |
1419
be2df1ddea8e
plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
953 |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
954 @param data: microblog data (must include at least a "content" or a "title" key). |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
955 see http://wiki.goffi.org/wiki/Bridge_API_-_Microblogging/en for details |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
956 @param service: PubSub service where the microblog must be published |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
957 None to publish on profile's PEP |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
958 @param node: PubSub node to use (defaut to microblog NS) |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
959 None is equivalend as using default value |
3848
e9c380ef41c8
plugin XEP-0277: return ID of published item in `send` and bridge's `mbSend`
Goffi <goffi@goffi.org>
parents:
3840
diff
changeset
|
960 @return: ID of the published item |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
961 """ |
1699 | 962 # TODO: check that all data keys are used, this would avoid sending publicly a private message |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
963 # by accident (e.g. if group plugin is not loaded, and "group*" key are not used) |
3861
37a1193d90db
plugin XEP-0277: add a trigger to `send` method:
Goffi <goffi@goffi.org>
parents:
3848
diff
changeset
|
964 if service is None: |
37a1193d90db
plugin XEP-0277: add a trigger to `send` method:
Goffi <goffi@goffi.org>
parents:
3848
diff
changeset
|
965 service = client.jid.userhostJID() |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
966 if node is None: |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
967 node = NS_MICROBLOG |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
968 |
3502
6132d363f0e9
plugin XEP-0277: user friendly ID:
Goffi <goffi@goffi.org>
parents:
3493
diff
changeset
|
969 item_id = data.get("id") |
6132d363f0e9
plugin XEP-0277: user friendly ID:
Goffi <goffi@goffi.org>
parents:
3493
diff
changeset
|
970 if item_id is None: |
6132d363f0e9
plugin XEP-0277: user friendly ID:
Goffi <goffi@goffi.org>
parents:
3493
diff
changeset
|
971 if data.get("user_friendly_id", True): |
6132d363f0e9
plugin XEP-0277: user friendly ID:
Goffi <goffi@goffi.org>
parents:
3493
diff
changeset
|
972 item_id = self.friendlyId(data) |
6132d363f0e9
plugin XEP-0277: user friendly ID:
Goffi <goffi@goffi.org>
parents:
3493
diff
changeset
|
973 else: |
6132d363f0e9
plugin XEP-0277: user friendly ID:
Goffi <goffi@goffi.org>
parents:
3493
diff
changeset
|
974 item_id = str(shortuuid.uuid()) |
2227
79d279d1ee88
plugin XEP-0277: comments node access model changes:
Goffi <goffi@goffi.org>
parents:
2218
diff
changeset
|
975 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
976 try: |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
977 await self._manageComments(client, data, service, node, item_id, access=None) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
978 except error.StanzaError: |
3028 | 979 log.warning("Can't create comments node for item {}".format(item_id)) |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
980 item = await self.data2entry(client, data, item_id, service, node) |
3861
37a1193d90db
plugin XEP-0277: add a trigger to `send` method:
Goffi <goffi@goffi.org>
parents:
3848
diff
changeset
|
981 |
37a1193d90db
plugin XEP-0277: add a trigger to `send` method:
Goffi <goffi@goffi.org>
parents:
3848
diff
changeset
|
982 if not await self.host.trigger.asyncPoint( |
37a1193d90db
plugin XEP-0277: add a trigger to `send` method:
Goffi <goffi@goffi.org>
parents:
3848
diff
changeset
|
983 "XEP-0277_send", client, service, node, item, data |
37a1193d90db
plugin XEP-0277: add a trigger to `send` method:
Goffi <goffi@goffi.org>
parents:
3848
diff
changeset
|
984 ): |
37a1193d90db
plugin XEP-0277: add a trigger to `send` method:
Goffi <goffi@goffi.org>
parents:
3848
diff
changeset
|
985 return None |
37a1193d90db
plugin XEP-0277: add a trigger to `send` method:
Goffi <goffi@goffi.org>
parents:
3848
diff
changeset
|
986 |
3848
e9c380ef41c8
plugin XEP-0277: return ID of published item in `send` and bridge's `mbSend`
Goffi <goffi@goffi.org>
parents:
3840
diff
changeset
|
987 await self._p.publish(client, service, node, [item]) |
e9c380ef41c8
plugin XEP-0277: return ID of published item in `send` and bridge's `mbSend`
Goffi <goffi@goffi.org>
parents:
3840
diff
changeset
|
988 return item_id |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
989 |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
990 def _mbRepeat( |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
991 self, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
992 service_s: str, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
993 node: str, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
994 item: str, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
995 extra_s: str, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
996 profile_key: str |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
997 ) -> defer.Deferred: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
998 service = jid.JID(service_s) if service_s else None |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
999 node = node if node else NS_MICROBLOG |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1000 client = self.host.getClient(profile_key) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1001 extra = data_format.deserialise(extra_s) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1002 d = defer.ensureDeferred( |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1003 self.repeat(client, item, service, node, extra) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1004 ) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1005 # [repeat] can return None, and we always need a str |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1006 d.addCallback(lambda ret: ret or "") |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1007 return d |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1008 |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1009 async def repeat( |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1010 self, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1011 client: SatXMPPEntity, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1012 item: str, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1013 service: Optional[jid.JID] = None, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1014 node: str = NS_MICROBLOG, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1015 extra: Optional[dict] = None, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1016 ) -> Optional[str]: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1017 """Re-publish a post from somewhere else |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1018 |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1019 This is a feature often name "share" or "boost", it is generally used to make a |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1020 publication more visible by sharing it with our own audience |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1021 """ |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1022 if service is None: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1023 service = client.jid.userhostJID() |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1024 |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1025 # we first get the post to repeat |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1026 items, __ = await self._p.getItems( |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1027 client, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1028 service, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1029 node, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1030 item_ids = [item] |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1031 ) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1032 if not items: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1033 raise exceptions.NotFound( |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1034 f"no item found at node {node!r} on {service} with ID {item!r}" |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1035 ) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1036 item_elt = items[0] |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1037 try: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1038 entry_elt = next(item_elt.elements(NS_ATOM, "entry")) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1039 except StopIteration: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1040 raise exceptions.DataError( |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1041 "post to repeat is not a XEP-0277 blog item" |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1042 ) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1043 |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1044 # we want to be sure that we have an author element |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1045 try: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1046 author_elt = next(entry_elt.elements(NS_ATOM, "author")) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1047 except StopIteration: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1048 author_elt = entry_elt.addElement("author") |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1049 |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1050 try: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1051 next(author_elt.elements(NS_ATOM, "name")) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1052 except StopIteration: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1053 author_elt.addElement("name", content=service.user) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1054 |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1055 try: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1056 next(author_elt.elements(NS_ATOM, "uri")) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1057 except StopIteration: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1058 entry_elt.addElement( |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1059 "uri", content=xmpp_uri.buildXMPPUri(None, path=service.full()) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1060 ) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1061 |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1062 # we add the link indicating that it's a repeated post |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1063 link_elt = entry_elt.addElement("link") |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1064 link_elt["rel"] = "via" |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1065 link_elt["href"] = xmpp_uri.buildXMPPUri( |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1066 "pubsub", path=service.full(), node=node, item=item |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1067 ) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1068 |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1069 return await self._p.sendItem( |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1070 client, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1071 client.jid.userhostJID(), |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1072 NS_MICROBLOG, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1073 entry_elt |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1074 ) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1075 |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1076 def _mbPreview(self, service, node, data, profile_key): |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1077 service = jid.JID(service) if service else None |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1078 node = node if node else NS_MICROBLOG |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1079 client = self.host.getClient(profile_key) |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1080 data = data_format.deserialise(data) |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1081 d = defer.ensureDeferred(self.preview(client, data, service, node)) |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1082 d.addCallback(data_format.serialise) |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1083 return d |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1084 |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1085 async def preview( |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1086 self, |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1087 client: SatXMPPEntity, |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1088 data: dict, |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1089 service: Optional[jid.JID] = None, |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1090 node: Optional[str] = NS_MICROBLOG |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1091 ) -> dict: |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1092 """Preview microblog data without publishing them |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1093 |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1094 params are the same as for [send] |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1095 @return: microblog data as would be retrieved from published item |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1096 """ |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1097 if node is None: |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1098 node = NS_MICROBLOG |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1099 |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1100 item_id = data.get("id", "") |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1101 |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1102 # we have to serialise then deserialise to be sure that all triggers are called |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1103 item_elt = await self.data2entry(client, data, item_id, service, node) |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1104 item_elt.uri = pubsub.NS_PUBSUB |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1105 return await self.item2mbdata(client, item_elt, service, node) |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1106 |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1107 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1108 ## retract ## |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1109 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1110 def _mbRetract(self, service_jid_s, nodeIdentifier, itemIdentifier, profile_key): |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1111 """Call self._p._retractItem, but use default node if node is empty""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1112 return self._p._retractItem( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1113 service_jid_s, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1114 nodeIdentifier or NS_MICROBLOG, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1115 itemIdentifier, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1116 True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1117 profile_key, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1118 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1119 |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
1120 ## get ## |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
1121 |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1122 def _mbGetSerialise(self, data): |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1123 items, metadata = data |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1124 metadata['items'] = items |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1125 return data_format.serialise(metadata) |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1126 |
3586
5f65f4e9f8cb
plugin XEP-0060: getItems extra is now serialised dict
Goffi <goffi@goffi.org>
parents:
3584
diff
changeset
|
1127 def _mbGet(self, service="", node="", max_items=10, item_ids=None, extra="", |
2760
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1128 profile_key=C.PROF_KEY_NONE): |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1129 """ |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1130 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit |
1513
955221487a3e
plugin XEP-0277, quick_frontend: rename mbGetLast to mbGet and add it the parameter "item_ids"
souliane <souliane@mailoo.org>
parents:
1511
diff
changeset
|
1131 @param item_ids (list[unicode]): list of item IDs |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1132 """ |
2286
330f8d4e2ad4
plugin XEP-0277: change affiliations for comments + fixes:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
1133 client = self.host.getClient(profile_key) |
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
|
1134 service = jid.JID(service) if service else None |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1135 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
|
1136 extra = self._p.parseExtra(data_format.deserialise(extra)) |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1137 d = defer.ensureDeferred( |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1138 self.mbGet(client, service, node or None, max_items, item_ids, |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1139 extra.rsm_request, extra.extra) |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1140 ) |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1141 d.addCallback(self._mbGetSerialise) |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1142 return d |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
1143 |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1144 async def mbGet(self, client, service=None, node=None, max_items=10, item_ids=None, |
2760
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1145 rsm_request=None, extra=None): |
1516
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
1146 """Get some microblogs |
1419
be2df1ddea8e
plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1147 |
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
|
1148 @param service(jid.JID, None): jid of the publisher |
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
|
1149 None to get profile's PEP |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1150 @param node(unicode, None): node to get (or microblog node if None) |
2286
330f8d4e2ad4
plugin XEP-0277: change affiliations for comments + fixes:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
1151 @param max_items(int): maximum number of item to get, None for no limit |
3591
d830c11eeef3
plugin XEP-0277: ignore `max_items` if `rsm_request` is set
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
1152 ignored if rsm_request is set |
1513
955221487a3e
plugin XEP-0277, quick_frontend: rename mbGetLast to mbGet and add it the parameter "item_ids"
souliane <souliane@mailoo.org>
parents:
1511
diff
changeset
|
1153 @param item_ids (list[unicode]): list of item IDs |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1154 @param rsm_request (rsm.RSMRequest): RSM request data |
1516
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
1155 @param extra (dict): extra data |
1268
bb30bf3ae932
plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents:
1233
diff
changeset
|
1156 |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
1157 @return: a deferred couple with the list of items and metadatas. |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1158 """ |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1159 if node is None: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1160 node = NS_MICROBLOG |
3591
d830c11eeef3
plugin XEP-0277: ignore `max_items` if `rsm_request` is set
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
1161 if rsm_request: |
d830c11eeef3
plugin XEP-0277: ignore `max_items` if `rsm_request` is set
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
1162 max_items = None |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1163 items_data = await self._p.getItems( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1164 client, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1165 service, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1166 node, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1167 max_items=max_items, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1168 item_ids=item_ids, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1169 rsm_request=rsm_request, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1170 extra=extra, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1171 ) |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1172 mb_data = await self._p.transItemsDataD( |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1173 items_data, partial(self.item2mbdata, client, service=service, node=node)) |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1174 return mb_data |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1175 |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1176 def _mbRename(self, service, node, item_id, new_id, profile_key): |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1177 return defer.ensureDeferred(self.mbRename( |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1178 self.host.getClient(profile_key), |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1179 jid.JID(service) if service else None, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1180 node or None, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1181 item_id, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1182 new_id |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1183 )) |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1184 |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1185 async def mbRename( |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1186 self, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1187 client: SatXMPPEntity, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1188 service: Optional[jid.JID], |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1189 node: Optional[str], |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1190 item_id: str, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1191 new_id: str |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1192 ) -> None: |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1193 if not node: |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1194 node = NS_MICROBLOG |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1195 await self._p.renameItem(client, service, node, item_id, new_id) |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1196 |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
1197 def parseCommentUrl(self, node_url): |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
1198 """Parse a XMPP URI |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
1199 |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
1200 Determine the fields comments_service and comments_node of a microblog data |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
1201 from the href attribute of an entry's link element. For example this input: |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
2148
diff
changeset
|
1202 xmpp:sat-pubsub.example.net?;node=urn%3Axmpp%3Acomments%3A_af43b363-3259-4b2a-ba4c-1bc33aa87634__urn%3Axmpp%3Agroupblog%3Asomebody%40example.net |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
2148
diff
changeset
|
1203 will return(JID(u'sat-pubsub.example.net'), 'urn:xmpp:comments:_af43b363-3259-4b2a-ba4c-1bc33aa87634__urn:xmpp:groupblog:somebody@example.net') |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
2148
diff
changeset
|
1204 @return (tuple[jid.JID, unicode]): service and node |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
1205 """ |
3643
30196b9a2b4c
plugin XEP-0277: use `common.uri` to parse comment URIs
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1206 try: |
30196b9a2b4c
plugin XEP-0277: use `common.uri` to parse comment URIs
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1207 parsed_url = xmpp_uri.parseXMPPUri(node_url) |
30196b9a2b4c
plugin XEP-0277: use `common.uri` to parse comment URIs
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1208 service = jid.JID(parsed_url["path"]) |
30196b9a2b4c
plugin XEP-0277: use `common.uri` to parse comment URIs
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1209 node = parsed_url["node"] |
30196b9a2b4c
plugin XEP-0277: use `common.uri` to parse comment URIs
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1210 except Exception as e: |
30196b9a2b4c
plugin XEP-0277: use `common.uri` to parse comment URIs
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1211 raise exceptions.DataError(f"Invalid comments link: {e}") |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
1212 |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
1213 return (service, node) |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
1214 |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
1215 ## configure ## |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
1216 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1217 def mbSetAccess(self, access="presence", profile_key=C.PROF_KEY_NONE): |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1218 """Create a microblog node on PEP with given access |
1419
be2df1ddea8e
plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1219 |
304 | 1220 If the node already exists, it change options |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1221 @param access: Node access model, according to xep-0060 #4.5 |
2218
6a2fa651d7fa
plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents:
2160
diff
changeset
|
1222 @param profile_key: profile key |
6a2fa651d7fa
plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents:
2160
diff
changeset
|
1223 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1224 # FIXME: check if this mehtod is need, deprecate it if not |
2218
6a2fa651d7fa
plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents:
2160
diff
changeset
|
1225 client = self.host.getClient(profile_key) |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1226 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1227 _options = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1228 self._p.OPT_ACCESS_MODEL: access, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1229 self._p.OPT_PERSIST_ITEMS: 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1230 self._p.OPT_MAX_ITEMS: -1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1231 self._p.OPT_DELIVER_PAYLOADS: 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1232 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1233 } |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1234 |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1235 def cb(result): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1236 # Node is created with right permission |
3028 | 1237 log.debug(_("Microblog node has now access %s") % access) |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1238 |
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1239 def fatal_err(s_error): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1240 # Something went wrong |
3028 | 1241 log.error(_("Can't set microblog access")) |
468
c97640c90a94
D-Bus Bridge: use inspection to name attribute + fix asynchronous calls for dynamically added method, it now use deferred return value instead of callback/errback attributes
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
1242 raise NodeAccessChangeException() |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1243 |
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1244 def err_cb(s_error): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1245 # If the node already exists, the condition is "conflict", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1246 # else we have an unmanaged error |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1247 if s_error.value.condition == "conflict": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1248 # d = self.host.plugins["XEP-0060"].deleteNode(client, client.jid.userhostJID(), NS_MICROBLOG) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1249 # d.addCallback(lambda x: create_node().addCallback(cb).addErrback(fatal_err)) |
304 | 1250 change_node_options().addCallback(cb).addErrback(fatal_err) |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1251 else: |
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1252 fatal_err(s_error) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1253 |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1254 def create_node(): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1255 return self._p.createNode( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1256 client, client.jid.userhostJID(), NS_MICROBLOG, _options |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1257 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1258 |
304 | 1259 def change_node_options(): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1260 return self._p.setOptions( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1261 client.jid.userhostJID(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1262 NS_MICROBLOG, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1263 client.jid.userhostJID(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1264 _options, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1265 profile_key=profile_key, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1266 ) |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1267 |
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1268 create_node().addCallback(cb).addErrback(err_cb) |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1269 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1270 ## methods to manage several stanzas/jids at once ## |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1271 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1272 # common |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1273 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1274 def _getClientAndNodeData(self, publishers_type, publishers, profile_key): |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1275 """Helper method to construct node_data from publishers_type/publishers |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1276 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1277 @param publishers_type: type of the list of publishers, one of: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1278 C.ALL: get all jids from roster, publishers is not used |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1279 C.GROUP: get jids from groups |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1280 C.JID: use publishers directly as list of jids |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1281 @param publishers: list of publishers, according to "publishers_type" (None, |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1282 list of groups or list of jids) |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1283 @param profile_key: %(doc_profile_key)s |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1284 """ |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1285 client = self.host.getClient(profile_key) |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1286 if publishers_type == C.JID: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1287 jids_set = set(publishers) |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1288 else: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1289 jids_set = client.roster.getJidsSet(publishers_type, publishers) |
1728
0eaa1a409dfb
plugin XEP-0277, EXTRA-PEP: get massive blogs from all the roster also retrieve items from a special JIDs list defined in EXTRA-PEP
souliane <souliane@mailoo.org>
parents:
1712
diff
changeset
|
1290 if publishers_type == C.ALL: |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1291 try: |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1292 # display messages from salut-a-toi@libervia.org or other PEP services |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1293 services = self.host.plugins["EXTRA-PEP"].getFollowedEntities( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1294 profile_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1295 ) |
1728
0eaa1a409dfb
plugin XEP-0277, EXTRA-PEP: get massive blogs from all the roster also retrieve items from a special JIDs list defined in EXTRA-PEP
souliane <souliane@mailoo.org>
parents:
1712
diff
changeset
|
1296 except KeyError: |
1741
cc31dd72526d
plugin misc_extra_pep: use a user parameter (jids_list) instead of a general configuration value
souliane <souliane@mailoo.org>
parents:
1734
diff
changeset
|
1297 pass # plugin is not loaded |
1728
0eaa1a409dfb
plugin XEP-0277, EXTRA-PEP: get massive blogs from all the roster also retrieve items from a special JIDs list defined in EXTRA-PEP
souliane <souliane@mailoo.org>
parents:
1712
diff
changeset
|
1298 else: |
1741
cc31dd72526d
plugin misc_extra_pep: use a user parameter (jids_list) instead of a general configuration value
souliane <souliane@mailoo.org>
parents:
1734
diff
changeset
|
1299 if services: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1300 log.debug( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1301 "Extra PEP followed entities: %s" |
3028 | 1302 % ", ".join([str(service) for service in services]) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1303 ) |
1741
cc31dd72526d
plugin misc_extra_pep: use a user parameter (jids_list) instead of a general configuration value
souliane <souliane@mailoo.org>
parents:
1734
diff
changeset
|
1304 jids_set.update(services) |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1305 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1306 node_data = [] |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1307 for jid_ in jids_set: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1308 node_data.append((jid_, NS_MICROBLOG)) |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1309 return client, node_data |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1310 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1311 def _checkPublishers(self, publishers_type, publishers): |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1312 """Helper method to deserialise publishers coming from bridge |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1313 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1314 publishers_type(unicode): type of the list of publishers, one of: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1315 publishers: list of publishers according to type |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1316 @return: deserialised (publishers_type, publishers) tuple |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1317 """ |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1318 if publishers_type == C.ALL: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1319 if publishers: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1320 raise failure.Failure( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1321 ValueError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1322 "Can't use publishers with {} type".format(publishers_type) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1323 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1324 ) |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1325 else: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1326 publishers = None |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1327 elif publishers_type == C.JID: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1328 publishers[:] = [jid.JID(publisher) for publisher in publishers] |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1329 return publishers_type, publishers |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1330 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1331 # subscribe # |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1332 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1333 def _mbSubscribeToMany(self, publishers_type, publishers, profile_key): |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1334 """ |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1335 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1336 @return (str): session id: Use pubsub.getSubscribeRTResult to get the results |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1337 """ |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1338 publishers_type, publishers = self._checkPublishers(publishers_type, publishers) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1339 return self.mbSubscribeToMany(publishers_type, publishers, profile_key) |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1340 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1341 def mbSubscribeToMany(self, publishers_type, publishers, profile_key): |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1342 """Subscribe microblogs for a list of groups or jids |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1343 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1344 @param publishers_type: type of the list of publishers, one of: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1345 C.ALL: get all jids from roster, publishers is not used |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1346 C.GROUP: get jids from groups |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1347 C.JID: use publishers directly as list of jids |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1348 @param publishers: list of publishers, according to "publishers_type" (None, list |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1349 of groups or list of jids) |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1350 @param profile: %(doc_profile)s |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1351 @return (str): session id |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1352 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1353 client, node_data = self._getClientAndNodeData( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1354 publishers_type, publishers, profile_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1355 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1356 return self._p.subscribeToMany( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1357 node_data, client.jid.userhostJID(), profile_key=profile_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1358 ) |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1359 |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1360 # get # |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1361 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1362 def _mbGetFromManyRTResult(self, session_id, profile_key=C.PROF_KEY_DEFAULT): |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1363 """Get real-time results for mbGetFromMany session |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1364 |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1365 @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
|
1366 @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
|
1367 - 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
|
1368 - 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
|
1369 - service (unicode): pubsub service |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1370 - node (unicode): pubsub node |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1371 - failure (unicode): empty string in case of success, error message else |
1513
955221487a3e
plugin XEP-0277, quick_frontend: rename mbGetLast to mbGet and add it the parameter "item_ids"
souliane <souliane@mailoo.org>
parents:
1511
diff
changeset
|
1372 - items_data(list): data as returned by [mbGet] |
955221487a3e
plugin XEP-0277, quick_frontend: rename mbGetLast to mbGet and add it the parameter "item_ids"
souliane <souliane@mailoo.org>
parents:
1511
diff
changeset
|
1373 - items_metadata(dict): metadata as returned by [mbGet] |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1374 @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
|
1375 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1376 |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1377 client = self.host.getClient(profile_key) |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1378 |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1379 def onSuccess(items_data): |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1380 """convert items elements to list of microblog data in items_data""" |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1381 d = self._p.transItemsDataD( |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1382 items_data, |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1383 # FIXME: service and node should be used here |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1384 partial(self.item2mbdata, client), |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1385 serialise=True |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1386 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1387 d.addCallback(lambda serialised: ("", serialised)) |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1388 return d |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1389 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1390 d = self._p.getRTResults( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1391 session_id, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1392 on_success=onSuccess, |
3028 | 1393 on_error=lambda failure: (str(failure.value), ([], {})), |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1394 profile=client.profile, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1395 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1396 d.addCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1397 lambda ret: ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1398 ret[0], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1399 [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1400 (service.full(), node, failure, items, metadata) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1401 for (service, node), (success, (failure, (items, metadata))) in ret[ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1402 1 |
3028 | 1403 ].items() |
2624
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 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1406 ) |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1407 return d |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1408 |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1409 def _mbGetFromMany(self, publishers_type, publishers, max_items=10, extra_dict=None, |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1410 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
|
1411 """ |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1412 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1413 """ |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1414 max_items = None if max_items == C.NO_LIMIT else max_items |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1415 publishers_type, publishers = self._checkPublishers(publishers_type, publishers) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1416 extra = self._p.parseExtra(extra_dict) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1417 return self.mbGetFromMany( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1418 publishers_type, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1419 publishers, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1420 max_items, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1421 extra.rsm_request, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1422 extra.extra, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1423 profile_key, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1424 ) |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1425 |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1426 def mbGetFromMany(self, publishers_type, publishers, max_items=None, rsm_request=None, |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1427 extra=None, 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
|
1428 """Get the published microblogs for a list of groups or jids |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1429 |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1430 @param publishers_type (str): type of the list of publishers (one of "GROUP" or |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1431 "JID" or "ALL") |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1432 @param publishers (list): list of publishers, according to publishers_type (list |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1433 of groups or list of jids) |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1434 @param max_items (int): optional limit on the number of retrieved items. |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1435 @param rsm_request (rsm.RSMRequest): RSM request data, common to all publishers |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1436 @param extra (dict): Extra data |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1437 @param profile_key: profile key |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1438 @return (str): RT Deferred session id |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1439 """ |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1440 # XXX: extra is unused here so far |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1441 client, node_data = self._getClientAndNodeData( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1442 publishers_type, publishers, profile_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1443 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1444 return self._p.getFromMany( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1445 node_data, max_items, rsm_request, profile_key=profile_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1446 ) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1447 |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1448 # comments # |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1449 |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1450 def _mbGetFromManyWithCommentsRTResultSerialise(self, data): |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1451 """Serialisation of result |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1452 |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1453 This is probably the longest method name of whole SàT ecosystem ^^ |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1454 @param data(dict): data as received by rt_sessions |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1455 @return (tuple): see [_mbGetFromManyWithCommentsRTResult] |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1456 """ |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1457 ret = [] |
3028 | 1458 data_iter = iter(data[1].items()) |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1459 for (service, node), (success, (failure_, (items_data, metadata))) in data_iter: |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1460 items = [] |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1461 for item, item_metadata in items_data: |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1462 item = data_format.serialise(item) |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1463 items.append((item, item_metadata)) |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1464 ret.append(( |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1465 service.full(), |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1466 node, |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1467 failure_, |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1468 items, |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1469 metadata)) |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1470 |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1471 return data[0], ret |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1472 |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1473 def _mbGetFromManyWithCommentsRTResult(self, session_id, |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1474 profile_key=C.PROF_KEY_DEFAULT): |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1475 """Get real-time results for [mbGetFromManyWithComments] session |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1476 |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1477 @param session_id: id of the real-time deferred session |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1478 @param return (tuple): (remaining, results) where: |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1479 - remaining is the number of still expected results |
1511
83f71763e1a7
plugin XEP-0277: clarify a docstring for one complex method argument
souliane <souliane@mailoo.org>
parents:
1459
diff
changeset
|
1480 - results is a list of 5-tuple with |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1481 - service (unicode): pubsub service |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1482 - node (unicode): pubsub node |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1483 - failure (unicode): empty string in case of success, error message else |
1511
83f71763e1a7
plugin XEP-0277: clarify a docstring for one complex method argument
souliane <souliane@mailoo.org>
parents:
1459
diff
changeset
|
1484 - items(list[tuple(dict, list)]): list of 2-tuple with |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1485 - item(dict): item microblog data |
1511
83f71763e1a7
plugin XEP-0277: clarify a docstring for one complex method argument
souliane <souliane@mailoo.org>
parents:
1459
diff
changeset
|
1486 - comments_list(list[tuple]): list of 5-tuple with |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1487 - service (unicode): pubsub service where the comments node is |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1488 - node (unicode): comments node |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1489 - failure (unicode): empty in case of success, else error message |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1490 - comments(list[dict]): list of microblog data |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1491 - comments_metadata(dict): metadata of the comment node |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1492 - metadata(dict): original node metadata |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1493 @param profile_key: %(doc_profile_key)s |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1494 """ |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1495 profile = self.host.getClient(profile_key).profile |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1496 d = self.rt_sessions.getResults(session_id, profile=profile) |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1497 d.addCallback(self._mbGetFromManyWithCommentsRTResultSerialise) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1498 return d |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1499 |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1500 def _mbGetFromManyWithComments(self, publishers_type, publishers, max_items=10, |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1501 max_comments=C.NO_LIMIT, extra_dict=None, |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1502 extra_comments_dict=None, profile_key=C.PROF_KEY_NONE): |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1503 """ |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1504 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1505 @param max_comments(int): maximum number of comments to get, C.NO_LIMIT for no |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1506 limit |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1507 """ |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1508 max_items = None if max_items == C.NO_LIMIT else max_items |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1509 max_comments = None if max_comments == C.NO_LIMIT else max_comments |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1510 publishers_type, publishers = self._checkPublishers(publishers_type, publishers) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1511 extra = self._p.parseExtra(extra_dict) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1512 extra_comments = self._p.parseExtra(extra_comments_dict) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1513 return self.mbGetFromManyWithComments( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1514 publishers_type, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1515 publishers, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1516 max_items, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1517 max_comments or None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1518 extra.rsm_request, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1519 extra.extra, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1520 extra_comments.rsm_request, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1521 extra_comments.extra, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1522 profile_key, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1523 ) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1524 |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1525 def mbGetFromManyWithComments(self, publishers_type, publishers, max_items=None, |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1526 max_comments=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:
2780
diff
changeset
|
1527 rsm_comments=None, extra_comments=None, |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1528 profile_key=C.PROF_KEY_NONE): |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1529 """Helper method to get the microblogs and their comments in one shot |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1530 |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1531 @param publishers_type (str): type of the list of publishers (one of "GROUP" or |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1532 "JID" or "ALL") |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1533 @param publishers (list): list of publishers, according to publishers_type (list |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1534 of groups or list of jids) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1535 @param max_items (int): optional limit on the number of retrieved items. |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1536 @param max_comments (int): maximum number of comments to retrieve |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1537 @param rsm_request (rsm.RSMRequest): RSM request for initial items only |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1538 @param extra (dict): extra configuration for initial items only |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1539 @param rsm_comments (rsm.RSMRequest): RSM request for comments only |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1540 @param extra_comments (dict): extra configuration for comments only |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1541 @param profile_key: profile key |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1542 @return (str): RT Deferred session id |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1543 """ |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1544 # XXX: this method seems complicated because it do a couple of treatments |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1545 # to serialise and associate the data, but it make life in frontends side |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1546 # a lot easier |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1547 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1548 client, node_data = self._getClientAndNodeData( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1549 publishers_type, publishers, profile_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1550 ) |
2360
72cbb6478f97
plugin XEP-0060: use client instead of profile_key in getItems
Goffi <goffi@goffi.org>
parents:
2341
diff
changeset
|
1551 |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1552 def getComments(items_data): |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1553 """Retrieve comments and add them to the items_data |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1554 |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1555 @param items_data: serialised items data |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1556 @return (defer.Deferred): list of items where each item is associated |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1557 with a list of comments data (service, node, list of items, metadata) |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1558 """ |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1559 items, metadata = items_data |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1560 items_dlist = [] # deferred list for items |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1561 for item in items: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1562 dlist = [] # deferred list for comments |
3028 | 1563 for key, value in item.items(): |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1564 # we look for comments |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1565 if key.startswith("comments") and key.endswith("_service"): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1566 prefix = key[: key.find("_")] |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1567 service_s = value |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1568 service = jid.JID(service_s) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1569 node = item["{}{}".format(prefix, "_node")] |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1570 # time to get the comments |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1571 d = defer.ensureDeferred( |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1572 self._p.getItems( |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1573 client, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1574 service, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1575 node, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1576 max_comments, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1577 rsm_request=rsm_comments, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1578 extra=extra_comments, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1579 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1580 ) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1581 # then serialise |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1582 d.addCallback( |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1583 lambda items_data: self._p.transItemsDataD( |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1584 items_data, |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1585 partial( |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1586 self.item2mbdata, client, service=service, node=node |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1587 ), |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1588 serialise=True |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1589 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1590 ) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1591 # with failure handling |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1592 d.addCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1593 lambda serialised_items_data: ("",) + serialised_items_data |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1594 ) |
3028 | 1595 d.addErrback(lambda failure: (str(failure.value), [], {})) |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1596 # and associate with service/node (needed if there are several |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1597 # comments nodes) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1598 d.addCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1599 lambda serialised, service_s=service_s, node=node: ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1600 service_s, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1601 node, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1602 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1603 + serialised |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1604 ) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1605 dlist.append(d) |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1606 # we get the comments |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1607 comments_d = defer.gatherResults(dlist) |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1608 # and add them to the item data |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1609 comments_d.addCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1610 lambda comments_data, item=item: (item, comments_data) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1611 ) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1612 items_dlist.append(comments_d) |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1613 # we gather the items + comments in a list |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1614 items_d = defer.gatherResults(items_dlist) |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1615 # and add the metadata |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1616 items_d.addCallback(lambda items_completed: (items_completed, metadata)) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1617 return items_d |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1618 |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1619 deferreds = {} |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1620 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:
3550
diff
changeset
|
1621 d = deferreds[(service, node)] = defer.ensureDeferred(self._p.getItems( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1622 client, service, node, max_items, 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:
3550
diff
changeset
|
1623 )) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1624 d.addCallback( |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1625 lambda items_data: self._p.transItemsDataD( |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1626 items_data, |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1627 partial(self.item2mbdata, client, service=service, node=node), |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1628 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1629 ) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1630 d.addCallback(getComments) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1631 d.addCallback(lambda items_comments_data: ("", items_comments_data)) |
3028 | 1632 d.addErrback(lambda failure: (str(failure.value), ([], {}))) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1633 |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1634 return self.rt_sessions.newSession(deferreds, client.profile) |
2341
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
1635 |
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
1636 |
3028 | 1637 @implementer(iwokkel.IDisco) |
2341
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
1638 class XEP_0277_handler(XMPPHandler): |
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
1639 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1640 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
2341
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
1641 return [disco.DiscoFeature(NS_MICROBLOG)] |
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
1642 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1643 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
2341
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
1644 return [] |