annotate libervia/backend/plugins/plugin_xep_0277.py @ 4281:9e63e02318ec

core: show warning instead of exception in case of missing dependency when loading plugins
author Goffi <goffi@goffi.org>
date Fri, 12 Jul 2024 18:53:00 +0200
parents 0d7bb4df2343
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
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
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3341
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
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
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
271 node: Optional[str],
3328
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] = {}
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
286 mb_data: Dict[str, Any] = {"service": service.full(), "extra": extra}
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
287
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
288 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
289 """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
290
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 @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
292 @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
293 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
294 @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
295 (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
296 """
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
297 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
298 if not increment:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
299 raise failure.Failure(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
300 exceptions.DataError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
301 "key {} is already present for item {}"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
302 ).format(key, item_elt["id"])
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
303 )
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
304 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
305 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
306 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
307 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
308 while new_key in mb_data:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
309 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
310 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
311 key = new_key
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
312 return key
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
313
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
314 @defer.inlineCallbacks
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
315 def parseElement(elem):
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
316 """Parse title/content elements and fill microblog_data accordingly"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
317 type_ = elem.getAttribute("type")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
318 if type_ == "xhtml":
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
319 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
320 if data_elt is None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
321 raise failure.Failure(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
322 exceptions.DataError(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
323 "XHML content not wrapped in a <div/> element, this is not "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
324 "standard !"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
325 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
326 )
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
327 if data_elt.uri != C.NS_XHTML:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
328 raise failure.Failure(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
329 exceptions.DataError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
330 _("Content of type XHTML must declare its namespace!")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
331 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
332 )
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
333 key = check_conflict("{}_xhtml".format(elem.name))
1791
1359ad0b37c2 reverted patch 3770d13776e8
Goffi <goffi@goffi.org>
parents: 1779
diff changeset
334 data = data_elt.toXml()
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
335 mb_data[key] = yield self.host.plugins["TEXT_SYNTAXES"].clean_xhtml(data)
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
336 else:
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
337 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
338 mb_data[key] = str(elem)
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
339
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
340 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
341 mb_data["id"] = id_
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
342 if item_elt.uri not in (pubsub.NS_PUBSUB, NS_PUBSUB_EVENT):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
343 msg = "Unsupported namespace {ns} in pubsub item {id_}".format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
344 ns=item_elt.uri, id_=id_
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
345 )
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
346 log.warning(msg)
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
347 raise failure.Failure(exceptions.DataError(msg))
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
348
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
349 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
350 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
351 except StopIteration:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
352 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
353 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
354
3328
d49607e3a066 plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents: 3308
diff changeset
355 # uri
d49607e3a066 plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents: 3308
diff changeset
356 # 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
357 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
358 mb_data["node"] = node
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
359 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
360 "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
361 path=service.full(),
3328
d49607e3a066 plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents: 3308
diff changeset
362 node=node,
d49607e3a066 plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents: 3308
diff changeset
363 item=id_,
d49607e3a066 plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents: 3308
diff changeset
364 )
d49607e3a066 plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents: 3308
diff changeset
365
2264
a8eaaac4d80f plugin XEP-0277, tools/common/data_objects: language handling
Goffi <goffi@goffi.org>
parents: 2243
diff changeset
366 # language
a8eaaac4d80f plugin XEP-0277, tools/common/data_objects: language handling
Goffi <goffi@goffi.org>
parents: 2243
diff changeset
367 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
368 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
369 except KeyError:
a8eaaac4d80f plugin XEP-0277, tools/common/data_objects: language handling
Goffi <goffi@goffi.org>
parents: 2243
diff changeset
370 pass
a8eaaac4d80f plugin XEP-0277, tools/common/data_objects: language handling
Goffi <goffi@goffi.org>
parents: 2243
diff changeset
371
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
372 # 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
373 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
374 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
375 except StopIteration:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
376 msg = "No atom id found in the pubsub item {}, this is not standard !".format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
377 id_
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
378 )
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
379 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
380 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
381 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
382 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
383
d5e72362ee91 plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
384 # 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
385
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
386 # 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
387 # 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
388 # 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
389 # 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
390 # 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
391 # 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
392 # 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
393 # 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
394 # raise failure.Failure(exceptions.DataError(msg))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
395 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
396 if not title_elts:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
397 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
398 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
399 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
400 yield parseElement(title_elt)
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
401
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
402 # 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
403 # 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
404 # if more than one can be present
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
405 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
406 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
407
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
408 # we check that text content is present
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
409 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
410 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
411 log.warning(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
412 "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
413 id_=id_, key=key
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
414 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
415 )
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
416 # ... 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
417 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
418 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
419 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
420 self.host.plugins["TEXT_SYNTAXES"].SYNTAX_TEXT,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
421 False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
422 )
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
423
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
424 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
425 # 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
426 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
427 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
428 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
429 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
430 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
431
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
432 # 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
433 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
434 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
435 except StopIteration:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
436 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
437 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
438 mb_data["updated"] = calendar.timegm(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
439 dateutil.parser.parse(str(updated_elt)).utctimetuple()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
440 )
302
9f3a6cf91668 plugin xep-0277: added getLastMicroblogs method
Goffi <goffi@goffi.org>
parents: 297
diff changeset
441 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
442 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
443 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
444 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
445 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
446 mb_data["published"] = calendar.timegm(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
447 dateutil.parser.parse(str(published_elt)).utctimetuple()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
448 )
859
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents: 858
diff changeset
449
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
450 # links
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
451 comments = mb_data["comments"] = []
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
452 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
453 href = link_elt.getAttribute("href")
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
454 if not href:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
455 log.warning(f"missing href in <link> element: {link_elt.toXml()}")
4020
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
456 continue
3840
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
457 rel = link_elt.getAttribute("rel")
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
458 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
459 uri = href
3308
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
460 comments_data = {
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
461 "uri": uri,
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
462 }
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
463 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
464 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
465 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
466 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
467 continue
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
468 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
469 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
470 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
471 comments.append(comments_data)
3840
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
472 elif rel == "via":
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
473 try:
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
474 repeater_jid = jid.JID(item_elt["publisher"])
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
475 except (KeyError, RuntimeError):
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
476 try:
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
477 # 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
478 # has not parent
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
479 top_elt = item_elt.parent
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
480 while top_elt.parent is not None:
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
481 top_elt = top_elt.parent
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
482 repeater_jid = jid.JID(top_elt["from"])
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
483 except (AttributeError, RuntimeError):
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
484 # 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
485 # stanza available
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
486 log.error(f"Can't find repeater of the post: {item_elt.toXml()}")
3840
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
487 continue
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
488
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
489 extra["repeated"] = {"by": repeater_jid.full(), "uri": href}
4020
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
490 elif rel in ("related", "enclosure"):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
491 attachment: Dict[str, Any] = {"sources": [{"url": href}]}
4020
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
492 if rel == "related":
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
493 attachment["external"] = True
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
494 for attr, key in (
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
495 ("type", "media_type"),
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
496 ("title", "desc"),
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
497 ):
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
498 value = link_elt.getAttribute(attr)
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
499 if value:
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
500 attachment[key] = value
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
501 try:
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
502 attachment["size"] = int(link_elt.attributes["lenght"])
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
503 except (KeyError, ValueError):
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
504 pass
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
505 if "media_type" not in attachment:
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
506 media_type = guess_type(href, False)[0]
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
507 if media_type is not None:
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
508 attachment["media_type"] = media_type
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
509
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
510 attachments = extra.setdefault("attachments", [])
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
511 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
512 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
513 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
514 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
515 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
516 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
517 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
518 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
519 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
520 )
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
521 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
522 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
523 log.warning(f"Unmanaged link element: {link_elt.toXml()}")
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
524
1453
d5e72362ee91 plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
525 # author
3492
fa796612adad plugin XEP-0277: better resilience to broken items:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
526 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
527 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
528 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
529 except StopIteration:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
530 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
531 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
532 # name
770
64dd7c0f4feb plugin groupblog, XEP-0277: store both published and updated timestamps
souliane <souliane@mailoo.org>
parents: 745
diff changeset
533 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
534 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
535 except StopIteration:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
536 log.warning(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
537 "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
538 )
3724
a0c08fcfe11e plugin XEP-0277: various fixes + async:
Goffi <goffi@goffi.org>
parents: 3680
diff changeset
539 author = None
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
540 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
541 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
542 # 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
543 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
544 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
545 except StopIteration:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
546 log.debug("No uri element found in author element of item {}".format(id_))
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
547 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
548 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
549 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
550 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
551 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
552 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
553 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
554 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
555 mb_data["author_jid"] = item_elt.getAttribute("publisher") or ""
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 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
557 # 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
558 # 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
559 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
560 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
561 except Exception as e:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
562 log.warning(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
563 f"No author name found, and can't parse author jid: {e}"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
564 )
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
565
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
566 if not publisher:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
567 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
568 mb_data["author_jid_verified"] = False
1681
c6c835046681 plugin XEP-0277: minor fixes for publisher attribute
Goffi <goffi@goffi.org>
parents: 1680
diff changeset
569 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
570 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
571 else:
3840
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
572 if "repeated" not in extra:
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
573 log.warning(
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
574 "item atom:uri differ from publisher attribute, spoofing "
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
575 "attempt ? atom:uri = {} publisher = {}".format(
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
576 uri, item_elt.getAttribute("publisher")
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
577 )
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
578 )
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_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
580 # 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
581 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
582 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
583 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
584 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
585 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
586 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
587
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
588 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
589 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
590 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
591 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
592 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
593 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
594 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
595 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
596
3492
fa796612adad plugin XEP-0277: better resilience to broken items:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
597 # categories
fa796612adad plugin XEP-0277: better resilience to broken items:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
598 categories = [
fa796612adad plugin XEP-0277: better resilience to broken items:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
599 category_elt.getAttribute("term", "")
fa796612adad plugin XEP-0277: better resilience to broken items:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
600 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
601 ]
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
602 mb_data["tags"] = categories
1664
5d0ff155be1a plugin XEP-0277: tags are handled through atom categories
Goffi <goffi@goffi.org>
parents: 1661
diff changeset
603
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
604 ## 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
605 # if other plugins have things to add or change
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
606 yield self.host.trigger.point("XEP-0277_item2data", item_elt, entry_elt, mb_data)
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
607
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
608 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
609
4023
78b5f356900c component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents: 4020
diff changeset
610 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
611 """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
612
3840
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
613 @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
614 @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
615 @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
616 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
617 @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
618 Needed to construct Atom id
1419
be2df1ddea8e plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
619 @return: deferred which fire domish.Element
be2df1ddea8e plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
620 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
621 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
622 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
623
2264
a8eaaac4d80f plugin XEP-0277, tools/common/data_objects: language handling
Goffi <goffi@goffi.org>
parents: 2243
diff changeset
624 ## language ##
3840
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
625 if "language" in mb_data:
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
626 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
627
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
628 ## 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
629 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
630
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
631 for elem_name in ("title", "content"):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
632 for type_ in ["", "_rich", "_xhtml"]:
4020
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
633 attr = f"{elem_name}{type_}"
3840
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
634 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
635 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
636 if type_:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
637 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
638 xml_content = await synt.convert(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
639 mb_data[attr],
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
640 synt.get_current_syntax(client.profile),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
641 "XHTML",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
642 )
4020
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
643 if f"{elem_name}_xhtml" in mb_data:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
644 raise failure.Failure(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
645 exceptions.DataError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
646 _(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
647 "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
648 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
649 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
650 )
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
651 else:
3840
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
652 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
653
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
654 div_elt = xml_tools.ElementParser()(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
655 xml_content, namespace=C.NS_XHTML
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
656 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
657 if (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
658 div_elt.name != "div"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
659 or div_elt.uri != C.NS_XHTML
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
660 or div_elt.attributes
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
661 ):
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
662 # 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
663 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
664 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
665 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
666 elem.addChild(div_elt)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
667 elem["type"] = "xhtml"
3840
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
668 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
669 # 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
670 # 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
671 elem_txt = entry_elt.addElement(elem_name)
3724
a0c08fcfe11e plugin XEP-0277: various fixes + async:
Goffi <goffi@goffi.org>
parents: 3680
diff changeset
672 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
673 "TEXT_SYNTAXES"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
674 ].convert(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
675 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
676 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
677 self.host.plugins["TEXT_SYNTAXES"].SYNTAX_TEXT,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
678 False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
679 )
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
680 elem_txt.addContent(text_content)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
681 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
682
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
683 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
684 elem.addContent(mb_data[attr])
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
685 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
686
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
687 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
688 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
689 except StopIteration:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
690 # 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
691 # so we transform content element to title
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
692 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
693 if not elems:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
694 raise exceptions.DataError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
695 "There must be at least one content or title element"
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 for elem in elems:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
698 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
699
4020
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
700 ## attachments ##
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
701 attachments = extra.get(C.KEY_ATTACHMENTS)
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
702 if attachments:
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
703 for attachment in attachments:
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
704 try:
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
705 url = attachment["url"]
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
706 except KeyError:
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
707 try:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
708 url = next(s["url"] for s in attachment["sources"] if "url" in s)
4020
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
709 except (StopIteration, KeyError):
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
710 log.warning(
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
711 f'"url" missing in attachment, ignoring: {attachment}'
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
712 )
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
713 continue
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
714
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
715 if not url.startswith("http"):
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
716 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
717 continue
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
718 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
719 # 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
720 link_elt["href"] = url
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
721 if attachment.get("external", False):
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
722 # 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
723 link_elt["rel"] = "related"
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
724 else:
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
725 # this is an attached file
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
726 link_elt["rel"] = "enclosure"
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
727 for key, attr in (
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
728 ("media_type", "type"),
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
729 ("desc", "title"),
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
730 ("size", "lenght"),
4020
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 value = attachment.get(key)
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
733 if value:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
734 link_elt[attr] = str(value)
4020
d8a1219e913f plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents: 4018
diff changeset
735
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
736 ## 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
737 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
738 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
739 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
740 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
741 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
742 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
743 node=quote(node, safe=""),
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
744 item=quote(item_id, safe=""),
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
745 )
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
746
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
747 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
748 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
749 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
750
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
751 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
752 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
753 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
754 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
755 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
756 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
757 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
758
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 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
760
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
761 ## author ##
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
762 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
763 try:
3840
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
764 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
765 except KeyError:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
766 # 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
767 author_name = client.jid.user
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
768 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
769
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
770 try:
3840
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
771 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
772 except KeyError:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
773 author_jid_s = client.jid.userhost()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
774 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
775
1820
3c8cf120a0fd plugin XEP-0277: added missing author_email parsing
Goffi <goffi@goffi.org>
parents: 1817
diff changeset
776 try:
3840
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
777 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
778 except KeyError:
3c8cf120a0fd plugin XEP-0277: added missing author_email parsing
Goffi <goffi@goffi.org>
parents: 1817
diff changeset
779 pass
3c8cf120a0fd plugin XEP-0277: added missing author_email parsing
Goffi <goffi@goffi.org>
parents: 1817
diff changeset
780
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
781 ## 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
782 current_time = time.time()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
783 entry_elt.addElement(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
784 "updated",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
785 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
786 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
787 entry_elt.addElement(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
788 "published",
3840
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
789 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
790 )
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
791
1664
5d0ff155be1a plugin XEP-0277: tags are handled through atom categories
Goffi <goffi@goffi.org>
parents: 1661
diff changeset
792 ## categories ##
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
793 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
794 category_elt = entry_elt.addElement("category")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
795 category_elt["term"] = tag
1664
5d0ff155be1a plugin XEP-0277: tags are handled through atom categories
Goffi <goffi@goffi.org>
parents: 1661
diff changeset
796
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
797 ## id ##
3840
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
798 entry_id = mb_data.get(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
799 "id",
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
800 xmpp_uri.build_xmpp_uri(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
801 "pubsub",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
802 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
803 node=node,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
804 item=item_id,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
805 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
806 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
807 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
808
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
809 ## comments ##
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
810 for comments_data in mb_data.get("comments", []):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
811 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
812 # 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
813 try:
c86a22009c1f plugin XEP-0277: fix comments node handling when parent node doesn't exist.
Goffi <goffi@goffi.org>
parents: 4178
diff changeset
814 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
815 except KeyError:
c86a22009c1f plugin XEP-0277: fix comments node handling when parent node doesn't exist.
Goffi <goffi@goffi.org>
parents: 4178
diff changeset
816 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
817 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
818 else:
c86a22009c1f plugin XEP-0277: fix comments node handling when parent node doesn't exist.
Goffi <goffi@goffi.org>
parents: 4178
diff changeset
819 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
820 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
821
3840
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
822 if "repeated" in extra:
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
823 try:
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
824 repeated = extra["repeated"]
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
825 link_elt = entry_elt.addElement("link")
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
826 link_elt["rel"] = "via"
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
827 link_elt["href"] = repeated["uri"]
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
828 except KeyError as e:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
829 log.warning(f"invalid repeated element({e}): {extra['repeated']}")
3840
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
830
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
831 ## 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
832 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
833
96ee986dab3c plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents: 1656
diff changeset
834 ## the trigger ##
96ee986dab3c plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents: 1656
diff changeset
835 # 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
836 self.host.trigger.point(
3840
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
837 "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
838 )
1661
96ee986dab3c plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents: 1656
diff changeset
839
3724
a0c08fcfe11e plugin XEP-0277: various fixes + async:
Goffi <goffi@goffi.org>
parents: 3680
diff changeset
840 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
841
3513
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
842 ## publish/preview ##
1421
16b1ba7ccaaa plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
843
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
844 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
845 """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
846 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
847
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
848 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
849 """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
850
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
851 @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
852 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
853 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
854 raise ValueError("This node is not a comment node")
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
855 return item_id[len(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
856
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
857 def get_comments_node(self, item_id):
1821
d6062afdd54f plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents: 1820
diff changeset
858 """Generate comment node
d6062afdd54f plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents: 1820
diff changeset
859
d6062afdd54f plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents: 1820
diff changeset
860 @param item_id(unicode): id of the parent item
d6062afdd54f plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents: 1820
diff changeset
861 @return (unicode): comment node to use
d6062afdd54f plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents: 1820
diff changeset
862 """
3598
d390ff50af0f plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents: 3591
diff changeset
863 return f"{NS_COMMENT_PREFIX}{item_id}"
1821
d6062afdd54f plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents: 1820
diff changeset
864
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
865 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
866 """Get prefered PubSub service to create comment node
d6062afdd54f plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents: 1820
diff changeset
867
d6062afdd54f plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents: 1820
diff changeset
868 @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
869 @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
870 """
2433
014feb75092d plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents: 2415
diff changeset
871 if parent_service is not None:
014feb75092d plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents: 2415
diff changeset
872 if parent_service.user:
014feb75092d plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents: 2415
diff changeset
873 # we are on a PEP
014feb75092d plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents: 2415
diff changeset
874 if parent_service.host == client.jid.host:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
875 #  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
876 pass
014feb75092d plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents: 2415
diff changeset
877 else:
014feb75092d plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents: 2415
diff changeset
878 # 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
879 d = self.host.find_service_entity(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
880 client, "pubsub", "service", parent_service
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
881 )
2433
014feb75092d plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents: 2415
diff changeset
882 d.addCallback(lambda entity: entity or parent_service)
014feb75092d plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents: 2415
diff changeset
883 else:
014feb75092d plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents: 2415
diff changeset
884 # 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
885 return defer.succeed(parent_service)
014feb75092d plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents: 2415
diff changeset
886
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
887 return defer.succeed(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
888 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
889 )
1821
d6062afdd54f plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents: 1820
diff changeset
890
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
891 async def _manage_comments(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
892 self, client, mb_data, service, node, item_id, access=None
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
893 ):
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
894 """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
895
3308
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
896 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
897 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
898 @param mb_data(dict): microblog mb_data
1821
d6062afdd54f plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents: 1820
diff changeset
899 @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
900 @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
901 @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
902 @param access(unicode, None): access model
79d279d1ee88 plugin XEP-0277: comments node access model changes:
Goffi <goffi@goffi.org>
parents: 2218
diff changeset
903 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
904 """
2807
0b7ce5daee9b plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents: 2780
diff changeset
905 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
906 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
907 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
908 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
909 else:
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
910 # 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
911 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
912 elif allow_comments == False:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
913 if "comments" in mb_data:
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
914 log.warning(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
915 "comments are not allowed but there is already a comments node, "
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
916 "it may be lost: {uri}".format(uri=mb_data["comments"])
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
917 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
918 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
919 return
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
920
3308
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
921 # 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
922 # handle this in a list
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
923 if len(mb_data.setdefault("comments", [])) == 0:
3308
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
924 # we need at least one comment node
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
925 mb_data["comments"].append({})
3308
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
926
2227
79d279d1ee88 plugin XEP-0277: comments node access model changes:
Goffi <goffi@goffi.org>
parents: 2218
diff changeset
927 if access is None:
79d279d1ee88 plugin XEP-0277: comments node access model changes:
Goffi <goffi@goffi.org>
parents: 2218
diff changeset
928 # 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
929 try:
c86a22009c1f plugin XEP-0277: fix comments node handling when parent node doesn't exist.
Goffi <goffi@goffi.org>
parents: 4178
diff changeset
930 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
931 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
932 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
933 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
934 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
935 access = parent_node_config.get(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
936 self._p.OPT_ACCESS_MODEL, self._p.ACCESS_OPEN
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
937 )
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
938
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
939 options = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
940 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
941 self._p.OPT_MAX_ITEMS: "max",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
942 self._p.OPT_PERSIST_ITEMS: 1,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
943 self._p.OPT_DELIVER_PAYLOADS: 1,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
944 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
945 # 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
946 self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
947 }
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
948
1661
96ee986dab3c plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents: 1656
diff changeset
949 # 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
950 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
951
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
952 for comments_data in mb_data["comments"]:
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
953 uri = comments_data.get("uri")
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
954 comments_node = comments_data.get("node")
3308
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
955 try:
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
956 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
957 except KeyError:
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
958 comments_service = None
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
959
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
960 if uri:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
961 uri_service, uri_node = self.parse_comment_url(uri)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
962 if (comments_node is not None and comments_node != uri_node) or (
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
963 comments_service is not None and comments_service != uri_service
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
964 ):
3308
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
965 raise ValueError(
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
966 f"Incoherence between comments URI ({uri}) and comments_service "
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
967 f"({comments_service}) or comments_node ({comments_node})"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
968 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
969 comments_data["service"] = comments_service = uri_service
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
970 comments_data["node"] = comments_node = uri_node
3308
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
971 else:
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
972 if not comments_node:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
973 comments_node = self.get_comments_node(item_id)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
974 comments_data["node"] = comments_node
3308
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
975 if comments_service is None:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
976 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
977 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
978 comments_service = client.jid.userhostJID()
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
979 comments_data["service"] = comments_service
3308
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
980
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
981 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
982 "pubsub",
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
983 path=comments_service.full(),
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
984 node=comments_node,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
985 )
1821
d6062afdd54f plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents: 1820
diff changeset
986
3308
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
987 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
988 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
989 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
990 if e.condition == "conflict":
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
991 log.info(
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
992 "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
993 comments_node, comments_service
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
994 )
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
995 )
3308
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
996 else:
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
997 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
998 else:
3308
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
999 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
1000 # 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
1001 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
1002 client, service, node
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
1003 )
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
1004 # …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
1005 # 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
1006 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
1007 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
1008 comments_affiliations[jid_] = "publisher"
2286
330f8d4e2ad4 plugin XEP-0277: change affiliations for comments + fixes:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
1009
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1010 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
1011 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
1012 )
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
1013
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1014 def friendly_id(self, data):
3513
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1015 """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
1016 # 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
1017 id_base = regex.url_friendly_text(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1018 data.get("title")
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1019 or data.get("title_rich")
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1020 or data.get("content")
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1021 or data.get("content_rich")
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1022 or ""
3519
02eec2a5b5f9 plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents: 3513
diff changeset
1023 )
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
1024 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
1025 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
1026 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
1027 return f"{id_base}-{token_urlsafe(3)}"
3513
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1028
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1029 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
1030 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
1031 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
1032 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
1033 data = data_format.deserialise(data)
3513
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1034 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
1035
3513
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1036 async def send(
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1037 self,
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1038 client: SatXMPPEntity,
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1039 data: dict,
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1040 service: Optional[jid.JID] = None,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1041 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
1042 ) -> 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
1043 """Send XEP-0277's microblog data
1419
be2df1ddea8e plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1044
3513
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1045 @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
1046 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
1047 @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
1048 None to publish on profile's PEP
3513
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1049 @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
1050 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
1051 @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
1052 """
1699
a72f04c67ac9 plugin XEP-0277: just a reminder
Goffi <goffi@goffi.org>
parents: 1681
diff changeset
1053 # 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
1054 # 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
1055 if service is None:
37a1193d90db plugin XEP-0277: add a trigger to `send` method:
Goffi <goffi@goffi.org>
parents: 3848
diff changeset
1056 service = client.jid.userhostJID()
1821
d6062afdd54f plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents: 1820
diff changeset
1057 if node is None:
d6062afdd54f plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents: 1820
diff changeset
1058 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
1059
3502
6132d363f0e9 plugin XEP-0277: user friendly ID:
Goffi <goffi@goffi.org>
parents: 3493
diff changeset
1060 item_id = data.get("id")
6132d363f0e9 plugin XEP-0277: user friendly ID:
Goffi <goffi@goffi.org>
parents: 3493
diff changeset
1061 if item_id is None:
6132d363f0e9 plugin XEP-0277: user friendly ID:
Goffi <goffi@goffi.org>
parents: 3493
diff changeset
1062 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
1063 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
1064 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
1065 # 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
1066 # 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
1067 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
1068 items, __ = await self._p.get_items(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1069 client, service, node, item_ids=[item_id]
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
1070 )
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
1071 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
1072 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
1073 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
1074 # 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
1075 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
1076 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
1077 ' 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
1078 )
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
1079 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
1080 item_id = self.friendly_id(data)
2227
79d279d1ee88 plugin XEP-0277: comments node access model changes:
Goffi <goffi@goffi.org>
parents: 2218
diff changeset
1081
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
1082 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1083 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
1084 except error.StanzaError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
1085 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
1086 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
1087
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1088 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
1089 "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
1090 ):
37a1193d90db plugin XEP-0277: add a trigger to `send` method:
Goffi <goffi@goffi.org>
parents: 3848
diff changeset
1091 return None
37a1193d90db plugin XEP-0277: add a trigger to `send` method:
Goffi <goffi@goffi.org>
parents: 3848
diff changeset
1092
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
1093 extra = {}
3972
5fbdf986670c plugin pte: Pubsub Target Encryption implementation:
Goffi <goffi@goffi.org>
parents: 3957
diff changeset
1094 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
1095 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
1096 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
1097 extra[key] = value
3934
e345d93fb6e5 plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
1098
e345d93fb6e5 plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
1099 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
1100 return item_id
3513
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1101
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1102 def _mb_repeat(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1103 self, service_s: str, node: str, item: str, extra_s: str, profile_key: str
3840
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1104 ) -> defer.Deferred:
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1105 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
1106 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
1107 client = self.host.get_client(profile_key)
3840
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1108 extra = data_format.deserialise(extra_s)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1109 d = defer.ensureDeferred(self.repeat(client, item, service, node, extra))
3840
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1110 # [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
1111 d.addCallback(lambda ret: ret or "")
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1112 return d
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1113
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1114 async def repeat(
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1115 self,
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1116 client: SatXMPPEntity,
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1117 item: str,
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1118 service: Optional[jid.JID] = None,
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1119 node: str = NS_MICROBLOG,
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1120 extra: Optional[dict] = None,
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1121 ) -> Optional[str]:
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1122 """Re-publish a post from somewhere else
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1123
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1124 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
1125 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
1126 """
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1127 if service is None:
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1128 service = client.jid.userhostJID()
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1129
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1130 # we first get the post to repeat
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1131 items, __ = await self._p.get_items(client, service, node, item_ids=[item])
3840
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1132 if not items:
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1133 raise exceptions.NotFound(
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1134 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
1135 )
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1136 item_elt = items[0]
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1137 try:
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1138 entry_elt = next(item_elt.elements(NS_ATOM, "entry"))
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1139 except StopIteration:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1140 raise exceptions.DataError("post to repeat is not a XEP-0277 blog item")
3840
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1141
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1142 # 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
1143 try:
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1144 author_elt = next(entry_elt.elements(NS_ATOM, "author"))
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1145 except StopIteration:
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1146 author_elt = entry_elt.addElement("author")
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1147
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1148 try:
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1149 next(author_elt.elements(NS_ATOM, "name"))
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1150 except StopIteration:
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1151 author_elt.addElement("name", content=service.user)
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 try:
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1154 next(author_elt.elements(NS_ATOM, "uri"))
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1155 except StopIteration:
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1156 entry_elt.addElement(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1157 "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
1158 )
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1159
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1160 # 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
1161 link_elt = entry_elt.addElement("link")
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1162 link_elt["rel"] = "via"
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1163 link_elt["href"] = xmpp_uri.build_xmpp_uri(
3840
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1164 "pubsub", path=service.full(), node=node, item=item
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1165 )
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1166
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1167 return await self._p.send_item(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1168 client, client.jid.userhostJID(), NS_MICROBLOG, entry_elt
3840
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1169 )
5b192a5eb72d plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents: 3763
diff changeset
1170
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1171 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
1172 service = jid.JID(service) if service else None
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1173 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
1174 client = self.host.get_client(profile_key)
3513
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1175 data = data_format.deserialise(data)
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1176 d = defer.ensureDeferred(self.preview(client, data, service, node))
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1177 d.addCallback(data_format.serialise)
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1178 return d
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1179
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1180 async def preview(
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1181 self,
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1182 client: SatXMPPEntity,
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1183 data: dict,
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1184 service: Optional[jid.JID] = None,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1185 node: Optional[str] = NS_MICROBLOG,
3513
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1186 ) -> dict:
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1187 """Preview microblog data without publishing them
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1188
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1189 params are the same as for [send]
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1190 @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
1191 """
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1192 if node is None:
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1193 node = NS_MICROBLOG
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1194
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1195 item_id = data.get("id", "")
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1196
753d151da886 XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents: 3502
diff changeset
1197 # 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
1198 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
1199 item_elt.uri = pubsub.NS_PUBSUB
4023
78b5f356900c component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents: 4020
diff changeset
1200 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
1201
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
1202 ## retract ##
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
1203
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1204 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
1205 """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
1206 return self._p._retract_item(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1207 service_jid_s,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1208 nodeIdentifier or NS_MICROBLOG,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1209 itemIdentifier,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1210 True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1211 profile_key,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1212 )
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
1213
1421
16b1ba7ccaaa plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
1214 ## get ##
16b1ba7ccaaa plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
1215
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1216 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
1217 items, metadata = data
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1218 metadata["items"] = items
3308
384283adcce1 plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
1219 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
1220
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1221 def _mb_get(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1222 self,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1223 service="",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1224 node="",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1225 max_items=10,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1226 item_ids=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1227 extra="",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1228 profile_key=C.PROF_KEY_NONE,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1229 ):
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
1230 """
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
1231 @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
1232 @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
1233 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1234 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
1235 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
1236 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
1237 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
1238 d = defer.ensureDeferred(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1239 self.mb_get(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1240 client,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1241 service,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1242 node or None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1243 max_items,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1244 item_ids,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1245 extra.rsm_request,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1246 extra.extra,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1247 )
3584
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3550
diff changeset
1248 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1249 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
1250 return d
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
1251
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1252 async def mb_get(
3949
f7ff893b536e plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents: 3934
diff changeset
1253 self,
f7ff893b536e plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents: 3934
diff changeset
1254 client: SatXMPPEntity,
f7ff893b536e plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents: 3934
diff changeset
1255 service: Optional[jid.JID] = None,
f7ff893b536e plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents: 3934
diff changeset
1256 node: Optional[str] = None,
f7ff893b536e plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents: 3934
diff changeset
1257 max_items: Optional[int] = 10,
f7ff893b536e plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents: 3934
diff changeset
1258 item_ids: Optional[List[str]] = None,
f7ff893b536e plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents: 3934
diff changeset
1259 rsm_request: Optional[rsm.RSMRequest] = None,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1260 extra: Optional[Dict[str, Any]] = None,
3949
f7ff893b536e plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents: 3934
diff changeset
1261 ) -> 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
1262 """Get some microblogs
1419
be2df1ddea8e plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1263
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
1264 @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
1265 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
1266 @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
1267 @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
1268 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
1269 @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
1270 @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
1271 @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
1272
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
1273 @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
1274 """
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
1275 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
1276 node = NS_MICROBLOG
3591
d830c11eeef3 plugin XEP-0277: ignore `max_items` if `rsm_request` is set
Goffi <goffi@goffi.org>
parents: 3586
diff changeset
1277 if rsm_request:
d830c11eeef3 plugin XEP-0277: ignore `max_items` if `rsm_request` is set
Goffi <goffi@goffi.org>
parents: 3586
diff changeset
1278 max_items = None
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1279 items_data = await self._p.get_items(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1280 client,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1281 service,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1282 node,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1283 max_items=max_items,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1284 item_ids=item_ids,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1285 rsm_request=rsm_request,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1286 extra=extra,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1287 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1288 mb_data_list, metadata = await self._p.trans_items_data_d(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1289 items_data, partial(self.item_2_mb_data, client, service=service, node=node)
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1290 )
3949
f7ff893b536e plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents: 3934
diff changeset
1291 encrypted = metadata.pop("encrypted", None)
f7ff893b536e plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents: 3934
diff changeset
1292 if encrypted is not None:
f7ff893b536e plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents: 3934
diff changeset
1293 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
1294 try:
f7ff893b536e plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents: 3934
diff changeset
1295 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
1296 except KeyError:
f7ff893b536e plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents: 3934
diff changeset
1297 pass
f7ff893b536e plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents: 3934
diff changeset
1298 return (mb_data_list, metadata)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
1299
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1300 def _mb_rename(self, service, node, item_id, new_id, profile_key):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1301 return defer.ensureDeferred(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1302 self.mb_rename(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1303 self.host.get_client(profile_key),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1304 jid.JID(service) if service else None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1305 node or None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1306 item_id,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1307 new_id,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1308 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1309 )
3519
02eec2a5b5f9 plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents: 3513
diff changeset
1310
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1311 async def mb_rename(
3519
02eec2a5b5f9 plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents: 3513
diff changeset
1312 self,
02eec2a5b5f9 plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents: 3513
diff changeset
1313 client: SatXMPPEntity,
02eec2a5b5f9 plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents: 3513
diff changeset
1314 service: Optional[jid.JID],
02eec2a5b5f9 plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents: 3513
diff changeset
1315 node: Optional[str],
02eec2a5b5f9 plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents: 3513
diff changeset
1316 item_id: str,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1317 new_id: str,
3519
02eec2a5b5f9 plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents: 3513
diff changeset
1318 ) -> None:
02eec2a5b5f9 plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents: 3513
diff changeset
1319 if not node:
02eec2a5b5f9 plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents: 3513
diff changeset
1320 node = NS_MICROBLOG
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1321 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
1322
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1323 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
1324 """Parse a XMPP URI
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
1325
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1421
diff changeset
1326 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
1327 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
1328 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
1329 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
1330 @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
1331 """
3643
30196b9a2b4c plugin XEP-0277: use `common.uri` to parse comment URIs
Goffi <goffi@goffi.org>
parents: 3550
diff changeset
1332 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1333 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
1334 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
1335 node = parsed_url["node"]
30196b9a2b4c plugin XEP-0277: use `common.uri` to parse comment URIs
Goffi <goffi@goffi.org>
parents: 3550
diff changeset
1336 except Exception as e:
30196b9a2b4c plugin XEP-0277: use `common.uri` to parse comment URIs
Goffi <goffi@goffi.org>
parents: 3550
diff changeset
1337 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
1338
16b1ba7ccaaa plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
1339 return (service, node)
16b1ba7ccaaa plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
1340
16b1ba7ccaaa plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
1341 ## configure ##
16b1ba7ccaaa plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
1342
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1343 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
1344 """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
1345
304
e04ccf122bb6 microblog sending
Goffi <goffi@goffi.org>
parents: 303
diff changeset
1346 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
1347 @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
1348 @param profile_key: profile key
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2160
diff changeset
1349 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1350 #  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
1351 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
1352
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1353 _options = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1354 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
1355 self._p.OPT_MAX_ITEMS: "max",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1356 self._p.OPT_PERSIST_ITEMS: 1,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1357 self._p.OPT_DELIVER_PAYLOADS: 1,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1358 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1359 }
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
1360
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 302
diff changeset
1361 def cb(result):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1362 # Node is created with right permission
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
1363 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
1364
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 302
diff changeset
1365 def fatal_err(s_error):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1366 # Something went wrong
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
1367 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
1368 raise NodeAccessChangeException()
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 302
diff changeset
1369
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 302
diff changeset
1370 def err_cb(s_error):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1371 # If the node already exists, the condition is "conflict",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1372 # else we have an unmanaged error
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1373 if s_error.value.condition == "conflict":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1374 # 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
1375 # d.addCallback(lambda x: create_node().addCallback(cb).addErrback(fatal_err))
304
e04ccf122bb6 microblog sending
Goffi <goffi@goffi.org>
parents: 303
diff changeset
1376 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
1377 else:
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 302
diff changeset
1378 fatal_err(s_error)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
1379
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 302
diff changeset
1380 def create_node():
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1381 return self._p.createNode(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1382 client, client.jid.userhostJID(), NS_MICROBLOG, _options
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1383 )
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
1384
304
e04ccf122bb6 microblog sending
Goffi <goffi@goffi.org>
parents: 303
diff changeset
1385 def change_node_options():
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1386 return self._p.setOptions(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1387 client.jid.userhostJID(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1388 NS_MICROBLOG,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1389 client.jid.userhostJID(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1390 _options,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1391 profile_key=profile_key,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1392 )
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 302
diff changeset
1393
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 302
diff changeset
1394 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
1395
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
1396 ## 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
1397
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
1398 # common
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
1399
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1400 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
1401 """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
1402
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
1403 @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
1404 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
1405 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
1406 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
1407 @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
1408 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
1409 @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
1410 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1411 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
1412 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
1413 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
1414 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1415 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
1416 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
1417 try:
0b7ce5daee9b plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents: 2780
diff changeset
1418 # 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
1419 services = self.host.plugins["EXTRA-PEP"].get_followed_entities(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1420 profile_key
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1421 )
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
1422 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
1423 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
1424 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
1425 if services:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1426 log.debug(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1427 "Extra PEP followed entities: %s"
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
1428 % ", ".join([str(service) for service in services])
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1429 )
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
1430 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
1431
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
1432 node_data = []
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
1433 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
1434 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
1435 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
1436
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1437 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
1438 """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
1439
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
1440 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
1441 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
1442 @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
1443 """
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
1444 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
1445 if publishers:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1446 raise failure.Failure(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1447 ValueError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1448 "Can't use publishers with {} type".format(publishers_type)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1449 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1450 )
1450
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
1451 else:
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
1452 publishers = None
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
1453 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
1454 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
1455 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
1456
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
1457 # subscribe #
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
1458
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1459 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
1460 """
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
1461
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
1462 @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
1463 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1464 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
1465 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
1466
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1467 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
1468 """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
1469
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
1470 @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
1471 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
1472 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
1473 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
1474 @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
1475 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
1476 @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
1477 @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
1478 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1479 client, node_data = self._get_client_and_node_data(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1480 publishers_type, publishers, profile_key
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1481 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1482 return self._p.subscribe_to_many(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1483 node_data, client.jid.userhostJID(), profile_key=profile_key
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1484 )
1450
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
1485
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1486 # get #
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1487
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1488 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
1489 """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
1490
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1491 @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
1492 @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
1493 - 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
1494 - 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
1495 - service (unicode): pubsub service
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1496 - node (unicode): pubsub node
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1497 - 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
1498 - 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
1499 - 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
1500 @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
1501 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1502
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1503 client = self.host.get_client(profile_key)
3328
d49607e3a066 plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents: 3308
diff changeset
1504
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1505 def onSuccess(items_data):
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1506 """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
1507 d = self._p.trans_items_data_d(
3328
d49607e3a066 plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents: 3308
diff changeset
1508 items_data,
d49607e3a066 plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents: 3308
diff changeset
1509 # FIXME: service and node should be used here
4023
78b5f356900c component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents: 4020
diff changeset
1510 partial(self.item_2_mb_data, client),
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1511 serialise=True,
3328
d49607e3a066 plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents: 3308
diff changeset
1512 )
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1513 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
1514 return d
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1515
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1516 d = self._p.get_rt_results(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1517 session_id,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1518 on_success=onSuccess,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
1519 on_error=lambda failure: (str(failure.value), ([], {})),
3328
d49607e3a066 plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents: 3308
diff changeset
1520 profile=client.profile,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1521 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1522 d.addCallback(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1523 lambda ret: (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1524 ret[0],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1525 [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1526 (service.full(), node, failure, items, metadata)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1527 for (service, node), (success, (failure, (items, metadata))) in ret[
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1528 1
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
1529 ].items()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1530 ],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1531 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1532 )
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1533 return d
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1534
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1535 def _mb_get_from_many(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1536 self,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1537 publishers_type,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1538 publishers,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1539 max_items=10,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1540 extra_dict=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1541 profile_key=C.PROF_KEY_NONE,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1542 ):
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1543 """
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
1544 @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
1545 """
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
1546 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
1547 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
1548 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
1549 return self.mb_get_from_many(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1550 publishers_type,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1551 publishers,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1552 max_items,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1553 extra.rsm_request,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1554 extra.extra,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1555 profile_key,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1556 )
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1557
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1558 def mb_get_from_many(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1559 self,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1560 publishers_type,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1561 publishers,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1562 max_items=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1563 rsm_request=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1564 extra=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1565 profile_key=C.PROF_KEY_NONE,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1566 ):
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1567 """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
1568
2807
0b7ce5daee9b plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents: 2780
diff changeset
1569 @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
1570 "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
1571 @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
1572 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
1573 @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
1574 @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
1575 @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
1576 @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
1577 @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
1578 """
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
1579 # 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
1580 client, node_data = self._get_client_and_node_data(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1581 publishers_type, publishers, profile_key
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1582 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1583 return self._p.get_from_many(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1584 node_data, max_items, rsm_request, profile_key=profile_key
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1585 )
1454
4e2fab4de195 plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents: 1453
diff changeset
1586
4e2fab4de195 plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents: 1453
diff changeset
1587 # comments #
4e2fab4de195 plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents: 1453
diff changeset
1588
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1589 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
1590 """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
1591
0b7ce5daee9b plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents: 2780
diff changeset
1592 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
1593 @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
1594 @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
1595 """
0b7ce5daee9b plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents: 2780
diff changeset
1596 ret = []
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
1597 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
1598 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
1599 items = []
0b7ce5daee9b plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents: 2780
diff changeset
1600 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
1601 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
1602 items.append((item, item_metadata))
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1603 ret.append((service.full(), node, failure_, items, 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
1604
0b7ce5daee9b plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents: 2780
diff changeset
1605 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
1606
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1607 def _mb_get_from_many_with_comments_rt_result(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1608 self, session_id, profile_key=C.PROF_KEY_DEFAULT
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1609 ):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1610 """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
1611
4e2fab4de195 plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents: 1453
diff changeset
1612 @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
1613 @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
1614 - 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
1615 - 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
1616 - 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
1617 - 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
1618 - 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
1619 - 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
1620 - 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
1621 - 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
1622 - 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
1623 - 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
1624 - 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
1625 - 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
1626 - 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
1627 - 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
1628 @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
1629 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1630 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
1631 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
1632 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
1633 return d
4e2fab4de195 plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents: 1453
diff changeset
1634
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1635 def _mb_get_from_many_with_comments(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1636 self,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1637 publishers_type,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1638 publishers,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1639 max_items=10,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1640 max_comments=C.NO_LIMIT,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1641 extra_dict=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1642 extra_comments_dict=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1643 profile_key=C.PROF_KEY_NONE,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1644 ):
1454
4e2fab4de195 plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents: 1453
diff changeset
1645 """
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1454
diff changeset
1646 @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
1647 @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
1648 limit
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 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
1651 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
1652 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
1653 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
1654 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
1655 return self.mb_get_from_many_with_comments(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1656 publishers_type,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1657 publishers,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1658 max_items,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1659 max_comments or None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1660 extra.rsm_request,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1661 extra.extra,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1662 extra_comments.rsm_request,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1663 extra_comments.extra,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1664 profile_key,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1665 )
1454
4e2fab4de195 plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents: 1453
diff changeset
1666
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1667 def mb_get_from_many_with_comments(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1668 self,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1669 publishers_type,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1670 publishers,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1671 max_items=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1672 max_comments=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1673 rsm_request=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1674 extra=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1675 rsm_comments=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1676 extra_comments=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1677 profile_key=C.PROF_KEY_NONE,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1678 ):
1454
4e2fab4de195 plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents: 1453
diff changeset
1679 """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
1680
2807
0b7ce5daee9b plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents: 2780
diff changeset
1681 @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
1682 "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
1683 @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
1684 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
1685 @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
1686 @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
1687 @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
1688 @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
1689 @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
1690 @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
1691 @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
1692 @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
1693 """
4e2fab4de195 plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents: 1453
diff changeset
1694 # 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
1695 # 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
1696 # 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
1697
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1698 client, node_data = self._get_client_and_node_data(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1699 publishers_type, publishers, profile_key
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1700 )
2360
72cbb6478f97 plugin XEP-0060: use client instead of profile_key in getItems
Goffi <goffi@goffi.org>
parents: 2341
diff changeset
1701
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1702 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
1703 """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
1704
4e2fab4de195 plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents: 1453
diff changeset
1705 @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
1706 @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
1707 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
1708 """
4e2fab4de195 plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents: 1453
diff changeset
1709 items, metadata = items_data
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1710 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
1711 for item in items:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1712 dlist = [] # deferred list for comments
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
1713 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
1714 # we look for comments
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1715 if key.startswith("comments") and key.endswith("_service"):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1716 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
1717 service_s = value
3328
d49607e3a066 plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents: 3308
diff changeset
1718 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
1719 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
1720 # 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
1721 d = defer.ensureDeferred(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1722 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
1723 client,
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3550
diff changeset
1724 service,
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3550
diff changeset
1725 node,
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3550
diff changeset
1726 max_comments,
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3550
diff changeset
1727 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
1728 extra=extra_comments,
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3550
diff changeset
1729 )
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1730 )
1454
4e2fab4de195 plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents: 1453
diff changeset
1731 # then serialise
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1732 d.addCallback(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1733 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
1734 items_data,
d49607e3a066 plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents: 3308
diff changeset
1735 partial(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1736 self.item_2_mb_data,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1737 client,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1738 service=service,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1739 node=node,
3328
d49607e3a066 plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents: 3308
diff changeset
1740 ),
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1741 serialise=True,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1742 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1743 )
1454
4e2fab4de195 plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents: 1453
diff changeset
1744 # with failure handling
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1745 d.addCallback(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1746 lambda serialised_items_data: ("",) + serialised_items_data
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1747 )
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
1748 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
1749 # 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
1750 # comments nodes)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1751 d.addCallback(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1752 lambda serialised, service_s=service_s, node=node: (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1753 service_s,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1754 node,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1755 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1756 + serialised
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 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
1759 # 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
1760 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
1761 # and add them to the item data
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1762 comments_d.addCallback(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1763 lambda comments_data, item=item: (item, comments_data)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1764 )
1454
4e2fab4de195 plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents: 1453
diff changeset
1765 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
1766 # 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
1767 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
1768 # 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
1769 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
1770 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
1771
4e2fab4de195 plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents: 1453
diff changeset
1772 deferreds = {}
4e2fab4de195 plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents: 1453
diff changeset
1773 for service, node in node_data:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1774 d = deferreds[(service, node)] = defer.ensureDeferred(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1775 self._p.get_items(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1776 client, service, node, max_items, rsm_request=rsm_request, extra=extra
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1777 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4186
diff changeset
1778 )
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1779 d.addCallback(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1780 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
1781 items_data,
4023
78b5f356900c component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents: 4020
diff changeset
1782 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
1783 )
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1784 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1785 d.addCallback(get_comments)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1786 d.addCallback(lambda items_comments_data: ("", items_comments_data))
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
1787 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
1788
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
1789 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
1790
f9580b4a105a plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents: 2322
diff changeset
1791
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
1792 @implementer(iwokkel.IDisco)
2341
f9580b4a105a plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents: 2322
diff changeset
1793 class XEP_0277_handler(XMPPHandler):
f9580b4a105a plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents: 2322
diff changeset
1794
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1795 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
1796 return [disco.DiscoFeature(NS_MICROBLOG)]
f9580b4a105a plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents: 2322
diff changeset
1797
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1798 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
1799 return []