Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_xep_0277.py @ 4225:cd889f4771cb
cli (file/receive): handle `CONFIRM` dialog received in pre-flight.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 05 Mar 2024 17:31:56 +0100 |
parents | c86a22009c1f |
children | 0d7bb4df2343 |
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 |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
20 from urllib.parse import quote, urlparse |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
21 import dateutil |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
22 import calendar |
4020
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
23 from mimetypes import guess_type |
3502
6132d363f0e9
plugin XEP-0277: user friendly ID:
Goffi <goffi@goffi.org>
parents:
3493
diff
changeset
|
24 from secrets import token_urlsafe |
4020
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
25 from typing import List, Optional, Dict, Tuple, Any, Dict |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
26 from functools import partial |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
27 |
3502
6132d363f0e9
plugin XEP-0277: user friendly ID:
Goffi <goffi@goffi.org>
parents:
3493
diff
changeset
|
28 import shortuuid |
6132d363f0e9
plugin XEP-0277: user friendly ID:
Goffi <goffi@goffi.org>
parents:
3493
diff
changeset
|
29 |
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.protocols.jabber import jid, error |
2341
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
31 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
|
32 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
|
33 from twisted.internet import defer |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
34 from twisted.python import failure |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
35 |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
36 # 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
|
37 from wokkel import pubsub |
3949
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
38 from wokkel import disco, iwokkel, rsm |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
39 from zope.interface import implementer |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
40 |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
41 from libervia.backend.core.i18n import _ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
42 from libervia.backend.core.constants import Const as C |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
43 from libervia.backend.core.log import getLogger |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
44 from libervia.backend.core import exceptions |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
45 from libervia.backend.core.core_types import SatXMPPEntity |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
46 from libervia.backend.tools import xml_tools |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
47 from libervia.backend.tools import sat_defer |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
48 from libervia.backend.tools import utils |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
49 from libervia.backend.tools.common import data_format |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
50 from libervia.backend.tools.common import uri as xmpp_uri |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
51 from libervia.backend.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
|
52 |
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 |
3179
84a94b385760
bridge: messageSend's extra is now serialised
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
54 log = getLogger(__name__) |
84a94b385760
bridge: messageSend's extra is now serialised
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
55 |
84a94b385760
bridge: messageSend's extra is now serialised
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
56 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
57 NS_MICROBLOG = "urn:xmpp:microblog:0" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
58 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
|
59 NS_PUBSUB_EVENT = f"{pubsub.NS_PUBSUB}#event" |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
60 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
|
61 |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 |
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 PLUGIN_INFO = { |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2117
diff
changeset
|
64 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
|
65 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
|
66 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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 C.PI_MAIN: "XEP_0277", |
2341
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
72 C.PI_HANDLER: "yes", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
73 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
|
74 } |
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
76 |
339
b0b773f432e5
plugin XEP-00277: setMicroblogAccess is now asynchronous
Goffi <goffi@goffi.org>
parents:
311
diff
changeset
|
77 class NodeAccessChangeException(Exception): |
b0b773f432e5
plugin XEP-00277: setMicroblogAccess is now asynchronous
Goffi <goffi@goffi.org>
parents:
311
diff
changeset
|
78 pass |
b0b773f432e5
plugin XEP-00277: setMicroblogAccess is now asynchronous
Goffi <goffi@goffi.org>
parents:
311
diff
changeset
|
79 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
80 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
81 class XEP_0277(object): |
1831
68c0dc13d821
plugin blog import, XEP-0277: progress + redirect:
Goffi <goffi@goffi.org>
parents:
1829
diff
changeset
|
82 namespace = NS_MICROBLOG |
3724
a0c08fcfe11e
plugin XEP-0277: various fixes + async:
Goffi <goffi@goffi.org>
parents:
3680
diff
changeset
|
83 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
|
84 |
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 def __init__(self, host): |
3028 | 86 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
|
87 self.host = host |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
88 host.register_namespace("microblog", NS_MICROBLOG) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
89 self._p = self.host.plugins[ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
90 "XEP-0060" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
91 ] # this facilitate the access to pubsub plugin |
3598
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
92 ps_cache = self.host.plugins.get("PUBSUB_CACHE") |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
93 if ps_cache is not None: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
94 ps_cache.register_analyser( |
3598
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
95 { |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
96 "name": "XEP-0277", |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
97 "node": NS_MICROBLOG, |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
98 "namespace": NS_ATOM, |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
99 "type": "blog", |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
100 "to_sync": True, |
4023
78b5f356900c
component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents:
4020
diff
changeset
|
101 "parser": self.item_2_mb_data, |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
102 "match_cb": self._cache_node_match_cb, |
3598
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
103 } |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
104 ) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
105 self.rt_sessions = sat_defer.RTDeferredSessions() |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
106 self.host.plugins["XEP-0060"].add_managed_node( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
107 NS_MICROBLOG, items_cb=self._items_received |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
108 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
109 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
110 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
111 "mb_send", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
112 ".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
|
113 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
|
114 out_sign="s", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
115 method=self._mb_send, |
3028 | 116 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
117 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
118 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
119 "mb_repeat", |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
120 ".plugin", |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
121 in_sign="sssss", |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
122 out_sign="s", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
123 method=self._mb_repeat, |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
124 async_=True, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
125 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
126 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
127 "mb_preview", |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
128 ".plugin", |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
129 in_sign="ssss", |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
130 out_sign="s", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
131 method=self._mb_preview, |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
132 async_=True, |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
133 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
134 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
135 "mb_retract", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
136 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
137 in_sign="ssss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
138 out_sign="", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
139 method=self._mb_retract, |
3028 | 140 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
141 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
142 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
143 "mb_get", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
144 ".plugin", |
3586
5f65f4e9f8cb
plugin XEP-0060: getItems extra is now serialised dict
Goffi <goffi@goffi.org>
parents:
3584
diff
changeset
|
145 in_sign="ssiasss", |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
146 out_sign="s", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
147 method=self._mb_get, |
3028 | 148 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
149 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
150 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
151 "mb_rename", |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
152 ".plugin", |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
153 in_sign="sssss", |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
154 out_sign="", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
155 method=self._mb_rename, |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
156 async_=True, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
157 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
158 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
159 "mb_access_set", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
160 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
161 in_sign="ss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
162 out_sign="", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
163 method=self.mb_access_set, |
3028 | 164 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
165 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
166 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
167 "mb_subscribe_to_many", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
168 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
169 in_sign="sass", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
170 out_sign="s", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
171 method=self._mb_subscribe_to_many, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
172 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
173 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
174 "mb_get_from_many_rt_result", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
175 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
176 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
|
177 out_sign="(ua(sssasa{ss}))", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
178 method=self._mb_get_from_many_rt_result, |
3028 | 179 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
180 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
181 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
182 "mb_get_from_many", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
183 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
184 in_sign="sasia{ss}s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
185 out_sign="s", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
186 method=self._mb_get_from_many, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
187 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
188 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
189 "mb_get_from_many_with_comments_rt_result", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
190 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
191 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
|
192 out_sign="(ua(sssa(sa(sssasa{ss}))a{ss}))", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
193 method=self._mb_get_from_many_with_comments_rt_result, |
3028 | 194 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
195 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
196 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
197 "mb_get_from_many_with_comments", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
198 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
199 in_sign="sasiia{ss}a{ss}s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
200 out_sign="s", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
201 method=self._mb_get_from_many_with_comments, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
202 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
203 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
204 "mb_is_comment_node", |
3762
becd7f1aa033
plugin XEP-0277: bridge method `mbIsCommentNode` + methods renaming
Goffi <goffi@goffi.org>
parents:
3761
diff
changeset
|
205 ".plugin", |
becd7f1aa033
plugin XEP-0277: bridge method `mbIsCommentNode` + methods renaming
Goffi <goffi@goffi.org>
parents:
3761
diff
changeset
|
206 in_sign="s", |
becd7f1aa033
plugin XEP-0277: bridge method `mbIsCommentNode` + methods renaming
Goffi <goffi@goffi.org>
parents:
3761
diff
changeset
|
207 out_sign="b", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
208 method=self.is_comment_node, |
3762
becd7f1aa033
plugin XEP-0277: bridge method `mbIsCommentNode` + methods renaming
Goffi <goffi@goffi.org>
parents:
3761
diff
changeset
|
209 ) |
302
9f3a6cf91668
plugin xep-0277: added getLastMicroblogs method
Goffi <goffi@goffi.org>
parents:
297
diff
changeset
|
210 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
211 def get_handler(self, client): |
2341
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
212 return XEP_0277_handler() |
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
213 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
214 def _cache_node_match_cb( |
3598
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
215 self, |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
216 client: SatXMPPEntity, |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
217 analyse: dict, |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
218 ) -> None: |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
219 """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
|
220 if analyse["node"].startswith(NS_COMMENT_PREFIX): |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
221 analyse["subtype"] = "comment" |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
222 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
223 def _check_features_cb(self, available): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
224 return {"available": C.BOOL_TRUE} |
1656
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
225 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
226 def _check_features_eb(self, fail): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
227 return {"available": C.BOOL_FALSE} |
1656
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
228 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
229 def features_get(self, profile): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
230 client = self.host.get_client(profile) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
231 d = self.host.check_features(client, [], identity=("pubsub", "pep")) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
232 d.addCallbacks(self._check_features_cb, self._check_features_eb) |
1656
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
233 return d |
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
234 |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
235 ## plugin management methods ## |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
236 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
237 def _items_received(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
|
238 """Callback which manage items notifications (publish + retract)""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
239 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
240 def manage_item(data, event): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
241 self.host.bridge.ps_event( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
242 C.PS_MICROBLOG, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
243 itemsEvent.sender.full(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
244 itemsEvent.nodeIdentifier, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
245 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
|
246 data_format.serialise(data), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
247 client.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
248 ) |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
249 |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
250 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
|
251 if item.name == C.PS_ITEM: |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
252 # FIXME: service and node should be used here |
4023
78b5f356900c
component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents:
4020
diff
changeset
|
253 self.item_2_mb_data(client, item, None, None).addCallbacks( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
254 manage_item, lambda failure: None, (C.PS_PUBLISH,) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
255 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
256 elif item.name == C.PS_RETRACT: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
257 manage_item({"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
|
258 else: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
259 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
|
260 |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
261 ## 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
|
262 |
707
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
263 @defer.inlineCallbacks |
4023
78b5f356900c
component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents:
4020
diff
changeset
|
264 def item_2_mb_data( |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
265 self, |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
266 client: SatXMPPEntity, |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
267 item_elt: domish.Element, |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
268 service: Optional[jid.JID], |
4023
78b5f356900c
component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents:
4020
diff
changeset
|
269 # FIXME: node is Optional until all calls to item_2_mb_data set properly service |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
270 # 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
|
271 node: Optional[str] |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
272 ) -> 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
|
273 """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
|
274 |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
275 @param item_elt: microblog item element |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
276 @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
|
277 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
|
278 @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
|
279 if None, "uri" won't be set |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
280 @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
|
281 """ |
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
|
282 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
|
283 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
|
284 |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
285 extra: Dict[str, Any] = {} |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
286 mb_data: Dict[str, Any] = { |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
287 "service": service.full(), |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
288 "extra": extra |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
289 } |
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
|
290 |
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
|
291 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
|
292 """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
|
293 |
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 @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
|
295 @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
|
296 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
|
297 @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
|
298 (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
|
299 """ |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
300 if key in mb_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
|
301 if not increment: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
302 raise failure.Failure( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
303 exceptions.DataError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
304 "key {} is already present for item {}" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
305 ).format(key, item_elt["id"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
306 ) |
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 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
308 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
|
309 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
|
310 new_key = fmt.format(key, idx) |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
311 while new_key in mb_data: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
312 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
|
313 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
|
314 key = new_key |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
315 return key |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
316 |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
317 @defer.inlineCallbacks |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
318 def parseElement(elem): |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
319 """Parse title/content elements and fill microblog_data accordingly""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
320 type_ = elem.getAttribute("type") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
321 if type_ == "xhtml": |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
322 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
|
323 if data_elt is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
324 raise failure.Failure( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
325 exceptions.DataError( |
3028 | 326 "XHML content not wrapped in a <div/> element, this is not " |
327 "standard !" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
328 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
329 ) |
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
|
330 if data_elt.uri != C.NS_XHTML: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
331 raise failure.Failure( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
332 exceptions.DataError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
333 _("Content of type XHTML must declare its namespace!") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
334 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
335 ) |
3028 | 336 key = check_conflict("{}_xhtml".format(elem.name)) |
1791 | 337 data = data_elt.toXml() |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
338 mb_data[key] = yield self.host.plugins["TEXT_SYNTAXES"].clean_xhtml( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
339 data |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
340 ) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
341 else: |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
342 key = check_conflict(elem.name) |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
343 mb_data[key] = str(elem) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
344 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
345 id_ = item_elt.getAttribute("id", "") # there can be no id for transient nodes |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
346 mb_data["id"] = id_ |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
347 if item_elt.uri not in (pubsub.NS_PUBSUB, NS_PUBSUB_EVENT): |
3028 | 348 msg = "Unsupported namespace {ns} in pubsub item {id_}".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
349 ns=item_elt.uri, id_=id_ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
350 ) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
351 log.warning(msg) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
352 raise failure.Failure(exceptions.DataError(msg)) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
353 |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
354 try: |
3028 | 355 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
|
356 except StopIteration: |
3028 | 357 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
|
358 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
|
359 |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
360 # uri |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
361 # 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
|
362 if node is not None: |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
363 mb_data["node"] = node |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
364 mb_data['uri'] = xmpp_uri.build_xmpp_uri( |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
365 "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
|
366 path=service.full(), |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
367 node=node, |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
368 item=id_, |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
369 ) |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
370 |
2264
a8eaaac4d80f
plugin XEP-0277, tools/common/data_objects: language handling
Goffi <goffi@goffi.org>
parents:
2243
diff
changeset
|
371 # language |
a8eaaac4d80f
plugin XEP-0277, tools/common/data_objects: language handling
Goffi <goffi@goffi.org>
parents:
2243
diff
changeset
|
372 try: |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
373 mb_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
|
374 except KeyError: |
a8eaaac4d80f
plugin XEP-0277, tools/common/data_objects: language handling
Goffi <goffi@goffi.org>
parents:
2243
diff
changeset
|
375 pass |
a8eaaac4d80f
plugin XEP-0277, tools/common/data_objects: language handling
Goffi <goffi@goffi.org>
parents:
2243
diff
changeset
|
376 |
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
|
377 # 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
|
378 try: |
3028 | 379 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
|
380 except StopIteration: |
3028 | 381 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
|
382 .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
|
383 log.warning(msg) |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
384 mb_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
|
385 else: |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
386 mb_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
|
387 |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
388 # 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
|
389 |
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 # 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
|
391 # 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
|
392 # 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
|
393 # 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
|
394 # 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
|
395 # 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
|
396 # 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
|
397 # 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
|
398 # raise failure.Failure(exceptions.DataError(msg)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
399 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
|
400 if not title_elts: |
3028 | 401 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
|
402 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
|
403 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
|
404 yield parseElement(title_elt) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
405 |
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
|
406 # 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
|
407 # 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
|
408 # if more than one can be present |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
409 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
|
410 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
|
411 |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
412 # we check that text content is present |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
413 for key in ("title", "content"): |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
414 if key not in mb_data and ("{}_xhtml".format(key)) in mb_data: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
415 log.warning( |
3028 | 416 "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
|
417 id_=id_, key=key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
418 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
419 ) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
420 # ... and do the conversion if it's not |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
421 mb_data[key] = yield self.host.plugins["TEXT_SYNTAXES"].convert( |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
422 mb_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
|
423 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
|
424 self.host.plugins["TEXT_SYNTAXES"].SYNTAX_TEXT, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
425 False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
426 ) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
427 |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
428 if "content" not in mb_data: |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
429 # use the atom title data as the microblog body content |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
430 mb_data["content"] = mb_data["title"] |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
431 del mb_data["title"] |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
432 if "title_xhtml" in mb_data: |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
433 mb_data["content_xhtml"] = mb_data["title_xhtml"] |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
434 del mb_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
|
435 |
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
|
436 # 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
|
437 try: |
3028 | 438 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
|
439 except StopIteration: |
3028 | 440 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
|
441 raise failure.Failure(exceptions.DataError(msg)) |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
442 mb_data["updated"] = calendar.timegm( |
3028 | 443 dateutil.parser.parse(str(updated_elt)).utctimetuple() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
444 ) |
302
9f3a6cf91668
plugin xep-0277: added getLastMicroblogs method
Goffi <goffi@goffi.org>
parents:
297
diff
changeset
|
445 try: |
3028 | 446 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
|
447 except StopIteration: |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
448 mb_data["published"] = mb_data["updated"] |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
449 else: |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
450 mb_data["published"] = calendar.timegm( |
3028 | 451 dateutil.parser.parse(str(published_elt)).utctimetuple() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
452 ) |
859
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
858
diff
changeset
|
453 |
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
|
454 # links |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
455 comments = mb_data['comments'] = [] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
456 for link_elt in entry_elt.elements(NS_ATOM, "link"): |
4020
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
457 href = link_elt.getAttribute("href") |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
458 if not href: |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
459 log.warning( |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
460 f'missing href in <link> element: {link_elt.toXml()}' |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
461 ) |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
462 continue |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
463 rel = link_elt.getAttribute("rel") |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
464 if (rel == "replies" and link_elt.getAttribute("title") == "comments"): |
4020
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
465 uri = href |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
466 comments_data = { |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
467 "uri": uri, |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
468 } |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
469 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
470 comment_service, comment_node = self.parse_comment_url(uri) |
3069
73db9db8b9e1
plugin XEP-0277: fixed comments URLs parsing
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
471 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
|
472 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
|
473 continue |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
474 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
|
475 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
|
476 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
|
477 comments.append(comments_data) |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
478 elif rel == "via": |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
479 try: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
480 repeater_jid = jid.JID(item_elt["publisher"]) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
481 except (KeyError, RuntimeError): |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
482 try: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
483 # 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
|
484 # has not parent |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
485 top_elt = item_elt.parent |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
486 while top_elt.parent is not None: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
487 top_elt = top_elt.parent |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
488 repeater_jid = jid.JID(top_elt["from"]) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
489 except (AttributeError, RuntimeError): |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
490 # 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
|
491 # stanza available |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
492 log.error( |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
493 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
|
494 ) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
495 continue |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
496 |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
497 extra["repeated"] = { |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
498 "by": repeater_jid.full(), |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
499 "uri": href |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
500 } |
4020
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
501 elif rel in ("related", "enclosure"): |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
502 attachment: Dict[str, Any] = { |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
503 "sources": [{"url": href}] |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
504 } |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
505 if rel == "related": |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
506 attachment["external"] = True |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
507 for attr, key in ( |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
508 ("type", "media_type"), |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
509 ("title", "desc"), |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
510 ): |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
511 value = link_elt.getAttribute(attr) |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
512 if value: |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
513 attachment[key] = value |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
514 try: |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
515 attachment["size"] = int(link_elt.attributes["lenght"]) |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
516 except (KeyError, ValueError): |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
517 pass |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
518 if "media_type" not in attachment: |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
519 media_type = guess_type(href, False)[0] |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
520 if media_type is not None: |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
521 attachment["media_type"] = media_type |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
522 |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
523 attachments = extra.setdefault("attachments", []) |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
524 attachments.append(attachment) |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
525 elif rel == "alternate": |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
526 link_data = {"url": href} |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
527 media_type = link_elt.getAttribute("type") or guess_type(href)[0] |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
528 if media_type: |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
529 link_data["media_type"] = media_type |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
530 else: |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
531 log.warning( |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
532 f"Invalid or missing media type for alternate link: {href}" |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
533 ) |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
534 extra.setdefault("alt_links", []).append(link_data) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
535 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
536 log.warning( |
4020
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
537 f"Unmanaged link element: {link_elt.toXml()}" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
538 ) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
539 |
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
|
540 # author |
3492
fa796612adad
plugin XEP-0277: better resilience to broken items:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
541 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
|
542 try: |
3028 | 543 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
|
544 except StopIteration: |
3028 | 545 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
|
546 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
|
547 # name |
770
64dd7c0f4feb
plugin groupblog, XEP-0277: store both published and updated timestamps
souliane <souliane@mailoo.org>
parents:
745
diff
changeset
|
548 try: |
3028 | 549 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
|
550 except StopIteration: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
551 log.warning( |
3028 | 552 "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
|
553 ) |
3724
a0c08fcfe11e
plugin XEP-0277: various fixes + async:
Goffi <goffi@goffi.org>
parents:
3680
diff
changeset
|
554 author = None |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
555 else: |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
556 author = mb_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
|
557 # 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
|
558 try: |
3028 | 559 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
|
560 except StopIteration: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
561 log.debug( |
3028 | 562 "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
|
563 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
564 if publisher: |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
565 mb_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
|
566 else: |
3028 | 567 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
|
568 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
|
569 uri = uri[5:] |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
570 mb_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
|
571 else: |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
572 mb_data["author_jid"] = ( |
3028 | 573 item_elt.getAttribute("publisher") or "" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
574 ) |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
575 if not author and mb_data["author_jid"]: |
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
|
576 # 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
|
577 # 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
|
578 try: |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
579 mb_data["author"] = jid.JID(mb_data["author_jid"]).user |
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
|
580 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
|
581 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
|
582 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
583 if not publisher: |
3028 | 584 log.debug("No publisher attribute, we can't verify author jid") |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
585 mb_data["author_jid_verified"] = False |
1681
c6c835046681
plugin XEP-0277: minor fixes for publisher attribute
Goffi <goffi@goffi.org>
parents:
1680
diff
changeset
|
586 elif jid.JID(publisher).userhostJID() == jid.JID(uri).userhostJID(): |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
587 mb_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
|
588 else: |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
589 if "repeated" not in extra: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
590 log.warning( |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
591 "item atom:uri differ from publisher attribute, spoofing " |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
592 "attempt ? atom:uri = {} publisher = {}".format( |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
593 uri, item_elt.getAttribute("publisher") |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
594 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
595 ) |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
596 mb_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
|
597 # 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
|
598 try: |
3028 | 599 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
|
600 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
|
601 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
|
602 else: |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
603 mb_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
|
604 |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
605 if not mb_data.get("author_jid"): |
3493
b54bdd4ec507
plugin XEP-0277: be sure to have an `author_jid` set
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
606 if publisher: |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
607 mb_data["author_jid"] = publisher |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
608 mb_data["author_jid_verified"] = True |
3493
b54bdd4ec507
plugin XEP-0277: be sure to have an `author_jid` set
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
609 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
610 iq_elt = xml_tools.find_ancestor(item_elt, "iq", C.NS_STREAM) |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
611 mb_data["author_jid"] = iq_elt["from"] |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
612 mb_data["author_jid_verified"] = False |
3493
b54bdd4ec507
plugin XEP-0277: be sure to have an `author_jid` set
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
613 |
3492
fa796612adad
plugin XEP-0277: better resilience to broken items:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
614 # categories |
fa796612adad
plugin XEP-0277: better resilience to broken items:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
615 categories = [ |
fa796612adad
plugin XEP-0277: better resilience to broken items:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
616 category_elt.getAttribute("term", "") |
fa796612adad
plugin XEP-0277: better resilience to broken items:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
617 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
|
618 ] |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
619 mb_data["tags"] = categories |
1664
5d0ff155be1a
plugin XEP-0277: tags are handled through atom categories
Goffi <goffi@goffi.org>
parents:
1661
diff
changeset
|
620 |
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
|
621 ## 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
|
622 # if other plugins have things to add or change |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
623 yield self.host.trigger.point( |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
624 "XEP-0277_item2data", item_elt, entry_elt, mb_data |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
625 ) |
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
|
626 |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
627 defer.returnValue(mb_data) |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
628 |
4023
78b5f356900c
component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents:
4020
diff
changeset
|
629 async def mb_data_2_entry_elt(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
|
630 """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
|
631 |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
632 @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
|
633 @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
|
634 @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
|
635 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
|
636 @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
|
637 Needed to construct Atom id |
1419
be2df1ddea8e
plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
638 @return: deferred which fire domish.Element |
be2df1ddea8e
plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
639 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
640 entry_elt = domish.Element((NS_ATOM, "entry")) |
4020
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
641 extra = mb_data.get("extra", {}) |
706
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
642 |
2264
a8eaaac4d80f
plugin XEP-0277, tools/common/data_objects: language handling
Goffi <goffi@goffi.org>
parents:
2243
diff
changeset
|
643 ## language ## |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
644 if "language" in mb_data: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
645 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
|
646 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
647 ## 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
|
648 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
|
649 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
650 for elem_name in ("title", "content"): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
651 for type_ in ["", "_rich", "_xhtml"]: |
4020
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
652 attr = f"{elem_name}{type_}" |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
653 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
|
654 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
|
655 if type_: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
656 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
|
657 xml_content = await synt.convert( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
658 mb_data[attr], synt.get_current_syntax(client.profile), "XHTML" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
659 ) |
4020
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
660 if f"{elem_name}_xhtml" in mb_data: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
661 raise failure.Failure( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
662 exceptions.DataError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
663 _( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
664 "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
|
665 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
666 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
667 ) |
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
|
668 else: |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
669 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
|
670 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
671 div_elt = xml_tools.ElementParser()( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
672 xml_content, namespace=C.NS_XHTML |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
673 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
674 if ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
675 div_elt.name != "div" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
676 or div_elt.uri != C.NS_XHTML |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
677 or div_elt.attributes |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
678 ): |
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
|
679 # 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
|
680 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
|
681 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
|
682 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
|
683 elem.addChild(div_elt) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
684 elem["type"] = "xhtml" |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
685 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
|
686 # 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
|
687 # 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
|
688 elem_txt = entry_elt.addElement(elem_name) |
3724
a0c08fcfe11e
plugin XEP-0277: various fixes + async:
Goffi <goffi@goffi.org>
parents:
3680
diff
changeset
|
689 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
|
690 "TEXT_SYNTAXES" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
691 ].convert( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
692 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
|
693 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
|
694 self.host.plugins["TEXT_SYNTAXES"].SYNTAX_TEXT, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
695 False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
696 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
697 elem_txt.addContent(text_content) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
698 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
|
699 |
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
|
700 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
|
701 elem.addContent(mb_data[attr]) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
702 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
|
703 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
704 try: |
3028 | 705 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
|
706 except StopIteration: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
707 # 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
|
708 # so we transform content element to title |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
709 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
|
710 if not elems: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
711 raise exceptions.DataError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
712 "There must be at least one content or title element" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
713 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
714 for elem in elems: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
715 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
|
716 |
4020
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
717 ## attachments ## |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
718 attachments = extra.get(C.KEY_ATTACHMENTS) |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
719 if attachments: |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
720 for attachment in attachments: |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
721 try: |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
722 url = attachment["url"] |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
723 except KeyError: |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
724 try: |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
725 url = next( |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
726 s['url'] for s in attachment["sources"] if 'url' in s |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
727 ) |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
728 except (StopIteration, KeyError): |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
729 log.warning( |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
730 f'"url" missing in attachment, ignoring: {attachment}' |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
731 ) |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
732 continue |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
733 |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
734 if not url.startswith("http"): |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
735 log.warning(f"non HTTP URL in attachment, ignoring: {attachment}") |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
736 continue |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
737 link_elt = entry_elt.addElement("link") |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
738 # XXX: "uri" is set in self._manage_comments if not already existing |
4020
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
739 link_elt["href"] = url |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
740 if attachment.get("external", False): |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
741 # this is a link to an external data such as a website |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
742 link_elt["rel"] = "related" |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
743 else: |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
744 # this is an attached file |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
745 link_elt["rel"] = "enclosure" |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
746 for key, attr in ( |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
747 ("media_type", "type"), |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
748 ("desc", "title"), |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
749 ("size", "lenght") |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
750 ): |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
751 value = attachment.get(key) |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
752 if value: |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
753 link_elt[attr] = str(value) |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
754 |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
755 ## alternate links ## |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
756 alt_links = extra.get("alt_links") |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
757 if alt_links: |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
758 for link_data in alt_links: |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
759 url_template = link_data["url"] |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
760 url = url_template.format( |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
761 service=quote(service.full(), safe=""), |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
762 node=quote(node, safe=""), |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
763 item=quote(item_id, safe="") |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
764 ) |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
765 |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
766 link_elt = entry_elt.addElement("link") |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
767 link_elt["href"] = url |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
768 link_elt["rel"] = "alternate" |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
769 |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
770 media_type = link_data.get("media_type") |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
771 if not media_type: |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
772 parsed_url = urlparse(url) |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
773 if parsed_url.scheme in ["http", "https"]: |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
774 media_type = "text/html" |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
775 else: |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
776 media_type = guess_type(url)[0] or "application/octet-stream" |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
777 |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
778 link_elt["type"] = media_type |
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
779 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
780 ## author ## |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
781 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
|
782 try: |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
783 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
|
784 except KeyError: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
785 # 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
|
786 author_name = client.jid.user |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
787 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
|
788 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
789 try: |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
790 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
|
791 except KeyError: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
792 author_jid_s = client.jid.userhost() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
793 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
|
794 |
1820
3c8cf120a0fd
plugin XEP-0277: added missing author_email parsing
Goffi <goffi@goffi.org>
parents:
1817
diff
changeset
|
795 try: |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
796 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
|
797 except KeyError: |
3c8cf120a0fd
plugin XEP-0277: added missing author_email parsing
Goffi <goffi@goffi.org>
parents:
1817
diff
changeset
|
798 pass |
3c8cf120a0fd
plugin XEP-0277: added missing author_email parsing
Goffi <goffi@goffi.org>
parents:
1817
diff
changeset
|
799 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
800 ## 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
|
801 current_time = time.time() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
802 entry_elt.addElement( |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
803 "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
|
804 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
805 entry_elt.addElement( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
806 "published", |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
807 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
|
808 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
809 |
1664
5d0ff155be1a
plugin XEP-0277: tags are handled through atom categories
Goffi <goffi@goffi.org>
parents:
1661
diff
changeset
|
810 ## categories ## |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
811 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
|
812 category_elt = entry_elt.addElement("category") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
813 category_elt["term"] = tag |
1664
5d0ff155be1a
plugin XEP-0277: tags are handled through atom categories
Goffi <goffi@goffi.org>
parents:
1661
diff
changeset
|
814 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
815 ## id ## |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
816 entry_id = mb_data.get( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
817 "id", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
818 xmpp_uri.build_xmpp_uri( |
3028 | 819 "pubsub", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
820 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
|
821 node=node, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
822 item=item_id, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
823 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
824 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
825 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
|
826 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
827 ## comments ## |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
828 for comments_data in mb_data.get('comments', []): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
829 link_elt = entry_elt.addElement("link") |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
830 # XXX: "uri" is set in self._manage_comments if not already existing |
4186
c86a22009c1f
plugin XEP-0277: fix comments node handling when parent node doesn't exist.
Goffi <goffi@goffi.org>
parents:
4178
diff
changeset
|
831 try: |
c86a22009c1f
plugin XEP-0277: fix comments node handling when parent node doesn't exist.
Goffi <goffi@goffi.org>
parents:
4178
diff
changeset
|
832 link_elt["href"] = comments_data["uri"] |
c86a22009c1f
plugin XEP-0277: fix comments node handling when parent node doesn't exist.
Goffi <goffi@goffi.org>
parents:
4178
diff
changeset
|
833 except KeyError: |
c86a22009c1f
plugin XEP-0277: fix comments node handling when parent node doesn't exist.
Goffi <goffi@goffi.org>
parents:
4178
diff
changeset
|
834 log.warning(f"missing URI in comments data: {comments_data}") |
c86a22009c1f
plugin XEP-0277: fix comments node handling when parent node doesn't exist.
Goffi <goffi@goffi.org>
parents:
4178
diff
changeset
|
835 entry_elt.children.remove(link_elt) |
c86a22009c1f
plugin XEP-0277: fix comments node handling when parent node doesn't exist.
Goffi <goffi@goffi.org>
parents:
4178
diff
changeset
|
836 else: |
c86a22009c1f
plugin XEP-0277: fix comments node handling when parent node doesn't exist.
Goffi <goffi@goffi.org>
parents:
4178
diff
changeset
|
837 link_elt["rel"] = "replies" |
c86a22009c1f
plugin XEP-0277: fix comments node handling when parent node doesn't exist.
Goffi <goffi@goffi.org>
parents:
4178
diff
changeset
|
838 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
|
839 |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
840 if "repeated" in extra: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
841 try: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
842 repeated = extra["repeated"] |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
843 link_elt = entry_elt.addElement("link") |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
844 link_elt["rel"] = "via" |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
845 link_elt["href"] = repeated["uri"] |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
846 except KeyError as e: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
847 log.warning( |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
848 f"invalid repeated element({e}): {extra['repeated']}" |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
849 ) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
850 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
851 ## 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
|
852 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
|
853 |
96ee986dab3c
plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents:
1656
diff
changeset
|
854 ## the trigger ## |
96ee986dab3c
plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents:
1656
diff
changeset
|
855 # 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
|
856 self.host.trigger.point( |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
857 "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
|
858 ) |
1661
96ee986dab3c
plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents:
1656
diff
changeset
|
859 |
3724
a0c08fcfe11e
plugin XEP-0277: various fixes + async:
Goffi <goffi@goffi.org>
parents:
3680
diff
changeset
|
860 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
|
861 |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
862 ## publish/preview ## |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
863 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
864 def is_comment_node(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
|
865 """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
|
866 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
|
867 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
868 def get_parent_item(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
|
869 """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
|
870 |
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
|
871 @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
|
872 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
873 if not self.is_comment_node(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
|
874 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
|
875 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
|
876 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
877 def get_comments_node(self, item_id): |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
878 """Generate comment node |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
879 |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
880 @param item_id(unicode): id of the parent item |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
881 @return (unicode): comment node to use |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
882 """ |
3598
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
883 return f"{NS_COMMENT_PREFIX}{item_id}" |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
884 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
885 def get_comments_service(self, client, parent_service=None): |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
886 """Get prefered PubSub service to create comment node |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
887 |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
888 @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
|
889 @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
|
890 """ |
2433
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
891 if parent_service is not None: |
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
892 if parent_service.user: |
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
893 # we are on a PEP |
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
894 if parent_service.host == client.jid.host: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
895 # 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
|
896 pass |
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
897 else: |
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
898 # other server, let's try to find a non PEP service there |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
899 d = self.host.find_service_entity( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
900 client, "pubsub", "service", parent_service |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
901 ) |
2433
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
902 d.addCallback(lambda entity: entity or parent_service) |
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
903 else: |
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
904 # 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
|
905 return defer.succeed(parent_service) |
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
906 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
907 return defer.succeed( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
908 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
|
909 ) |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
910 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
911 async def _manage_comments(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
|
912 """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
|
913 |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
914 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
|
915 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
|
916 @param mb_data(dict): microblog mb_data |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
917 @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
|
918 @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
|
919 @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
|
920 @param access(unicode, None): access model |
79d279d1ee88
plugin XEP-0277: comments node access model changes:
Goffi <goffi@goffi.org>
parents:
2218
diff
changeset
|
921 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
|
922 """ |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
923 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
|
924 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
|
925 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
|
926 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
|
927 else: |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
928 # 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
|
929 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
|
930 elif allow_comments == False: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
931 if "comments" in mb_data: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
932 log.warning( |
3028 | 933 "comments are not allowed but there is already a comments node, " |
934 "it may be lost: {uri}".format( | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
935 uri=mb_data["comments"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
936 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
937 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
938 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
|
939 return |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
940 |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
941 # 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
|
942 # 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
|
943 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
|
944 # 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
|
945 mb_data['comments'].append({}) |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
946 |
2227
79d279d1ee88
plugin XEP-0277: comments node access model changes:
Goffi <goffi@goffi.org>
parents:
2218
diff
changeset
|
947 if access is None: |
79d279d1ee88
plugin XEP-0277: comments node access model changes:
Goffi <goffi@goffi.org>
parents:
2218
diff
changeset
|
948 # TODO: cache access models per service/node |
4186
c86a22009c1f
plugin XEP-0277: fix comments node handling when parent node doesn't exist.
Goffi <goffi@goffi.org>
parents:
4178
diff
changeset
|
949 try: |
c86a22009c1f
plugin XEP-0277: fix comments node handling when parent node doesn't exist.
Goffi <goffi@goffi.org>
parents:
4178
diff
changeset
|
950 parent_node_config = await self._p.getConfiguration(client, service, node) |
c86a22009c1f
plugin XEP-0277: fix comments node handling when parent node doesn't exist.
Goffi <goffi@goffi.org>
parents:
4178
diff
changeset
|
951 except error.StanzaError as e: |
c86a22009c1f
plugin XEP-0277: fix comments node handling when parent node doesn't exist.
Goffi <goffi@goffi.org>
parents:
4178
diff
changeset
|
952 log.debug(f"Can't get parent node configuration: {e}") |
c86a22009c1f
plugin XEP-0277: fix comments node handling when parent node doesn't exist.
Goffi <goffi@goffi.org>
parents:
4178
diff
changeset
|
953 access = self._p.ACCESS_OPEN |
c86a22009c1f
plugin XEP-0277: fix comments node handling when parent node doesn't exist.
Goffi <goffi@goffi.org>
parents:
4178
diff
changeset
|
954 else: |
c86a22009c1f
plugin XEP-0277: fix comments node handling when parent node doesn't exist.
Goffi <goffi@goffi.org>
parents:
4178
diff
changeset
|
955 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
|
956 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
957 options = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
958 self._p.OPT_ACCESS_MODEL: access, |
4018
86efd854dee1
plugin XEP-0277: ensure that `max-items` is set to `max` when creating a node
Goffi <goffi@goffi.org>
parents:
4011
diff
changeset
|
959 self._p.OPT_MAX_ITEMS: "max", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
960 self._p.OPT_PERSIST_ITEMS: 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
961 self._p.OPT_DELIVER_PAYLOADS: 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
962 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
963 # 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
|
964 self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
965 } |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
966 |
1661
96ee986dab3c
plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents:
1656
diff
changeset
|
967 # 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
|
968 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
|
969 |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
970 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
|
971 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
|
972 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
|
973 try: |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
974 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
|
975 except KeyError: |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
976 comments_service = None |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
977 |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
978 if uri: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
979 uri_service, uri_node = self.parse_comment_url(uri) |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
980 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
|
981 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
|
982 raise ValueError( |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
983 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
|
984 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
|
985 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
|
986 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
|
987 else: |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
988 if not comments_node: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
989 comments_node = self.get_comments_node(item_id) |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
990 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
|
991 if comments_service is None: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
992 comments_service = await self.get_comments_service(client, service) |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
993 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
|
994 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
|
995 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
|
996 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
997 comments_data['uri'] = xmpp_uri.build_xmpp_uri( |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
998 "pubsub", |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
999 path=comments_service.full(), |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1000 node=comments_node, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1001 ) |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
1002 |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1003 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
|
1004 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
|
1005 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
|
1006 if e.condition == "conflict": |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1007 log.info( |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1008 "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
|
1009 comments_node, comments_service |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1010 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1011 ) |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1012 else: |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1013 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
|
1014 else: |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1015 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
|
1016 # for whitelist access we need to copy affiliations from parent item |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1017 comments_affiliations = await self._p.get_node_affiliations( |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1018 client, service, node |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1019 ) |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1020 # …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
|
1021 # 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
|
1022 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
|
1023 if affiliation == "member": |
4186
c86a22009c1f
plugin XEP-0277: fix comments node handling when parent node doesn't exist.
Goffi <goffi@goffi.org>
parents:
4178
diff
changeset
|
1024 comments_affiliations[jid_] = "publisher" |
2286
330f8d4e2ad4
plugin XEP-0277: change affiliations for comments + fixes:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
1025 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1026 await self._p.set_node_affiliations( |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1027 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
|
1028 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1029 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1030 def friendly_id(self, data): |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1031 """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
|
1032 # TODO: rich content should be converted to plain text |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1033 id_base = regex.url_friendly_text( |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1034 data.get('title') |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1035 or data.get('title_rich') |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1036 or data.get('content') |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1037 or data.get('content_rich') |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1038 or '' |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1039 ) |
4172
0e48181d50ab
Plugin XEP-0277: Add metadata to prevent adding random suffixes to generated user-friendly IDs.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
1040 if not data.get("user_friendly_id_suffix", True): |
0e48181d50ab
Plugin XEP-0277: Add metadata to prevent adding random suffixes to generated user-friendly IDs.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
1041 return id_base |
0e48181d50ab
Plugin XEP-0277: Add metadata to prevent adding random suffixes to generated user-friendly IDs.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
1042 else: |
0e48181d50ab
Plugin XEP-0277: Add metadata to prevent adding random suffixes to generated user-friendly IDs.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
1043 return f"{id_base}-{token_urlsafe(3)}" |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1044 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1045 def _mb_send(self, service, node, data, 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
|
1046 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
|
1047 node = node if node else NS_MICROBLOG |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1048 client = self.host.get_client(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
|
1049 data = data_format.deserialise(data) |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1050 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
|
1051 |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1052 async def send( |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1053 self, |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1054 client: SatXMPPEntity, |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1055 data: dict, |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1056 service: Optional[jid.JID] = None, |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1057 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
|
1058 ) -> 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
|
1059 """Send XEP-0277's microblog data |
1419
be2df1ddea8e
plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1060 |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1061 @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
|
1062 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
|
1063 @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
|
1064 None to publish on profile's PEP |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1065 @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
|
1066 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
|
1067 @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
|
1068 """ |
1699 | 1069 # 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
|
1070 # 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
|
1071 if service is None: |
37a1193d90db
plugin XEP-0277: add a trigger to `send` method:
Goffi <goffi@goffi.org>
parents:
3848
diff
changeset
|
1072 service = client.jid.userhostJID() |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
1073 if node is None: |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
1074 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
|
1075 |
3502
6132d363f0e9
plugin XEP-0277: user friendly ID:
Goffi <goffi@goffi.org>
parents:
3493
diff
changeset
|
1076 item_id = data.get("id") |
6132d363f0e9
plugin XEP-0277: user friendly ID:
Goffi <goffi@goffi.org>
parents:
3493
diff
changeset
|
1077 if item_id is None: |
6132d363f0e9
plugin XEP-0277: user friendly ID:
Goffi <goffi@goffi.org>
parents:
3493
diff
changeset
|
1078 if data.get("user_friendly_id", True): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1079 item_id = self.friendly_id(data) |
4178
cf0ea77f9537
plugin XEP-0277, doc: conflict is now checked and avoided if `user_friendly_id_suffix` is `False`, doc updated
Goffi <goffi@goffi.org>
parents:
4175
diff
changeset
|
1080 if not data.get("user_friendly_id_suffix", True): |
cf0ea77f9537
plugin XEP-0277, doc: conflict is now checked and avoided if `user_friendly_id_suffix` is `False`, doc updated
Goffi <goffi@goffi.org>
parents:
4175
diff
changeset
|
1081 # we have no random suffix, which can lead to conflict, so we check if |
cf0ea77f9537
plugin XEP-0277, doc: conflict is now checked and avoided if `user_friendly_id_suffix` is `False`, doc updated
Goffi <goffi@goffi.org>
parents:
4175
diff
changeset
|
1082 # the item doesn't already exist, and change ID if it's the case. |
cf0ea77f9537
plugin XEP-0277, doc: conflict is now checked and avoided if `user_friendly_id_suffix` is `False`, doc updated
Goffi <goffi@goffi.org>
parents:
4175
diff
changeset
|
1083 try: |
cf0ea77f9537
plugin XEP-0277, doc: conflict is now checked and avoided if `user_friendly_id_suffix` is `False`, doc updated
Goffi <goffi@goffi.org>
parents:
4175
diff
changeset
|
1084 items, __ = await self._p.get_items( |
cf0ea77f9537
plugin XEP-0277, doc: conflict is now checked and avoided if `user_friendly_id_suffix` is `False`, doc updated
Goffi <goffi@goffi.org>
parents:
4175
diff
changeset
|
1085 client, |
cf0ea77f9537
plugin XEP-0277, doc: conflict is now checked and avoided if `user_friendly_id_suffix` is `False`, doc updated
Goffi <goffi@goffi.org>
parents:
4175
diff
changeset
|
1086 service, |
cf0ea77f9537
plugin XEP-0277, doc: conflict is now checked and avoided if `user_friendly_id_suffix` is `False`, doc updated
Goffi <goffi@goffi.org>
parents:
4175
diff
changeset
|
1087 node, |
cf0ea77f9537
plugin XEP-0277, doc: conflict is now checked and avoided if `user_friendly_id_suffix` is `False`, doc updated
Goffi <goffi@goffi.org>
parents:
4175
diff
changeset
|
1088 item_ids = [item_id] |
cf0ea77f9537
plugin XEP-0277, doc: conflict is now checked and avoided if `user_friendly_id_suffix` is `False`, doc updated
Goffi <goffi@goffi.org>
parents:
4175
diff
changeset
|
1089 ) |
cf0ea77f9537
plugin XEP-0277, doc: conflict is now checked and avoided if `user_friendly_id_suffix` is `False`, doc updated
Goffi <goffi@goffi.org>
parents:
4175
diff
changeset
|
1090 except exceptions.NotFound: |
cf0ea77f9537
plugin XEP-0277, doc: conflict is now checked and avoided if `user_friendly_id_suffix` is `False`, doc updated
Goffi <goffi@goffi.org>
parents:
4175
diff
changeset
|
1091 pass |
cf0ea77f9537
plugin XEP-0277, doc: conflict is now checked and avoided if `user_friendly_id_suffix` is `False`, doc updated
Goffi <goffi@goffi.org>
parents:
4175
diff
changeset
|
1092 else: |
cf0ea77f9537
plugin XEP-0277, doc: conflict is now checked and avoided if `user_friendly_id_suffix` is `False`, doc updated
Goffi <goffi@goffi.org>
parents:
4175
diff
changeset
|
1093 # the item already exists |
cf0ea77f9537
plugin XEP-0277, doc: conflict is now checked and avoided if `user_friendly_id_suffix` is `False`, doc updated
Goffi <goffi@goffi.org>
parents:
4175
diff
changeset
|
1094 log.info( |
cf0ea77f9537
plugin XEP-0277, doc: conflict is now checked and avoided if `user_friendly_id_suffix` is `False`, doc updated
Goffi <goffi@goffi.org>
parents:
4175
diff
changeset
|
1095 f"there is already an item with ID {item_id}, we have to " |
cf0ea77f9537
plugin XEP-0277, doc: conflict is now checked and avoided if `user_friendly_id_suffix` is `False`, doc updated
Goffi <goffi@goffi.org>
parents:
4175
diff
changeset
|
1096 ' set the "user_friendly_id_suffix" flag.' |
cf0ea77f9537
plugin XEP-0277, doc: conflict is now checked and avoided if `user_friendly_id_suffix` is `False`, doc updated
Goffi <goffi@goffi.org>
parents:
4175
diff
changeset
|
1097 ) |
cf0ea77f9537
plugin XEP-0277, doc: conflict is now checked and avoided if `user_friendly_id_suffix` is `False`, doc updated
Goffi <goffi@goffi.org>
parents:
4175
diff
changeset
|
1098 data["user_friendly_id_suffix"] = True |
cf0ea77f9537
plugin XEP-0277, doc: conflict is now checked and avoided if `user_friendly_id_suffix` is `False`, doc updated
Goffi <goffi@goffi.org>
parents:
4175
diff
changeset
|
1099 item_id = self.friendly_id(data) |
2227
79d279d1ee88
plugin XEP-0277: comments node access model changes:
Goffi <goffi@goffi.org>
parents:
2218
diff
changeset
|
1100 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1101 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1102 await self._manage_comments(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
|
1103 except error.StanzaError: |
3028 | 1104 log.warning("Can't create comments node for item {}".format(item_id)) |
4023
78b5f356900c
component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents:
4020
diff
changeset
|
1105 item = await self.mb_data_2_entry_elt(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
|
1106 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1107 if not await self.host.trigger.async_point( |
3861
37a1193d90db
plugin XEP-0277: add a trigger to `send` method:
Goffi <goffi@goffi.org>
parents:
3848
diff
changeset
|
1108 "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
|
1109 ): |
37a1193d90db
plugin XEP-0277: add a trigger to `send` method:
Goffi <goffi@goffi.org>
parents:
3848
diff
changeset
|
1110 return None |
37a1193d90db
plugin XEP-0277: add a trigger to `send` method:
Goffi <goffi@goffi.org>
parents:
3848
diff
changeset
|
1111 |
3957
b8ab6da58ac8
plugin XEP-0277: `signed` flag can now be used in `extra` to use sign the blog post:
Goffi <goffi@goffi.org>
parents:
3949
diff
changeset
|
1112 extra = {} |
3972
5fbdf986670c
plugin pte: Pubsub Target Encryption implementation:
Goffi <goffi@goffi.org>
parents:
3957
diff
changeset
|
1113 for key in ("encrypted", "encrypted_for", "signed"): |
3957
b8ab6da58ac8
plugin XEP-0277: `signed` flag can now be used in `extra` to use sign the blog post:
Goffi <goffi@goffi.org>
parents:
3949
diff
changeset
|
1114 value = data.get(key) |
b8ab6da58ac8
plugin XEP-0277: `signed` flag can now be used in `extra` to use sign the blog post:
Goffi <goffi@goffi.org>
parents:
3949
diff
changeset
|
1115 if value is not None: |
b8ab6da58ac8
plugin XEP-0277: `signed` flag can now be used in `extra` to use sign the blog post:
Goffi <goffi@goffi.org>
parents:
3949
diff
changeset
|
1116 extra[key] = value |
3934
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3931
diff
changeset
|
1117 |
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3931
diff
changeset
|
1118 await self._p.publish(client, service, node, [item], extra=extra) |
3848
e9c380ef41c8
plugin XEP-0277: return ID of published item in `send` and bridge's `mbSend`
Goffi <goffi@goffi.org>
parents:
3840
diff
changeset
|
1119 return item_id |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1120 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1121 def _mb_repeat( |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1122 self, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1123 service_s: str, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1124 node: str, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1125 item: str, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1126 extra_s: str, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1127 profile_key: str |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1128 ) -> defer.Deferred: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1129 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
|
1130 node = node if node else NS_MICROBLOG |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1131 client = self.host.get_client(profile_key) |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1132 extra = data_format.deserialise(extra_s) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1133 d = defer.ensureDeferred( |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1134 self.repeat(client, item, service, node, extra) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1135 ) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1136 # [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
|
1137 d.addCallback(lambda ret: ret or "") |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1138 return d |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1139 |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1140 async def repeat( |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1141 self, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1142 client: SatXMPPEntity, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1143 item: str, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1144 service: Optional[jid.JID] = None, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1145 node: str = NS_MICROBLOG, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1146 extra: Optional[dict] = None, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1147 ) -> Optional[str]: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1148 """Re-publish a post from somewhere else |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1149 |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1150 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
|
1151 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
|
1152 """ |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1153 if service is None: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1154 service = client.jid.userhostJID() |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1155 |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1156 # we first get the post to repeat |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1157 items, __ = await self._p.get_items( |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1158 client, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1159 service, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1160 node, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1161 item_ids = [item] |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1162 ) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1163 if not items: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1164 raise exceptions.NotFound( |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1165 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
|
1166 ) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1167 item_elt = items[0] |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1168 try: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1169 entry_elt = next(item_elt.elements(NS_ATOM, "entry")) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1170 except StopIteration: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1171 raise exceptions.DataError( |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1172 "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
|
1173 ) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1174 |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1175 # 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
|
1176 try: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1177 author_elt = next(entry_elt.elements(NS_ATOM, "author")) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1178 except StopIteration: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1179 author_elt = entry_elt.addElement("author") |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1180 |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1181 try: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1182 next(author_elt.elements(NS_ATOM, "name")) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1183 except StopIteration: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1184 author_elt.addElement("name", content=service.user) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1185 |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1186 try: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1187 next(author_elt.elements(NS_ATOM, "uri")) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1188 except StopIteration: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1189 entry_elt.addElement( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1190 "uri", content=xmpp_uri.build_xmpp_uri(None, path=service.full()) |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1191 ) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1192 |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1193 # 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
|
1194 link_elt = entry_elt.addElement("link") |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1195 link_elt["rel"] = "via" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1196 link_elt["href"] = xmpp_uri.build_xmpp_uri( |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1197 "pubsub", path=service.full(), node=node, item=item |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1198 ) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1199 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1200 return await self._p.send_item( |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1201 client, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1202 client.jid.userhostJID(), |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1203 NS_MICROBLOG, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1204 entry_elt |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1205 ) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1206 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1207 def _mb_preview(self, service, node, data, profile_key): |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1208 service = jid.JID(service) if service else None |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1209 node = node if node else NS_MICROBLOG |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1210 client = self.host.get_client(profile_key) |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1211 data = data_format.deserialise(data) |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1212 d = defer.ensureDeferred(self.preview(client, data, service, node)) |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1213 d.addCallback(data_format.serialise) |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1214 return d |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1215 |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1216 async def preview( |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1217 self, |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1218 client: SatXMPPEntity, |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1219 data: dict, |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1220 service: Optional[jid.JID] = None, |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1221 node: Optional[str] = NS_MICROBLOG |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1222 ) -> dict: |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1223 """Preview microblog data without publishing them |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1224 |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1225 params are the same as for [send] |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1226 @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
|
1227 """ |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1228 if node is None: |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1229 node = NS_MICROBLOG |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1230 |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1231 item_id = data.get("id", "") |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1232 |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1233 # we have to serialise then deserialise to be sure that all triggers are called |
4023
78b5f356900c
component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents:
4020
diff
changeset
|
1234 item_elt = await self.mb_data_2_entry_elt(client, data, item_id, service, node) |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1235 item_elt.uri = pubsub.NS_PUBSUB |
4023
78b5f356900c
component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents:
4020
diff
changeset
|
1236 return await self.item_2_mb_data(client, item_elt, service, node) |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1237 |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1238 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1239 ## retract ## |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1240 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1241 def _mb_retract(self, service_jid_s, nodeIdentifier, itemIdentifier, profile_key): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1242 """Call self._p._retract_item, but use default node if node is empty""" |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1243 return self._p._retract_item( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1244 service_jid_s, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1245 nodeIdentifier or NS_MICROBLOG, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1246 itemIdentifier, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1247 True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1248 profile_key, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1249 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1250 |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
1251 ## get ## |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
1252 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1253 def _mb_get_serialise(self, data): |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1254 items, metadata = data |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1255 metadata['items'] = items |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1256 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
|
1257 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1258 def _mb_get(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
|
1259 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
|
1260 """ |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1261 @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
|
1262 @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
|
1263 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1264 client = self.host.get_client(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
|
1265 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
|
1266 max_items = None if max_items == C.NO_LIMIT else max_items |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1267 extra = self._p.parse_extra(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
|
1268 d = defer.ensureDeferred( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1269 self.mb_get(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
|
1270 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
|
1271 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1272 d.addCallback(self._mb_get_serialise) |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1273 return d |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
1274 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1275 async def mb_get( |
3949
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1276 self, |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1277 client: SatXMPPEntity, |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1278 service: Optional[jid.JID] = None, |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1279 node: Optional[str] = None, |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1280 max_items: Optional[int] = 10, |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1281 item_ids: Optional[List[str]] = None, |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1282 rsm_request: Optional[rsm.RSMRequest] = None, |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1283 extra: Optional[Dict[str, Any]] = None |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1284 ) -> Tuple[List[Dict[str, Any]], Dict[str, Any]]: |
1516
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
1285 """Get some microblogs |
1419
be2df1ddea8e
plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1286 |
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
|
1287 @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
|
1288 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
|
1289 @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
|
1290 @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
|
1291 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
|
1292 @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
|
1293 @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
|
1294 @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
|
1295 |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
1296 @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
|
1297 """ |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1298 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
|
1299 node = NS_MICROBLOG |
3591
d830c11eeef3
plugin XEP-0277: ignore `max_items` if `rsm_request` is set
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
1300 if rsm_request: |
d830c11eeef3
plugin XEP-0277: ignore `max_items` if `rsm_request` is set
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
1301 max_items = None |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1302 items_data = await self._p.get_items( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1303 client, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1304 service, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1305 node, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1306 max_items=max_items, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1307 item_ids=item_ids, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1308 rsm_request=rsm_request, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1309 extra=extra, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1310 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1311 mb_data_list, metadata = await self._p.trans_items_data_d( |
4023
78b5f356900c
component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents:
4020
diff
changeset
|
1312 items_data, partial(self.item_2_mb_data, client, service=service, node=node)) |
3949
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1313 encrypted = metadata.pop("encrypted", None) |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1314 if encrypted is not None: |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1315 for mb_data in mb_data_list: |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1316 try: |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1317 mb_data["encrypted"] = encrypted[mb_data["id"]] |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1318 except KeyError: |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1319 pass |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1320 return (mb_data_list, metadata) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1321 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1322 def _mb_rename(self, service, node, item_id, new_id, profile_key): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1323 return defer.ensureDeferred(self.mb_rename( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1324 self.host.get_client(profile_key), |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1325 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
|
1326 node or None, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1327 item_id, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1328 new_id |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1329 )) |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1330 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1331 async def mb_rename( |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1332 self, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1333 client: SatXMPPEntity, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1334 service: Optional[jid.JID], |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1335 node: Optional[str], |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1336 item_id: str, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1337 new_id: str |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1338 ) -> None: |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1339 if not node: |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1340 node = NS_MICROBLOG |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1341 await self._p.rename_item(client, service, node, item_id, new_id) |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1342 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1343 def parse_comment_url(self, node_url): |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
1344 """Parse a XMPP URI |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
1345 |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
1346 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
|
1347 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
|
1348 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
|
1349 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
|
1350 @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
|
1351 """ |
3643
30196b9a2b4c
plugin XEP-0277: use `common.uri` to parse comment URIs
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1352 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1353 parsed_url = xmpp_uri.parse_xmpp_uri(node_url) |
3643
30196b9a2b4c
plugin XEP-0277: use `common.uri` to parse comment URIs
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1354 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
|
1355 node = parsed_url["node"] |
30196b9a2b4c
plugin XEP-0277: use `common.uri` to parse comment URIs
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1356 except Exception as e: |
30196b9a2b4c
plugin XEP-0277: use `common.uri` to parse comment URIs
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1357 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
|
1358 |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
1359 return (service, node) |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
1360 |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
1361 ## configure ## |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
1362 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1363 def mb_access_set(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
|
1364 """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
|
1365 |
304 | 1366 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
|
1367 @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
|
1368 @param profile_key: profile key |
6a2fa651d7fa
plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents:
2160
diff
changeset
|
1369 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1370 # FIXME: check if this mehtod is need, deprecate it if not |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1371 client = self.host.get_client(profile_key) |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1372 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1373 _options = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1374 self._p.OPT_ACCESS_MODEL: access, |
4018
86efd854dee1
plugin XEP-0277: ensure that `max-items` is set to `max` when creating a node
Goffi <goffi@goffi.org>
parents:
4011
diff
changeset
|
1375 self._p.OPT_MAX_ITEMS: "max", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1376 self._p.OPT_PERSIST_ITEMS: 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1377 self._p.OPT_DELIVER_PAYLOADS: 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1378 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1379 } |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1380 |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1381 def cb(result): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1382 # Node is created with right permission |
3028 | 1383 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
|
1384 |
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1385 def fatal_err(s_error): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1386 # Something went wrong |
3028 | 1387 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
|
1388 raise NodeAccessChangeException() |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1389 |
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1390 def err_cb(s_error): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1391 # If the node already exists, the condition is "conflict", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1392 # else we have an unmanaged error |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1393 if s_error.value.condition == "conflict": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1394 # 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
|
1395 # d.addCallback(lambda x: create_node().addCallback(cb).addErrback(fatal_err)) |
304 | 1396 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
|
1397 else: |
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1398 fatal_err(s_error) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1399 |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1400 def create_node(): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1401 return self._p.createNode( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1402 client, client.jid.userhostJID(), NS_MICROBLOG, _options |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1403 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1404 |
304 | 1405 def change_node_options(): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1406 return self._p.setOptions( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1407 client.jid.userhostJID(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1408 NS_MICROBLOG, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1409 client.jid.userhostJID(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1410 _options, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1411 profile_key=profile_key, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1412 ) |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1413 |
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1414 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
|
1415 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1416 ## 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
|
1417 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1418 # common |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1419 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1420 def _get_client_and_node_data(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
|
1421 """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
|
1422 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1423 @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
|
1424 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
|
1425 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
|
1426 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
|
1427 @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
|
1428 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
|
1429 @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
|
1430 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1431 client = self.host.get_client(profile_key) |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1432 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
|
1433 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
|
1434 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1435 jids_set = client.roster.get_jids_set(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
|
1436 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
|
1437 try: |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1438 # display messages from salut-a-toi@libervia.org or other PEP services |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1439 services = self.host.plugins["EXTRA-PEP"].get_followed_entities( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1440 profile_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1441 ) |
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
|
1442 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
|
1443 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
|
1444 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
|
1445 if services: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1446 log.debug( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1447 "Extra PEP followed entities: %s" |
3028 | 1448 % ", ".join([str(service) for service in services]) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1449 ) |
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
|
1450 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
|
1451 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1452 node_data = [] |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1453 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
|
1454 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
|
1455 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
|
1456 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1457 def _check_publishers(self, publishers_type, publishers): |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1458 """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
|
1459 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1460 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
|
1461 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
|
1462 @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
|
1463 """ |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1464 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
|
1465 if publishers: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1466 raise failure.Failure( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1467 ValueError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1468 "Can't use publishers with {} type".format(publishers_type) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1469 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1470 ) |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1471 else: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1472 publishers = None |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1473 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
|
1474 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
|
1475 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
|
1476 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1477 # subscribe # |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1478 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1479 def _mb_subscribe_to_many(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
|
1480 """ |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1481 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1482 @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
|
1483 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1484 publishers_type, publishers = self._check_publishers(publishers_type, publishers) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1485 return self.mb_subscribe_to_many(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
|
1486 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1487 def mb_subscribe_to_many(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
|
1488 """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
|
1489 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1490 @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
|
1491 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
|
1492 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
|
1493 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
|
1494 @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
|
1495 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
|
1496 @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
|
1497 @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
|
1498 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1499 client, node_data = self._get_client_and_node_data( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1500 publishers_type, publishers, profile_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1501 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1502 return self._p.subscribe_to_many( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1503 node_data, client.jid.userhostJID(), profile_key=profile_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1504 ) |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1505 |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1506 # get # |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1507 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1508 def _mb_get_from_many_rt_result(self, session_id, profile_key=C.PROF_KEY_DEFAULT): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1509 """Get real-time results for mb_get_from_many session |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1510 |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1511 @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
|
1512 @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
|
1513 - 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
|
1514 - 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
|
1515 - service (unicode): pubsub service |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1516 - node (unicode): pubsub node |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1517 - failure (unicode): empty string in case of success, error message else |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1518 - items_data(list): data as returned by [mb_get] |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1519 - items_metadata(dict): metadata as returned by [mb_get] |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1520 @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
|
1521 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1522 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1523 client = self.host.get_client(profile_key) |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1524 |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1525 def onSuccess(items_data): |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1526 """convert items elements to list of microblog data in items_data""" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1527 d = self._p.trans_items_data_d( |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1528 items_data, |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1529 # FIXME: service and node should be used here |
4023
78b5f356900c
component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents:
4020
diff
changeset
|
1530 partial(self.item_2_mb_data, client), |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1531 serialise=True |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1532 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1533 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
|
1534 return d |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1535 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1536 d = self._p.get_rt_results( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1537 session_id, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1538 on_success=onSuccess, |
3028 | 1539 on_error=lambda failure: (str(failure.value), ([], {})), |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1540 profile=client.profile, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1541 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1542 d.addCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1543 lambda ret: ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1544 ret[0], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1545 [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1546 (service.full(), node, failure, items, metadata) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1547 for (service, node), (success, (failure, (items, metadata))) in ret[ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1548 1 |
3028 | 1549 ].items() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1550 ], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1551 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1552 ) |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1553 return d |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1554 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1555 def _mb_get_from_many(self, publishers_type, publishers, max_items=10, extra_dict=None, |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1556 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
|
1557 """ |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1558 @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
|
1559 """ |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1560 max_items = None if max_items == C.NO_LIMIT else max_items |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1561 publishers_type, publishers = self._check_publishers(publishers_type, publishers) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1562 extra = self._p.parse_extra(extra_dict) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1563 return self.mb_get_from_many( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1564 publishers_type, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1565 publishers, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1566 max_items, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1567 extra.rsm_request, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1568 extra.extra, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1569 profile_key, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1570 ) |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1571 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1572 def mb_get_from_many(self, publishers_type, publishers, max_items=None, rsm_request=None, |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1573 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
|
1574 """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
|
1575 |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1576 @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
|
1577 "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
|
1578 @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
|
1579 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
|
1580 @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
|
1581 @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
|
1582 @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
|
1583 @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
|
1584 @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
|
1585 """ |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1586 # XXX: extra is unused here so far |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1587 client, node_data = self._get_client_and_node_data( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1588 publishers_type, publishers, profile_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1589 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1590 return self._p.get_from_many( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1591 node_data, max_items, rsm_request, profile_key=profile_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1592 ) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1593 |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1594 # comments # |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1595 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1596 def _mb_get_from_many_with_comments_rt_result_serialise(self, data): |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1597 """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
|
1598 |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1599 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
|
1600 @param data(dict): data as received by rt_sessions |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1601 @return (tuple): see [_mb_get_from_many_with_comments_rt_result] |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1602 """ |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1603 ret = [] |
3028 | 1604 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
|
1605 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
|
1606 items = [] |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1607 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
|
1608 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
|
1609 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
|
1610 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
|
1611 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
|
1612 node, |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1613 failure_, |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1614 items, |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1615 metadata)) |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1616 |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1617 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
|
1618 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1619 def _mb_get_from_many_with_comments_rt_result(self, session_id, |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1620 profile_key=C.PROF_KEY_DEFAULT): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1621 """Get real-time results for [mb_get_from_many_with_comments] session |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1622 |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1623 @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
|
1624 @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
|
1625 - 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
|
1626 - 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
|
1627 - 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
|
1628 - 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
|
1629 - 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
|
1630 - 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
|
1631 - 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
|
1632 - 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
|
1633 - 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
|
1634 - 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
|
1635 - 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
|
1636 - 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
|
1637 - 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
|
1638 - 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
|
1639 @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
|
1640 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1641 profile = self.host.get_client(profile_key).profile |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1642 d = self.rt_sessions.get_results(session_id, profile=profile) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1643 d.addCallback(self._mb_get_from_many_with_comments_rt_result_serialise) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1644 return d |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1645 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1646 def _mb_get_from_many_with_comments(self, publishers_type, publishers, max_items=10, |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1647 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
|
1648 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
|
1649 """ |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1650 @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
|
1651 @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
|
1652 limit |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1653 """ |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1654 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
|
1655 max_comments = None if max_comments == C.NO_LIMIT else max_comments |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1656 publishers_type, publishers = self._check_publishers(publishers_type, publishers) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1657 extra = self._p.parse_extra(extra_dict) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1658 extra_comments = self._p.parse_extra(extra_comments_dict) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1659 return self.mb_get_from_many_with_comments( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1660 publishers_type, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1661 publishers, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1662 max_items, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1663 max_comments or None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1664 extra.rsm_request, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1665 extra.extra, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1666 extra_comments.rsm_request, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1667 extra_comments.extra, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1668 profile_key, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1669 ) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1670 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1671 def mb_get_from_many_with_comments(self, publishers_type, publishers, max_items=None, |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1672 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
|
1673 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
|
1674 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
|
1675 """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
|
1676 |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1677 @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
|
1678 "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
|
1679 @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
|
1680 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
|
1681 @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
|
1682 @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
|
1683 @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
|
1684 @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
|
1685 @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
|
1686 @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
|
1687 @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
|
1688 @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
|
1689 """ |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1690 # 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
|
1691 # 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
|
1692 # 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
|
1693 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1694 client, node_data = self._get_client_and_node_data( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1695 publishers_type, publishers, profile_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1696 ) |
2360
72cbb6478f97
plugin XEP-0060: use client instead of profile_key in getItems
Goffi <goffi@goffi.org>
parents:
2341
diff
changeset
|
1697 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1698 def get_comments(items_data): |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1699 """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
|
1700 |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1701 @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
|
1702 @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
|
1703 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
|
1704 """ |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1705 items, metadata = items_data |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1706 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
|
1707 for item in items: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1708 dlist = [] # deferred list for comments |
3028 | 1709 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
|
1710 # we look for comments |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1711 if key.startswith("comments") and key.endswith("_service"): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1712 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
|
1713 service_s = value |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1714 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
|
1715 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
|
1716 # 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
|
1717 d = defer.ensureDeferred( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1718 self._p.get_items( |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1719 client, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1720 service, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1721 node, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1722 max_comments, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1723 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
|
1724 extra=extra_comments, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1725 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1726 ) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1727 # then serialise |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1728 d.addCallback( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1729 lambda items_data: self._p.trans_items_data_d( |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1730 items_data, |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1731 partial( |
4023
78b5f356900c
component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents:
4020
diff
changeset
|
1732 self.item_2_mb_data, client, service=service, node=node |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1733 ), |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1734 serialise=True |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1735 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1736 ) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1737 # with failure handling |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1738 d.addCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1739 lambda serialised_items_data: ("",) + serialised_items_data |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1740 ) |
3028 | 1741 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
|
1742 # 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
|
1743 # comments nodes) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1744 d.addCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1745 lambda serialised, service_s=service_s, node=node: ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1746 service_s, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1747 node, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1748 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1749 + serialised |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1750 ) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1751 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
|
1752 # 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
|
1753 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
|
1754 # and add them to the item data |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1755 comments_d.addCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1756 lambda comments_data, item=item: (item, comments_data) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1757 ) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1758 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
|
1759 # 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
|
1760 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
|
1761 # 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
|
1762 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
|
1763 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
|
1764 |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1765 deferreds = {} |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1766 for service, node in node_data: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1767 d = deferreds[(service, node)] = defer.ensureDeferred(self._p.get_items( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1768 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
|
1769 )) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1770 d.addCallback( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1771 lambda items_data: self._p.trans_items_data_d( |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1772 items_data, |
4023
78b5f356900c
component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents:
4020
diff
changeset
|
1773 partial(self.item_2_mb_data, client, service=service, node=node), |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1774 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1775 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1776 d.addCallback(get_comments) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1777 d.addCallback(lambda items_comments_data: ("", items_comments_data)) |
3028 | 1778 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
|
1779 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1780 return self.rt_sessions.new_session(deferreds, client.profile) |
2341
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
1781 |
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
1782 |
3028 | 1783 @implementer(iwokkel.IDisco) |
2341
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
1784 class XEP_0277_handler(XMPPHandler): |
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
1785 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1786 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
|
1787 return [disco.DiscoFeature(NS_MICROBLOG)] |
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
1788 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1789 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
|
1790 return [] |