Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_xep_0277.py @ 4397:6e3a0ef1c561 default tip
plugin XEP-0277: add `mentions` to extra data:
rel 463
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 06 Sep 2025 16:31:24 +0200 |
parents | 7c1d77efc752 |
children |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
3 # SAT plugin for microblogging over XMPP (xep-0277) |
3479 | 4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
9 # (at your option) any later version. |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
14 # GNU Affero General Public License for more details. |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
19 import time |
4175
30f7513e5590
plugin XEP-0277: generate and parse altertate links with the new `alt_links` data in `extra`
Goffi <goffi@goffi.org>
parents:
4172
diff
changeset
|
20 from urllib.parse import quote, urlparse |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
21 import dateutil |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
22 import calendar |
4020
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
23 from mimetypes import guess_type |
3502
6132d363f0e9
plugin XEP-0277: user friendly ID:
Goffi <goffi@goffi.org>
parents:
3493
diff
changeset
|
24 from secrets import token_urlsafe |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
25 from typing import List, Optional, Dict, Self, Tuple, Any, Dict, cast |
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 |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
28 from pydantic import BaseModel, ConfigDict, Field, model_validator |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
29 |
3502
6132d363f0e9
plugin XEP-0277: user friendly ID:
Goffi <goffi@goffi.org>
parents:
3493
diff
changeset
|
30 import shortuuid |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
31 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
|
32 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
|
33 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
|
34 from twisted.internet import defer |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
35 from twisted.python import failure |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
36 |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
37 # 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
|
38 from wokkel import pubsub |
3949
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
39 from wokkel import disco, iwokkel, rsm |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
40 from zope.interface import implementer |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
41 |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
42 from libervia.backend import G |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
43 from libervia.backend.core.i18n import _ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
44 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
|
45 from libervia.backend.core.log import getLogger |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
46 from libervia.backend.core import exceptions |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
47 from libervia.backend.core.core_types import SatXMPPEntity |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
48 from libervia.backend.models.types import JIDType |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
49 from libervia.backend.plugins.plugin_misc_text_syntaxes import TextSyntaxes |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
50 from libervia.backend.plugins.plugin_pubsub_cache import PubsubCache |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
51 from libervia.backend.plugins.plugin_xep_0060 import XEP_0060 |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
52 from libervia.backend.tools import xml_tools |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
53 from libervia.backend.tools import sat_defer |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
54 from libervia.backend.tools import utils |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
55 from libervia.backend.tools.common import data_format |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
56 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
|
57 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
|
58 |
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 |
3179
84a94b385760
bridge: messageSend's extra is now serialised
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
60 log = getLogger(__name__) |
84a94b385760
bridge: messageSend's extra is now serialised
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
61 |
84a94b385760
bridge: messageSend's extra is now serialised
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
62 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
63 NS_MICROBLOG = "urn:xmpp:microblog:0" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
64 NS_ATOM = "http://www.w3.org/2005/Atom" |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
65 NS_ATOM_THREADING = "http://purl.org/syndication/thread/1.0" |
3598
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
66 NS_PUBSUB_EVENT = f"{pubsub.NS_PUBSUB}#event" |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
67 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
|
68 |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 |
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 PLUGIN_INFO = { |
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_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
|
72 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
|
73 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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 C.PI_MAIN: "XEP_0277", |
2341
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
79 C.PI_HANDLER: "yes", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
80 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
|
81 } |
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
83 |
339
b0b773f432e5
plugin XEP-00277: setMicroblogAccess is now asynchronous
Goffi <goffi@goffi.org>
parents:
311
diff
changeset
|
84 class NodeAccessChangeException(Exception): |
b0b773f432e5
plugin XEP-00277: setMicroblogAccess is now asynchronous
Goffi <goffi@goffi.org>
parents:
311
diff
changeset
|
85 pass |
b0b773f432e5
plugin XEP-00277: setMicroblogAccess is now asynchronous
Goffi <goffi@goffi.org>
parents:
311
diff
changeset
|
86 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
87 |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
88 class Comment(BaseModel): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
89 uri: str = "" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
90 service: JIDType | None = None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
91 node: str = "" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
92 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
93 @model_validator(mode='after') |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
94 def set_uri_if_missing(self) -> Self: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
95 if not self.uri and self.service is not None and self.node: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
96 self.uri = xmpp_uri.build_xmpp_uri( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
97 "pubsub", |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
98 path=self.service.full(), |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
99 node=self.node |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
100 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
101 return self |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
102 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
103 class InReplyTo(BaseModel): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
104 ref: str |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
105 href: str|None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
106 type: str|None = None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
107 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
108 class Attachment(BaseModel): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
109 sources: list[dict[str, str]] = Field(default_factory=list) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
110 external: bool = Field( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
111 default=False, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
112 description="If True, this is a link to an external data, such as a website, " |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
113 "otherwise it's an attached file.", |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
114 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
115 media_type: str | None = None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
116 desc: str | None = None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
117 size: int | None = None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
118 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
119 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
120 class AltLink(BaseModel): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
121 url: str |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
122 media_type: str | None = None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
123 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
124 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
125 class Repeated(BaseModel): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
126 by: JIDType |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
127 uri: str |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
128 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
129 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
130 class MbExtra(BaseModel): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
131 """Extra data for microblog posts that accepts arbitrary keys""" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
132 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
133 model_config = ConfigDict(extra="allow") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
134 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
135 repeated: Repeated | None = None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
136 attachments: list[Attachment] = Field(default_factory=list) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
137 alt_links: list[AltLink] = Field(default_factory=list) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
138 # FIXME: Must be moved to pubsub signing plugin. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
139 encrypted: bool = False |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
140 encrypted_for: dict | None = None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
141 signed: bool = False |
4397
6e3a0ef1c561
plugin XEP-0277: add `mentions` to extra data:
Goffi <goffi@goffi.org>
parents:
4383
diff
changeset
|
142 # FIXME: Must be moved to XEP-0372 plugin. |
6e3a0ef1c561
plugin XEP-0277: add `mentions` to extra data:
Goffi <goffi@goffi.org>
parents:
4383
diff
changeset
|
143 mentions: list[JIDType] = Field(default_factory=list) |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
144 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
145 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
146 class MbData(BaseModel): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
147 id: str | None = None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
148 atom_id: str | None = None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
149 service: JIDType | None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
150 node: str = NS_MICROBLOG |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
151 uri: str | None = None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
152 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
153 user_friendly_id: bool = Field(default=True, exclude=True) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
154 user_friendly_id_suffix: bool = Field(default=True, exclude=True) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
155 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
156 published: float | None = None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
157 updated: float | None = None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
158 language: str | None = None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
159 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
160 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
161 title: str | None = None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
162 title_xhtml: str | None = None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
163 title_rich: str | None = Field(default=None, exclude=True) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
164 content: str | None = None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
165 content_xhtml: str | None = None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
166 content_rich: str | None = Field(default=None, exclude=True) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
167 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
168 author: str | None = None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
169 author_jid: JIDType | None = None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
170 author_email: str | None = None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
171 author_jid_verified: bool = False |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
172 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
173 allow_comments: bool | None = None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
174 comments: list[Comment] = Field(default_factory=list) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
175 in_reply_tos: list[InReplyTo]|None = None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
176 tags: list[str] = Field(default_factory=list) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
177 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
178 extra: MbExtra = Field(default_factory=MbExtra) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
179 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
180 @classmethod |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
181 async def from_element( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
182 cls, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
183 client: SatXMPPEntity, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
184 item_elt: domish.Element, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
185 service: jid.JID | None = None, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
186 # FIXME: node is Optional until all calls to item_2_mb_data set properly service |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
187 # and node. Once done, the Optional must be removed here |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
188 node: str | None = None, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
189 ) -> Self: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
190 """Create an MbData instance from a microblog XML element. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
191 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
192 @param item_elt: Microblog item element. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
193 @param service: PubSub service where the item has been retrieved. Profile's PEP is |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
194 used when service is None. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
195 @param node: PubSub node where the item has been retrieved. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
196 If None, "uri" won't be set. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
197 @return: MbData instance. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
198 @raise exceptions.DataError: if the XML is malformed or missing required data |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
199 """ |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
200 text_syntaxes = cast(TextSyntaxes, G.host.plugins["TEXT_SYNTAXES"]) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
201 if service is None: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
202 service = client.jid.userhostJID() |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
203 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
204 # there can be no id for transient nodes |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
205 id_ = item_elt.getAttribute("id") or "" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
206 if item_elt.uri not in (pubsub.NS_PUBSUB, pubsub.NS_PUBSUB_EVENT): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
207 raise exceptions.DataError( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
208 f"Unsupported namespace {item_elt.uri} in pubsub item {id_!r}." |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
209 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
210 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
211 try: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
212 entry_elt = next(item_elt.elements(NS_ATOM, "entry")) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
213 except StopIteration: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
214 raise exceptions.DataError(f"No atom entry found in the pubsub item {id_!r}.") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
215 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
216 # Initialize basic data |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
217 data = { |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
218 "id": id_, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
219 "service": service, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
220 "node": node, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
221 } |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
222 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
223 # Set URI if node is provided |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
224 # FIXME: node should alway be set in the future, check FIXME in method signature. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
225 if node is not None: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
226 data["uri"] = xmpp_uri.build_xmpp_uri( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
227 "pubsub", |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
228 path=service.full(), |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
229 node=node, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
230 item=id_, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
231 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
232 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
233 # Language. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
234 try: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
235 data["language"] = entry_elt[(C.NS_XML, "lang")].strip() |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
236 except KeyError: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
237 pass |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
238 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
239 # atom:id. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
240 try: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
241 id_elt = next(entry_elt.elements(NS_ATOM, "id")) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
242 except StopIteration: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
243 log.warning( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
244 f"No atom id found in the pubsub item {id_}, this is not standard!" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
245 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
246 data["atom_id"] = "" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
247 else: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
248 data["atom_id"] = str(id_elt) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
249 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
250 # Title(s) and content(s). |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
251 # FIXME: ATOM and XEP-0277 only allow 1 <title/> element but in the wild we have |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
252 # some blogs with several ones so we don't respect the standard for now (it |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
253 # doesn't break anything anyway), and we'll find a better option later. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
254 title_elts = list(entry_elt.elements(NS_ATOM, "title")) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
255 if not title_elts: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
256 raise exceptions.DataError(f"No atom title found in the pubsub item {id_!r}.") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
257 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
258 for title_elt in title_elts: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
259 await cls._parse_content_element(title_elt, data) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
260 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
261 # Content(s) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
262 # FIXME: As for <title/>, Atom only authorise at most 1 content but XEP-0277 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
263 # allows several ones. So for no we handle as if more than one can be present. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
264 for content_elt in entry_elt.elements(NS_ATOM, "content"): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
265 await cls._parse_content_element(content_elt, data) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
266 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
267 # Ensure text content exists when only xhtml is provided. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
268 for key in ("title", "content"): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
269 if key not in data and f"{key}_xhtml" in data: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
270 log.warning(f"item {id_!r} provides {key}_xhtml data but not a text one.") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
271 data[key] = await text_syntaxes.convert( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
272 data[f"{key}_xhtml"], |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
273 text_syntaxes.SYNTAX_XHTML, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
274 text_syntaxes.SYNTAX_TEXT, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
275 False, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
276 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
277 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
278 if "content" not in data: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
279 # Use the atom title data as the microblog body content. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
280 data["content"] = data["title"] |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
281 del data["title"] |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
282 if "title_xhtml" in data: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
283 data["content_xhtml"] = data["title_xhtml"] |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
284 del data["title_xhtml"] |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
285 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
286 # Dates. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
287 try: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
288 updated_elt = next(entry_elt.elements(NS_ATOM, "updated")) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
289 except StopIteration: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
290 raise exceptions.DataError( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
291 f"No atom updated element found in the pubsub item {id_!r}." |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
292 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
293 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
294 data["updated"] = calendar.timegm( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
295 dateutil.parser.parse(str(updated_elt)).utctimetuple() |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
296 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
297 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
298 try: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
299 published_elt = next(entry_elt.elements(NS_ATOM, "published")) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
300 except StopIteration: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
301 data["published"] = data["updated"] |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
302 else: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
303 data["published"] = calendar.timegm( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
304 dateutil.parser.parse(str(published_elt)).utctimetuple() |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
305 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
306 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
307 # Initialize extra data |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
308 extra = MbExtra() |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
309 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
310 # Links (comments, attachments, etc.) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
311 comments = [] |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
312 for link_elt in entry_elt.elements(NS_ATOM, "link"): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
313 href = link_elt.getAttribute("href") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
314 if not href: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
315 log.warning(f"Missing href in <link> element: {link_elt.toXml()}.") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
316 continue |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
317 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
318 rel = link_elt.getAttribute("rel") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
319 if rel == "replies" and link_elt.getAttribute("title") == "comments": |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
320 try: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
321 comment_service, comment_node = XEP_0277.parse_comment_url(href) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
322 except exceptions.DataError as e: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
323 log.exception(f"Can't parse comments url: {e}.") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
324 continue |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
325 else: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
326 comments.append( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
327 Comment(uri=href, service=comment_service, node=comment_node) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
328 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
329 elif rel == "via": |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
330 try: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
331 repeater_jid = jid.JID(item_elt["publisher"]) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
332 except (KeyError, RuntimeError): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
333 # We look for stanza element which is at the root, meaning that it has |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
334 # not parent. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
335 top_elt = item_elt.parent |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
336 assert top_elt is not None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
337 while top_elt.parent is not None: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
338 top_elt = top_elt.parent |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
339 try: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
340 repeater_jid = jid.JID(top_elt["from"]) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
341 except (AttributeError, RuntimeError): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
342 log.error(f"Can't find repeater of the post: {item_elt.toXml()}.") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
343 continue |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
344 extra.repeated = Repeated(by=repeater_jid, uri=href) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
345 elif rel in ("related", "enclosure"): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
346 extra.attachments.append(cls._parse_attachment(link_elt, href, rel)) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
347 elif rel == "alternate": |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
348 media_type = link_elt.getAttribute("type") or guess_type(href)[0] |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
349 if not media_type: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
350 log.warning( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
351 "Invalid or missing media type for alternate link: " |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
352 f"{link_elt.toXml()}." |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
353 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
354 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
355 extra.alt_links.append(AltLink(url=href, media_type=media_type)) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
356 else: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
357 log.warning(f"Unmanaged link element: {link_elt.toXml()}.") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
358 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
359 if comments: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
360 data["comments"] = comments |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
361 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
362 # Reply-To |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
363 in_reply_tos = [] |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
364 for in_reply_to_elt in entry_elt.elements(NS_ATOM_THREADING, "in-reply-to"): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
365 in_reply_to = InReplyTo( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
366 ref=in_reply_to_elt.getAttribute("ref", ""), |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
367 href=in_reply_to_elt.getAttribute("href"), |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
368 type=in_reply_to_elt.getAttribute("type") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
369 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
370 if not in_reply_to_elt.ref: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
371 log.warning( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
372 "No ref in <in-reply-to> element, this is not valid, ignoring: " |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
373 f"in_reply_to_elt.toXml()" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
374 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
375 continue |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
376 in_reply_tos.append(in_reply_to) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
377 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
378 if in_reply_tos: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
379 data["in_reply_tos"] = in_reply_tos |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
380 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
381 # Author information. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
382 author_data = cls._parse_author(entry_elt, item_elt, id_, extra) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
383 data.update(author_data) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
384 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
385 # Tags/categories |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
386 data["tags"] = [ |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
387 term |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
388 for category_elt in entry_elt.elements(NS_ATOM, "category") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
389 if (term := category_elt.getAttribute("term")) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
390 ] |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
391 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
392 data["extra"] = extra |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
393 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
394 ## the trigger ## |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
395 # if other plugins have things to add or change |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
396 G.host.trigger.point("XEP-0277_item2data", item_elt, entry_elt, data) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
397 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
398 return cls(**data) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
399 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
400 @staticmethod |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
401 async def _parse_content_element(elem: domish.Element, data: dict[str, Any]) -> None: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
402 """Parse title/content elements and add to data dict.""" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
403 type_ = elem.getAttribute("type") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
404 if type_ == "xhtml": |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
405 data_elt = elem.firstChildElement() |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
406 if data_elt is None: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
407 raise exceptions.DataError( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
408 "XHML content not wrapped in a <div/> element, this is not standard!" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
409 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
410 if data_elt.uri != C.NS_XHTML: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
411 raise exceptions.DataError( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
412 "Content of type XHTML must declare its namespace!" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
413 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
414 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
415 # We clean the content to avoid anything dangerous. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
416 text_syntaxes = cast(TextSyntaxes, G.host.plugins["TEXT_SYNTAXES"]) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
417 data[f"{elem.name}_xhtml"] = text_syntaxes.clean_xhtml(data_elt.toXml()) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
418 else: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
419 data[elem.name] = str(elem) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
420 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
421 @classmethod |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
422 def _parse_attachment( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
423 cls, link_elt: domish.Element, href: str, rel: str |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
424 ) -> Attachment: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
425 """Parse an attachment (related/enclosure) link.""" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
426 attachment = Attachment(sources=[{"url": href}], external=(rel == "related")) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
427 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
428 if media_type := link_elt.getAttribute("type"): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
429 attachment.media_type = media_type |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
430 if desc := link_elt.getAttribute("title"): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
431 attachment.desc = desc |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
432 try: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
433 attachment.size = int(link_elt["length"]) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
434 except (KeyError, ValueError): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
435 pass |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
436 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
437 if not attachment.media_type: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
438 if guessed_type := guess_type(href, False)[0]: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
439 attachment.media_type = guessed_type |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
440 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
441 return attachment |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
442 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
443 @classmethod |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
444 def _parse_author( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
445 cls, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
446 entry_elt: domish.Element, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
447 item_elt: domish.Element, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
448 item_id: str, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
449 extra: MbExtra, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
450 ) -> dict[str, Any]: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
451 """Parse author information from the entry.""" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
452 author_data: dict[str, Any] = {} |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
453 publisher = item_elt.getAttribute("publisher") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
454 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
455 try: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
456 author_elt = next(entry_elt.elements(NS_ATOM, "author")) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
457 except StopIteration: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
458 log.debug(f"Can't find author element in item {item_id!r}") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
459 if publisher: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
460 author_data["author_jid"] = publisher |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
461 author_data["author_jid_verified"] = True |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
462 return author_data |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
463 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
464 # Name. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
465 try: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
466 name_elt = next(author_elt.elements(NS_ATOM, "name")) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
467 except StopIteration: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
468 log.warning("No name element found in author element of item {item_id!r}.") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
469 else: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
470 author_data["author"] = str(name_elt).strip() |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
471 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
472 # Parse URI. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
473 try: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
474 uri_elt = next(author_elt.elements(NS_ATOM, "uri")) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
475 except StopIteration: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
476 log.debug(f"No uri element found in author element of item {item_id!r}.") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
477 if publisher: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
478 author_data["author_jid"] = publisher |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
479 author_data["author_jid_verified"] = True |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
480 else: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
481 iq_elt = xml_tools.find_ancestor(item_elt, "iq", C.NS_STREAM) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
482 author_data["author_jid"] = iq_elt["from"] |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
483 else: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
484 uri = str(uri_elt) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
485 if uri.startswith("xmpp:"): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
486 author_data["author_jid"] = uri[5:] or None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
487 else: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
488 author_data["author_jid"] = publisher or None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
489 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
490 if publisher: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
491 try: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
492 author_data["author_jid_verified"] = ( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
493 jid.JID(publisher).userhostJID() == jid.JID(uri).userhostJID() |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
494 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
495 except Exception: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
496 author_data["author_jid_verified"] = False |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
497 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
498 if not author_data["author_jid_verified"] and not extra.repeated is None: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
499 log.warning( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
500 'Item\'s atom:uri differs from "publisher" attribute, spoofing ' |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
501 f"attempt? {uri=} {publisher=}" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
502 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
503 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
504 # If no author name but we have JID, use the username. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
505 if "author" not in author_data and author_data.get("author_jid"): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
506 try: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
507 author_data["author"] = jid.JID(author_data["author_jid"]).user |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
508 except Exception as e: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
509 log.warning(f"Couldn't parse author JID: {e}.") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
510 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
511 # Email. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
512 try: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
513 email_elt = next(author_elt.elements(NS_ATOM, "email")) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
514 except StopIteration: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
515 pass |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
516 else: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
517 author_data["author_email"] = str(email_elt) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
518 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
519 return author_data |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
520 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
521 async def to_element( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
522 self, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
523 client: SatXMPPEntity, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
524 ) -> pubsub.Item: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
525 """Convert this MbData instance to a PubSub item Element. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
526 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
527 @param client: Client instance. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
528 @return: PubSub Item containing the Atom entry element |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
529 """ |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
530 text_syntaxes = cast(TextSyntaxes, G.host.plugins["TEXT_SYNTAXES"]) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
531 entry_elt = domish.Element((NS_ATOM, "entry")) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
532 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
533 ## Language ## |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
534 if self.language: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
535 entry_elt[(C.NS_XML, "lang")] = self.language.strip() |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
536 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
537 ## Content and Title ## |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
538 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
539 for elem_name in ("title", "content"): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
540 for type_ in ["", "_rich", "_xhtml"]: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
541 attr = f"{elem_name}{type_}" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
542 value = getattr(self, attr) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
543 if value is not None: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
544 elem = entry_elt.addElement(elem_name) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
545 if type_: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
546 if type_ == "_rich": |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
547 # Convert input from current syntax to XHTML |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
548 if getattr(self, f"{elem_name}_xhtml") != None: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
549 raise failure.Failure( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
550 exceptions.DataError( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
551 "Can't have xhtml and rich content at the same " |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
552 "time" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
553 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
554 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
555 content_xhtml = await text_syntaxes.convert( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
556 value, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
557 text_syntaxes.get_current_syntax(client.profile), |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
558 "XHTML", |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
559 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
560 else: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
561 content_xhtml = value |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
562 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
563 div_elt = xml_tools.ElementParser()( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
564 content_xhtml, namespace=C.NS_XHTML |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
565 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
566 if ( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
567 div_elt.name != "div" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
568 or div_elt.uri != C.NS_XHTML |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
569 or div_elt.attributes |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
570 ): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
571 # We need a wrapping <div/> at the top with XHTML namespace. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
572 wrap_div_elt = domish.Element((C.NS_XHTML, "div")) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
573 wrap_div_elt.addChild(div_elt) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
574 div_elt = wrap_div_elt |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
575 elem.addChild(div_elt) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
576 elem["type"] = "xhtml" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
577 if getattr(self, elem_name) is None: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
578 # There is no text content. It is mandatory so we create one |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
579 # from xhtml content. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
580 elem_txt = entry_elt.addElement(elem_name) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
581 text_content = await text_syntaxes.convert( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
582 content_xhtml, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
583 text_syntaxes.SYNTAX_XHTML, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
584 text_syntaxes.SYNTAX_TEXT, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
585 False, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
586 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
587 elem_txt.addContent(text_content) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
588 elem_txt["type"] = "text" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
589 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
590 else: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
591 # Raw text only needs to be escaped to get HTML-safe sequence. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
592 elem.addContent(value) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
593 elem["type"] = "text" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
594 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
595 # Ensure we have at least a title. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
596 if not any(entry_elt.elements(NS_ATOM, "title")): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
597 if any(entry_elt.elements(NS_ATOM, "content")): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
598 for elem in entry_elt.elements(NS_ATOM, "content"): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
599 elem.name = "title" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
600 else: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
601 raise exceptions.DataError( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
602 "Atom entry must have at least a title or content element" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
603 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
604 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
605 ## Attachments ## |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
606 for attachment in self.extra.attachments: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
607 url = None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
608 if attachment.sources: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
609 for source in attachment.sources: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
610 if "url" in source: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
611 url = source["url"] |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
612 break |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
613 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
614 if not url: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
615 log.warning(f'"url" missing in attachment, ignoring: {attachment}') |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
616 continue |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
617 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
618 if not url.startswith("http"): |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
619 log.warning(f"Non HTTP URL in attachment, ignoring: {attachment}.") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
620 continue |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
621 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
622 link_elt = entry_elt.addElement("link") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
623 # XXX: "uri" is set in self._manage_comments if not already existing |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
624 link_elt["href"] = url |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
625 link_elt["rel"] = "related" if attachment.external else "enclosure" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
626 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
627 if attachment.media_type: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
628 link_elt["type"] = attachment.media_type |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
629 if attachment.desc: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
630 link_elt["title"] = attachment.desc |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
631 if attachment.size: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
632 link_elt["length"] = str(attachment.size) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
633 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
634 ## Alternate Links ## |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
635 for alt_link in self.extra.alt_links: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
636 if self.service is None or self.node is None or self.id is None: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
637 log.warning( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
638 f"Can't compute alternate link due to missing service, node or ID." |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
639 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
640 continue |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
641 link_elt = entry_elt.addElement("link") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
642 url = link_elt["href"] = alt_link.url.format( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
643 service=quote(self.service.full(), safe=""), |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
644 node=quote(self.node, safe=""), |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
645 item=quote(self.id, safe=""), |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
646 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
647 link_elt["rel"] = "alternate" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
648 if alt_link.media_type: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
649 media_type = alt_link.media_type |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
650 else: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
651 parsed_url = urlparse(url) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
652 if parsed_url.scheme in ["http", "https"]: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
653 media_type = "text/html" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
654 else: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
655 media_type = guess_type(url)[0] or "application/octet-stream" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
656 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
657 link_elt["type"] = media_type |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
658 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
659 ## Author ## |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
660 author_elt = entry_elt.addElement("author") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
661 author_name = self.author or (self.author_jid.user if self.author_jid else "") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
662 author_elt.addElement("name", content=author_name) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
663 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
664 author_jid = self.author_jid or client.jid |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
665 author_elt.addElement("uri", content=f"xmpp:{author_jid.userhost()}") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
666 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
667 if self.author_email: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
668 author_elt.addElement("email", content=self.author_email) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
669 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
670 ## Dates ## |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
671 current_time = time.time() |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
672 entry_elt.addElement( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
673 "updated", |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
674 content=utils.xmpp_date( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
675 float(self.updated if self.updated else current_time) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
676 ), |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
677 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
678 entry_elt.addElement( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
679 "published", |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
680 content=utils.xmpp_date( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
681 float(self.published if self.published else current_time) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
682 ), |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
683 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
684 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
685 ## Tags ## |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
686 for tag in self.tags: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
687 category_elt = entry_elt.addElement("category") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
688 category_elt["term"] = tag |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
689 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
690 ## ID ## |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
691 if self.atom_id is None: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
692 if self.id is not None: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
693 if self.service is not None: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
694 self.atom_id = xmpp_uri.build_xmpp_uri( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
695 "pubsub", |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
696 path=self.service.full(), |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
697 node=self.node, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
698 item=self.id or "", |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
699 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
700 else: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
701 self.atom_id = self.id |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
702 else: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
703 self.atom_id = shortuuid.uuid() |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
704 entry_elt.addElement("id", content=self.atom_id) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
705 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
706 ## Comments ## |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
707 for comment in self.comments: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
708 link_elt = entry_elt.addElement("link") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
709 # XXX: "uri" is set in self._manage_comments if not already existing. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
710 if not comment.uri: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
711 log.warning("Missing URI for {comment}, ignoring.") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
712 continue |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
713 link_elt["href"] = comment.uri |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
714 link_elt["rel"] = "replies" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
715 link_elt["title"] = "comments" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
716 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
717 ## In-Reply-Tos ### |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
718 if self.in_reply_tos is not None: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
719 for in_reply_to in self.in_reply_tos: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
720 in_reply_to_elt = entry_elt.addElement((NS_ATOM_THREADING, "in-reply-to")) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
721 in_reply_to_elt["ref"] = in_reply_to.ref |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
722 if href := in_reply_to.href is not None: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
723 in_reply_to_elt["href"] = href |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
724 if type_ := in_reply_to.type is not None: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
725 in_reply_to_elt["type"] = type_ |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
726 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
727 ## Reposts ## |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
728 if self.extra.repeated: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
729 link_elt = entry_elt.addElement("link") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
730 link_elt["rel"] = "via" |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
731 link_elt["href"] = self.extra.repeated.uri |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
732 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
733 ## Final item building ## |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
734 item_elt = pubsub.Item(id=self.id, payload=entry_elt) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
735 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
736 ## Trigger ## |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
737 G.host.trigger.point("XEP-0277_data2entry", client, self, entry_elt, item_elt) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
738 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
739 return item_elt |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
740 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
741 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
742 class XEP_0277: |
1831
68c0dc13d821
plugin blog import, XEP-0277: progress + redirect:
Goffi <goffi@goffi.org>
parents:
1829
diff
changeset
|
743 namespace = NS_MICROBLOG |
3724
a0c08fcfe11e
plugin XEP-0277: various fixes + async:
Goffi <goffi@goffi.org>
parents:
3680
diff
changeset
|
744 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
|
745 |
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
746 def __init__(self, host): |
3028 | 747 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
|
748 self.host = host |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
749 host.register_namespace("microblog", NS_MICROBLOG) |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
750 self._p = cast(XEP_0060, self.host.plugins["XEP-0060"]) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
751 ps_cache = cast(PubsubCache, self.host.plugins.get("PUBSUB_CACHE")) |
3598
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
752 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
|
753 ps_cache.register_analyser( |
3598
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
754 { |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
755 "name": "XEP-0277", |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
756 "node": NS_MICROBLOG, |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
757 "namespace": NS_ATOM, |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
758 "type": "blog", |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
759 "to_sync": True, |
4023
78b5f356900c
component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents:
4020
diff
changeset
|
760 "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
|
761 "match_cb": self._cache_node_match_cb, |
3598
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
762 } |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
763 ) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
764 self.rt_sessions = sat_defer.RTDeferredSessions() |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
765 self._p.add_managed_node(NS_MICROBLOG, items_cb=self._items_received) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
766 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
767 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
768 "mb_send", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
769 ".plugin", |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
770 in_sign="ss", |
3848
e9c380ef41c8
plugin XEP-0277: return ID of published item in `send` and bridge's `mbSend`
Goffi <goffi@goffi.org>
parents:
3840
diff
changeset
|
771 out_sign="s", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
772 method=self._mb_send, |
3028 | 773 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
774 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
775 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
776 "mb_repeat", |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
777 ".plugin", |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
778 in_sign="sssss", |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
779 out_sign="s", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
780 method=self._mb_repeat, |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
781 async_=True, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
782 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
783 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
784 "mb_preview", |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
785 ".plugin", |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
786 in_sign="ssss", |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
787 out_sign="s", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
788 method=self._mb_preview, |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
789 async_=True, |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
790 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
791 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
792 "mb_retract", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
793 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
794 in_sign="ssss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
795 out_sign="", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
796 method=self._mb_retract, |
3028 | 797 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
798 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
799 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
800 "mb_get", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
801 ".plugin", |
3586
5f65f4e9f8cb
plugin XEP-0060: getItems extra is now serialised dict
Goffi <goffi@goffi.org>
parents:
3584
diff
changeset
|
802 in_sign="ssiasss", |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
803 out_sign="s", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
804 method=self._mb_get, |
3028 | 805 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
806 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
807 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
808 "mb_rename", |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
809 ".plugin", |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
810 in_sign="sssss", |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
811 out_sign="", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
812 method=self._mb_rename, |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
813 async_=True, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
814 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
815 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
816 "mb_access_set", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
817 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
818 in_sign="ss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
819 out_sign="", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
820 method=self.mb_access_set, |
3028 | 821 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
822 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
823 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
824 "mb_subscribe_to_many", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
825 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
826 in_sign="sass", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
827 out_sign="s", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
828 method=self._mb_subscribe_to_many, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
829 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
830 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
831 "mb_get_from_many_rt_result", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
832 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
833 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
|
834 out_sign="(ua(sssasa{ss}))", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
835 method=self._mb_get_from_many_rt_result, |
3028 | 836 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
837 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
838 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
839 "mb_get_from_many", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
840 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
841 in_sign="sasia{ss}s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
842 out_sign="s", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
843 method=self._mb_get_from_many, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
844 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
845 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
846 "mb_get_from_many_with_comments_rt_result", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
847 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
848 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
|
849 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
|
850 method=self._mb_get_from_many_with_comments_rt_result, |
3028 | 851 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
852 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
853 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
854 "mb_get_from_many_with_comments", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
855 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
856 in_sign="sasiia{ss}a{ss}s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
857 out_sign="s", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
858 method=self._mb_get_from_many_with_comments, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
859 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
860 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
861 "mb_is_comment_node", |
3762
becd7f1aa033
plugin XEP-0277: bridge method `mbIsCommentNode` + methods renaming
Goffi <goffi@goffi.org>
parents:
3761
diff
changeset
|
862 ".plugin", |
becd7f1aa033
plugin XEP-0277: bridge method `mbIsCommentNode` + methods renaming
Goffi <goffi@goffi.org>
parents:
3761
diff
changeset
|
863 in_sign="s", |
becd7f1aa033
plugin XEP-0277: bridge method `mbIsCommentNode` + methods renaming
Goffi <goffi@goffi.org>
parents:
3761
diff
changeset
|
864 out_sign="b", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
865 method=self.is_comment_node, |
3762
becd7f1aa033
plugin XEP-0277: bridge method `mbIsCommentNode` + methods renaming
Goffi <goffi@goffi.org>
parents:
3761
diff
changeset
|
866 ) |
302
9f3a6cf91668
plugin xep-0277: added getLastMicroblogs method
Goffi <goffi@goffi.org>
parents:
297
diff
changeset
|
867 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
868 def get_handler(self, client): |
2341
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
869 return XEP_0277_handler() |
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
870 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
871 def _cache_node_match_cb( |
3598
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
872 self, |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
873 client: SatXMPPEntity, |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
874 analyse: dict, |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
875 ) -> None: |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
876 """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
|
877 if analyse["node"].startswith(NS_COMMENT_PREFIX): |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
878 analyse["subtype"] = "comment" |
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
879 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
880 def _check_features_cb(self, available): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
881 return {"available": C.BOOL_TRUE} |
1656
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
882 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
883 def _check_features_eb(self, fail): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
884 return {"available": C.BOOL_FALSE} |
1656
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
885 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
886 def features_get(self, profile): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
887 client = self.host.get_client(profile) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
888 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
|
889 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
|
890 return d |
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
891 |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
892 ## plugin management methods ## |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
893 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
894 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
|
895 """Callback which manage items notifications (publish + retract)""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
896 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
897 def manage_item(data, event): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
898 self.host.bridge.ps_event( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
899 C.PS_MICROBLOG, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
900 itemsEvent.sender.full(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
901 itemsEvent.nodeIdentifier, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
902 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
|
903 data_format.serialise(data), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
904 client.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
905 ) |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
906 |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
907 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
|
908 if item.name == C.PS_ITEM: |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
909 # FIXME: service and node should be used here |
4023
78b5f356900c
component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents:
4020
diff
changeset
|
910 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
|
911 manage_item, lambda failure: None, (C.PS_PUBLISH,) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
912 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
913 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
|
914 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
|
915 else: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
916 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
|
917 |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
918 ## 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
|
919 |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
920 async def item_2_mb_data( |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
921 self, |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
922 client: SatXMPPEntity, |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
923 item_elt: domish.Element, |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
924 service: jid.JID | None, |
4023
78b5f356900c
component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents:
4020
diff
changeset
|
925 # 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
|
926 # and node. Once done, the Optional must be removed here |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
927 node: str | None, |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
928 ) -> 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
|
929 """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
|
930 |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
931 @param item_elt: microblog item element |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
932 @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
|
933 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
|
934 @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
|
935 if None, "uri" won't be set |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
936 @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
|
937 """ |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
938 mb_data = await MbData.from_element(client, item_elt, service, node) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
939 return mb_data.model_dump(exclude_none=True) |
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
|
940 |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
941 async def mb_data_2_entry_elt( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
942 self, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
943 client: SatXMPPEntity, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
944 mb_data: dict, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
945 ) -> pubsub.Item: |
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
|
946 """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
|
947 |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
948 @param mb_data: data dict as given by bridge method. |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
949 @param item_id: id of the item to use |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
950 @param service: pubsub service where the item is sent |
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
|
951 Needed to construct Atom id |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
952 @param node: pubsub node where the item is sent |
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
|
953 Needed to construct Atom id |
1419
be2df1ddea8e
plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
954 @return: deferred which fire domish.Element |
be2df1ddea8e
plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
955 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
956 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
|
957 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
|
958 |
2264
a8eaaac4d80f
plugin XEP-0277, tools/common/data_objects: language handling
Goffi <goffi@goffi.org>
parents:
2243
diff
changeset
|
959 ## language ## |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
960 if "language" in mb_data: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
961 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
|
962 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
963 ## content and title ## |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
964 text_syntaxes = cast(TextSyntaxes, 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
|
965 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
966 for elem_name in ("title", "content"): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
967 for type_ in ["", "_rich", "_xhtml"]: |
4020
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
968 attr = f"{elem_name}{type_}" |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
969 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
|
970 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
|
971 if type_: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
972 if type_ == "_rich": # convert input from current syntax to XHTML |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
973 xml_content = await text_syntaxes.convert( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
974 mb_data[attr], |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
975 text_syntaxes.get_current_syntax(client.profile), |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
976 "XHTML", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
977 ) |
4020
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
978 if f"{elem_name}_xhtml" in mb_data: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
979 raise failure.Failure( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
980 exceptions.DataError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
981 _( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
982 "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
|
983 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
984 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
985 ) |
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
|
986 else: |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
987 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
|
988 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
989 div_elt = xml_tools.ElementParser()( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
990 xml_content, namespace=C.NS_XHTML |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
991 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
992 if ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
993 div_elt.name != "div" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
994 or div_elt.uri != C.NS_XHTML |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
995 or div_elt.attributes |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
996 ): |
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
|
997 # 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
|
998 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
|
999 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
|
1000 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
|
1001 elem.addChild(div_elt) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1002 elem["type"] = "xhtml" |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1003 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
|
1004 # 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
|
1005 # 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
|
1006 elem_txt = entry_elt.addElement(elem_name) |
3724
a0c08fcfe11e
plugin XEP-0277: various fixes + async:
Goffi <goffi@goffi.org>
parents:
3680
diff
changeset
|
1007 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
|
1008 "TEXT_SYNTAXES" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1009 ].convert( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1010 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
|
1011 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
|
1012 self.host.plugins["TEXT_SYNTAXES"].SYNTAX_TEXT, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1013 False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1014 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1015 elem_txt.addContent(text_content) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1016 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
|
1017 |
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
|
1018 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
|
1019 elem.addContent(mb_data[attr]) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1020 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
|
1021 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1022 try: |
3028 | 1023 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
|
1024 except StopIteration: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1025 # 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
|
1026 # so we transform content element to title |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1027 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
|
1028 if not elems: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1029 raise exceptions.DataError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1030 "There must be at least one content or title element" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1031 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1032 for elem in elems: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1033 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
|
1034 |
4020
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1035 ## attachments ## |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1036 attachments = extra.get(C.KEY_ATTACHMENTS) |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1037 if attachments: |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1038 for attachment in attachments: |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1039 try: |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1040 url = attachment["url"] |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1041 except KeyError: |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1042 try: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1043 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
|
1044 except (StopIteration, KeyError): |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1045 log.warning( |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1046 f'"url" missing in attachment, ignoring: {attachment}' |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1047 ) |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1048 continue |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1049 |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1050 if not url.startswith("http"): |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1051 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
|
1052 continue |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1053 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
|
1054 # 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
|
1055 link_elt["href"] = url |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1056 if attachment.get("external", False): |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1057 # 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
|
1058 link_elt["rel"] = "related" |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1059 else: |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1060 # this is an attached file |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1061 link_elt["rel"] = "enclosure" |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1062 for key, attr in ( |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1063 ("media_type", "type"), |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1064 ("desc", "title"), |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1065 ("size", "lenght"), |
4020
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1066 ): |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1067 value = attachment.get(key) |
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1068 if value: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1069 link_elt[attr] = str(value) |
4020
d8a1219e913f
plugin XEP-0277: handle "related" and "enclosure" links:
Goffi <goffi@goffi.org>
parents:
4018
diff
changeset
|
1070 |
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
|
1071 ## 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
|
1072 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
|
1073 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
|
1074 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
|
1075 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
|
1076 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
|
1077 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
|
1078 node=quote(node, safe=""), |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1079 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
|
1080 ) |
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
|
1081 |
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
|
1082 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
|
1083 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
|
1084 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
|
1085 |
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
|
1086 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
|
1087 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
|
1088 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
|
1089 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
|
1090 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
|
1091 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
|
1092 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
|
1093 |
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
|
1094 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
|
1095 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1096 ## author ## |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1097 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
|
1098 try: |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1099 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
|
1100 except KeyError: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1101 # 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
|
1102 author_name = client.jid.user |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1103 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
|
1104 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1105 try: |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1106 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
|
1107 except KeyError: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1108 author_jid_s = client.jid.userhost() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1109 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
|
1110 |
1820
3c8cf120a0fd
plugin XEP-0277: added missing author_email parsing
Goffi <goffi@goffi.org>
parents:
1817
diff
changeset
|
1111 try: |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1112 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
|
1113 except KeyError: |
3c8cf120a0fd
plugin XEP-0277: added missing author_email parsing
Goffi <goffi@goffi.org>
parents:
1817
diff
changeset
|
1114 pass |
3c8cf120a0fd
plugin XEP-0277: added missing author_email parsing
Goffi <goffi@goffi.org>
parents:
1817
diff
changeset
|
1115 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1116 ## 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
|
1117 current_time = time.time() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1118 entry_elt.addElement( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1119 "updated", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1120 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
|
1121 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1122 entry_elt.addElement( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1123 "published", |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1124 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
|
1125 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1126 |
1664
5d0ff155be1a
plugin XEP-0277: tags are handled through atom categories
Goffi <goffi@goffi.org>
parents:
1661
diff
changeset
|
1127 ## categories ## |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1128 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
|
1129 category_elt = entry_elt.addElement("category") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1130 category_elt["term"] = tag |
1664
5d0ff155be1a
plugin XEP-0277: tags are handled through atom categories
Goffi <goffi@goffi.org>
parents:
1661
diff
changeset
|
1131 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1132 ## id ## |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1133 entry_id = mb_data.get( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1134 "id", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1135 xmpp_uri.build_xmpp_uri( |
3028 | 1136 "pubsub", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1137 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
|
1138 node=node, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1139 item=item_id, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1140 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1141 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1142 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
|
1143 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1144 ## comments ## |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1145 for comments_data in mb_data.get("comments", []): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1146 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
|
1147 # 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
|
1148 try: |
c86a22009c1f
plugin XEP-0277: fix comments node handling when parent node doesn't exist.
Goffi <goffi@goffi.org>
parents:
4178
diff
changeset
|
1149 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
|
1150 except KeyError: |
c86a22009c1f
plugin XEP-0277: fix comments node handling when parent node doesn't exist.
Goffi <goffi@goffi.org>
parents:
4178
diff
changeset
|
1151 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
|
1152 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
|
1153 else: |
c86a22009c1f
plugin XEP-0277: fix comments node handling when parent node doesn't exist.
Goffi <goffi@goffi.org>
parents:
4178
diff
changeset
|
1154 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
|
1155 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
|
1156 |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1157 if "repeated" in extra: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1158 try: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1159 repeated = extra["repeated"] |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1160 link_elt = entry_elt.addElement("link") |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1161 link_elt["rel"] = "via" |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1162 link_elt["href"] = repeated["uri"] |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1163 except KeyError as e: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1164 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
|
1165 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1166 ## 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
|
1167 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
|
1168 |
96ee986dab3c
plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents:
1656
diff
changeset
|
1169 ## the trigger ## |
96ee986dab3c
plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents:
1656
diff
changeset
|
1170 # 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
|
1171 self.host.trigger.point( |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1172 "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
|
1173 ) |
1661
96ee986dab3c
plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents:
1656
diff
changeset
|
1174 |
3724
a0c08fcfe11e
plugin XEP-0277: various fixes + async:
Goffi <goffi@goffi.org>
parents:
3680
diff
changeset
|
1175 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
|
1176 |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1177 ## publish/preview ## |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
1178 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1179 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
|
1180 """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
|
1181 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
|
1182 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1183 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
|
1184 """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
|
1185 |
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
|
1186 @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
|
1187 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1188 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
|
1189 raise ValueError("This node is not a comment node") |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1190 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
|
1191 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1192 def get_comments_node(self, item_id): |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
1193 """Generate comment node |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
1194 |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
1195 @param item_id(unicode): id of the parent item |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
1196 @return (unicode): comment node to use |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
1197 """ |
3598
d390ff50af0f
plugin XEP-0277: pubsub cache analyser implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
1198 return f"{NS_COMMENT_PREFIX}{item_id}" |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
1199 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1200 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
|
1201 """Get prefered PubSub service to create comment node |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
1202 |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
1203 @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
|
1204 @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
|
1205 """ |
2433
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
1206 if parent_service is not None: |
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
1207 if parent_service.user: |
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
1208 # we are on a PEP |
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
1209 if parent_service.host == client.jid.host: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1210 # 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
|
1211 pass |
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
1212 else: |
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
1213 # 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
|
1214 d = self.host.find_service_entity( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1215 client, "pubsub", "service", parent_service |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1216 ) |
2433
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
1217 d.addCallback(lambda entity: entity or parent_service) |
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
1218 else: |
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
1219 # 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
|
1220 return defer.succeed(parent_service) |
014feb75092d
plugin XEP-0277: better getCommentsService:
Goffi <goffi@goffi.org>
parents:
2415
diff
changeset
|
1221 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1222 return defer.succeed( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1223 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
|
1224 ) |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
1225 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1226 async def _manage_comments( |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1227 self, client: SatXMPPEntity, mb_data: MbData, access: str | None = None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1228 ) -> None: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1229 """Check comments keys in mb_data and create comments node if necessary. |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1230 |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1231 If a comments node metadata is set in the mb_data['comments'] list, it is used |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1232 otherwise it is generated (if allow_comments is True). |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1233 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1234 @param mb_data: Microblog data. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1235 @param access: Access model. |
2227
79d279d1ee88
plugin XEP-0277: comments node access model changes:
Goffi <goffi@goffi.org>
parents:
2218
diff
changeset
|
1236 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
|
1237 """ |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1238 if mb_data.allow_comments is None: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1239 if mb_data.comments: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1240 mb_data.allow_comments = True |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1241 else: |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1242 # No comments set or requested, nothing to do. |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1243 return |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1244 elif mb_data.allow_comments == False: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1245 if mb_data.comments: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1246 log.warning( |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1247 "Comments are not allowed but there is already a comments node, " |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1248 "it may be lost: {mb_data['comments']}." |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1249 ) |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1250 mb_data.comments.clear() |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1251 return |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1252 |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1253 # We have usually a single comment node, but the spec allow several, so we need to |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1254 # handle this in a list. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1255 if len(mb_data.comments) == 0: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1256 # We need at least one comment node, we set an empty one for now, we'll |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1257 # complete it below. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1258 mb_data.comments.append(Comment()) |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1259 |
2227
79d279d1ee88
plugin XEP-0277: comments node access model changes:
Goffi <goffi@goffi.org>
parents:
2218
diff
changeset
|
1260 if access is None: |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1261 # 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
|
1262 try: |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1263 parent_node_config = await self._p.getConfiguration( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1264 client, mb_data.service, mb_data.node |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1265 ) |
4186
c86a22009c1f
plugin XEP-0277: fix comments node handling when parent node doesn't exist.
Goffi <goffi@goffi.org>
parents:
4178
diff
changeset
|
1266 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
|
1267 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
|
1268 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
|
1269 else: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1270 access = parent_node_config.get( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1271 self._p.OPT_ACCESS_MODEL, self._p.ACCESS_OPEN |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1272 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1273 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1274 options = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1275 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
|
1276 self._p.OPT_MAX_ITEMS: "max", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1277 self._p.OPT_PERSIST_ITEMS: 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1278 self._p.OPT_DELIVER_PAYLOADS: 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1279 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1280 # 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
|
1281 self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1282 } |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1283 |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1284 # 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
|
1285 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
|
1286 |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1287 for comments_data in mb_data.comments: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1288 if comments_data.uri: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1289 uri_service, uri_node = self.parse_comment_url(comments_data.uri) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1290 if ( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1291 comments_data.node is not None and comments_data.node != uri_node |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1292 ) or ( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1293 comments_data.service is not None |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1294 and comments_data.service != uri_service |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1295 ): |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1296 raise ValueError( |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1297 f"Incoherence between comments URI ({comments_data.uri}) and " |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1298 f"comments_service ({comments_data.service}) or comments_node " |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1299 f"({comments_data.node})." |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1300 ) |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1301 comments_data.service = uri_service |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1302 comments_data.node = uri_node |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1303 else: |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1304 if not comments_data.node: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1305 comments_data.node = self.get_comments_node(mb_data.id) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1306 if comments_data.service is None: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1307 comments_data.service = await self.get_comments_service( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1308 client, mb_data.service |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1309 ) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1310 if comments_data.service is None: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1311 comments_data.service = client.jid.userhostJID() |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1312 |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1313 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
|
1314 "pubsub", |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1315 path=comments_data.service.full(), |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1316 node=comments_data.node, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1317 ) |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
1318 |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1319 try: |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1320 await self._p.createNode( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1321 client, comments_data.service, comments_data.node, options |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1322 ) |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1323 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
|
1324 if e.condition == "conflict": |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1325 log.info( |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1326 "node {} already exists on service {}".format( |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1327 comments_data.node, comments_data.service |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1328 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1329 ) |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1330 else: |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1331 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
|
1332 else: |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1333 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
|
1334 # 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
|
1335 comments_affiliations = await self._p.get_node_affiliations( |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1336 client, mb_data.service, mb_data.node |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1337 ) |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1338 # …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
|
1339 # 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
|
1340 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
|
1341 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
|
1342 comments_affiliations[jid_] = "publisher" |
2286
330f8d4e2ad4
plugin XEP-0277: change affiliations for comments + fixes:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
1343 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1344 await self._p.set_node_affiliations( |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1345 client, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1346 comments_data.service, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1347 comments_data.node, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1348 comments_affiliations, |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1349 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1350 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1351 def friendly_id(self, data): |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1352 """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
|
1353 # 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
|
1354 id_base = regex.url_friendly_text( |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1355 data.title or data.title_rich or data.content or data.content_rich or "" |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1356 ) |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1357 if not data.user_friendly_id_suffix: |
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
|
1358 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
|
1359 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
|
1360 return f"{id_base}-{token_urlsafe(3)}" |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1361 |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1362 def _mb_send(self, data, profile_key) -> defer.Deferred[str | None]: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1363 data = MbData.model_validate_json(data) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1364 client = self.host.get_client(profile_key) |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1365 return defer.ensureDeferred(self.send(client, data)) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1366 |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1367 async def send( |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1368 self, |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1369 client: SatXMPPEntity, |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1370 data: MbData, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1371 ) -> str | None: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1372 """Send XEP-0277's microblog data. |
1419
be2df1ddea8e
plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1373 |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1374 @param data: Microblog data (must include at least a "content" or a "title" key). |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1375 see http://wiki.goffi.org/wiki/Bridge_API_-_Microblogging/en for details. |
3848
e9c380ef41c8
plugin XEP-0277: return ID of published item in `send` and bridge's `mbSend`
Goffi <goffi@goffi.org>
parents:
3840
diff
changeset
|
1376 @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
|
1377 """ |
1699 | 1378 # 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
|
1379 # by accident (e.g. if group plugin is not loaded, and "group*" key are not used) |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1380 if data.id is None: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1381 if data.user_friendly_id: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1382 data.id = self.friendly_id(data) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1383 if not data.user_friendly_id_suffix: |
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
|
1384 # 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
|
1385 # 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
|
1386 try: |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1387 __, __ = await self._p.get_items( |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1388 client, data.service, data.node, item_ids=[data.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
|
1389 ) |
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
|
1390 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
|
1391 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
|
1392 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
|
1393 # 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
|
1394 log.info( |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1395 f"there is already an item with ID {data.id!r}, we have to " |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1396 'set the "user_friendly_id_suffix" flag.' |
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
|
1397 ) |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1398 data.user_friendly_id_suffix = True |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1399 data.id = self.friendly_id(data) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1400 |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1401 if not data.service: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1402 data.service = client.jid.userhostJID() |
2227
79d279d1ee88
plugin XEP-0277: comments node access model changes:
Goffi <goffi@goffi.org>
parents:
2218
diff
changeset
|
1403 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1404 try: |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1405 await self._manage_comments(client, data, 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
|
1406 except error.StanzaError: |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1407 log.warning("Can't create comments node for item {data.id}") |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1408 item_elt = await data.to_element(client) |
3861
37a1193d90db
plugin XEP-0277: add a trigger to `send` method:
Goffi <goffi@goffi.org>
parents:
3848
diff
changeset
|
1409 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1410 if not await self.host.trigger.async_point( |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1411 "XEP-0277_send", client, item_elt, data |
3861
37a1193d90db
plugin XEP-0277: add a trigger to `send` method:
Goffi <goffi@goffi.org>
parents:
3848
diff
changeset
|
1412 ): |
37a1193d90db
plugin XEP-0277: add a trigger to `send` method:
Goffi <goffi@goffi.org>
parents:
3848
diff
changeset
|
1413 return None |
37a1193d90db
plugin XEP-0277: add a trigger to `send` method:
Goffi <goffi@goffi.org>
parents:
3848
diff
changeset
|
1414 |
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
|
1415 extra = {} |
3972
5fbdf986670c
plugin pte: Pubsub Target Encryption implementation:
Goffi <goffi@goffi.org>
parents:
3957
diff
changeset
|
1416 for key in ("encrypted", "encrypted_for", "signed"): |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1417 value = getattr(data.extra, key) |
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
|
1418 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
|
1419 extra[key] = value |
3934
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3931
diff
changeset
|
1420 |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1421 await self._p.publish(client, data.service, data.node, [item_elt], extra=extra) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1422 return data.id |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1423 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1424 def _mb_repeat( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1425 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
|
1426 ) -> defer.Deferred: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1427 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
|
1428 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
|
1429 client = self.host.get_client(profile_key) |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1430 extra = data_format.deserialise(extra_s) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1431 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
|
1432 # [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
|
1433 d.addCallback(lambda ret: ret or "") |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1434 return d |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1435 |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1436 async def repeat( |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1437 self, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1438 client: SatXMPPEntity, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1439 item: str, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1440 service: Optional[jid.JID] = None, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1441 node: str = NS_MICROBLOG, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1442 extra: Optional[dict] = None, |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1443 ) -> Optional[str]: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1444 """Re-publish a post from somewhere else |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1445 |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1446 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
|
1447 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
|
1448 """ |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1449 if service is None: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1450 service = client.jid.userhostJID() |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1451 |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1452 # we first get the post to repeat |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1453 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
|
1454 if not items: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1455 raise exceptions.NotFound( |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1456 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
|
1457 ) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1458 item_elt = items[0] |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1459 try: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1460 entry_elt = next(item_elt.elements(NS_ATOM, "entry")) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1461 except StopIteration: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1462 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
|
1463 |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1464 # 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
|
1465 try: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1466 author_elt = next(entry_elt.elements(NS_ATOM, "author")) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1467 except StopIteration: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1468 author_elt = entry_elt.addElement("author") |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1469 |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1470 try: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1471 next(author_elt.elements(NS_ATOM, "name")) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1472 except StopIteration: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1473 author_elt.addElement("name", content=service.user) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1474 |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1475 try: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1476 next(author_elt.elements(NS_ATOM, "uri")) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1477 except StopIteration: |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1478 entry_elt.addElement( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1479 "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
|
1480 ) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1481 |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1482 # 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
|
1483 link_elt = entry_elt.addElement("link") |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1484 link_elt["rel"] = "via" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1485 link_elt["href"] = xmpp_uri.build_xmpp_uri( |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1486 "pubsub", path=service.full(), node=node, item=item |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1487 ) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1488 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1489 return await self._p.send_item( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1490 client, client.jid.userhostJID(), NS_MICROBLOG, entry_elt |
3840
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1491 ) |
5b192a5eb72d
plugin XEP-0277: post repeating implementation:
Goffi <goffi@goffi.org>
parents:
3763
diff
changeset
|
1492 |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1493 def _mb_preview(self, mb_data_s: str, profile_key: str) -> defer.Deferred[str]: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1494 client = self.host.get_client(profile_key) |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1495 mb_data = MbData.model_validate_json(mb_data_s) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1496 d = defer.ensureDeferred(self.preview(client, mb_data)) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1497 d.addCallback(lambda data: data.model_dump_json()) |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1498 d = cast(defer.Deferred[str], d) |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1499 return d |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1500 |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1501 async def preview( |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1502 self, |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1503 client: SatXMPPEntity, |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1504 mb_data: MbData, |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1505 ) -> MbData: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1506 """Preview microblog data without publishing them. |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1507 |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1508 params are the same as for [send] |
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1509 @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
|
1510 """ |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1511 if mb_data.service is None: |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1512 mb_data.service = client.jid.userhostJID() |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1513 # we have to serialise then deserialise to be sure that all triggers are called |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1514 item_elt = await mb_data.to_element(client) |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1515 item_elt.uri = pubsub.NS_PUBSUB |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1516 return await MbData.from_element(client, item_elt, mb_data.service, mb_data.node) |
3513
753d151da886
XEP-0277: new preview/mbPreview method:
Goffi <goffi@goffi.org>
parents:
3502
diff
changeset
|
1517 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1518 ## retract ## |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1519 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1520 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
|
1521 """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
|
1522 return self._p._retract_item( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1523 service_jid_s, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1524 nodeIdentifier or NS_MICROBLOG, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1525 itemIdentifier, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1526 True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1527 profile_key, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1528 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1529 |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
1530 ## get ## |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
1531 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1532 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
|
1533 items, metadata = data |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1534 metadata["items"] = items |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
1535 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
|
1536 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1537 def _mb_get( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1538 self, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1539 service="", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1540 node="", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1541 max_items=10, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1542 item_ids=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1543 extra="", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1544 profile_key=C.PROF_KEY_NONE, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
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 """ |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1547 @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
|
1548 @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
|
1549 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1550 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
|
1551 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
|
1552 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
|
1553 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
|
1554 d = defer.ensureDeferred( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1555 self.mb_get( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1556 client, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1557 service, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1558 node or None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1559 max_items, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1560 item_ids, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1561 extra.rsm_request, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1562 extra.extra, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1563 ) |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1564 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1565 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
|
1566 return d |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
1567 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1568 async def mb_get( |
3949
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1569 self, |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1570 client: SatXMPPEntity, |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1571 service: Optional[jid.JID] = None, |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1572 node: Optional[str] = None, |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1573 max_items: Optional[int] = 10, |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1574 item_ids: Optional[List[str]] = None, |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1575 rsm_request: Optional[rsm.RSMRequest] = None, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1576 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
|
1577 ) -> 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
|
1578 """Get some microblogs |
1419
be2df1ddea8e
plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1579 |
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
|
1580 @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
|
1581 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
|
1582 @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
|
1583 @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
|
1584 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
|
1585 @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
|
1586 @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
|
1587 @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
|
1588 |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
1589 @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
|
1590 """ |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1591 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
|
1592 node = NS_MICROBLOG |
3591
d830c11eeef3
plugin XEP-0277: ignore `max_items` if `rsm_request` is set
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
1593 if rsm_request: |
d830c11eeef3
plugin XEP-0277: ignore `max_items` if `rsm_request` is set
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
1594 max_items = None |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1595 items_data = await self._p.get_items( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1596 client, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1597 service, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1598 node, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1599 max_items=max_items, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1600 item_ids=item_ids, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1601 rsm_request=rsm_request, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1602 extra=extra, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1603 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1604 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
|
1605 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
|
1606 ) |
3949
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1607 encrypted = metadata.pop("encrypted", None) |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1608 if encrypted is not None: |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1609 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
|
1610 try: |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1611 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
|
1612 except KeyError: |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1613 pass |
f7ff893b536e
plugin XEP-0277: add `encryption` flag to MB data:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1614 return (mb_data_list, metadata) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1615 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1616 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
|
1617 return defer.ensureDeferred( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1618 self.mb_rename( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1619 self.host.get_client(profile_key), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1620 jid.JID(service) if service else None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1621 node or None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1622 item_id, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1623 new_id, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1624 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1625 ) |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1626 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1627 async def mb_rename( |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1628 self, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1629 client: SatXMPPEntity, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1630 service: Optional[jid.JID], |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1631 node: Optional[str], |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1632 item_id: str, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1633 new_id: str, |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1634 ) -> None: |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1635 if not node: |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3513
diff
changeset
|
1636 node = NS_MICROBLOG |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1637 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
|
1638 |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1639 @staticmethod |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1640 def parse_comment_url(node_url): |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
1641 """Parse a XMPP URI |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
1642 |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
1643 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
|
1644 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
|
1645 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
|
1646 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
|
1647 @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
|
1648 """ |
3643
30196b9a2b4c
plugin XEP-0277: use `common.uri` to parse comment URIs
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1649 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1650 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
|
1651 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
|
1652 node = parsed_url["node"] |
30196b9a2b4c
plugin XEP-0277: use `common.uri` to parse comment URIs
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1653 except Exception as e: |
30196b9a2b4c
plugin XEP-0277: use `common.uri` to parse comment URIs
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
1654 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
|
1655 |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
1656 return (service, node) |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
1657 |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
1658 ## configure ## |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
1659 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1660 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
|
1661 """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
|
1662 |
304 | 1663 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
|
1664 @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
|
1665 @param profile_key: profile key |
6a2fa651d7fa
plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents:
2160
diff
changeset
|
1666 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1667 # 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
|
1668 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
|
1669 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1670 _options = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1671 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
|
1672 self._p.OPT_MAX_ITEMS: "max", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1673 self._p.OPT_PERSIST_ITEMS: 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1674 self._p.OPT_DELIVER_PAYLOADS: 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1675 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1676 } |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1677 |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1678 def cb(result): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1679 # Node is created with right permission |
3028 | 1680 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
|
1681 |
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1682 def fatal_err(s_error): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1683 # Something went wrong |
3028 | 1684 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
|
1685 raise NodeAccessChangeException() |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1686 |
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1687 def err_cb(s_error): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1688 # If the node already exists, the condition is "conflict", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1689 # else we have an unmanaged error |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1690 if s_error.value.condition == "conflict": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1691 # 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
|
1692 # d.addCallback(lambda x: create_node().addCallback(cb).addErrback(fatal_err)) |
304 | 1693 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
|
1694 else: |
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1695 fatal_err(s_error) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1696 |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1697 def create_node(): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1698 return self._p.createNode( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1699 client, client.jid.userhostJID(), NS_MICROBLOG, _options |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1700 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1701 |
304 | 1702 def change_node_options(): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1703 return self._p.setOptions( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1704 client.jid.userhostJID(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1705 NS_MICROBLOG, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1706 client.jid.userhostJID(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1707 _options, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1708 profile_key=profile_key, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1709 ) |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1710 |
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
1711 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
|
1712 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1713 ## 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
|
1714 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1715 # common |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1716 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1717 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
|
1718 """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
|
1719 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1720 @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
|
1721 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
|
1722 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
|
1723 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
|
1724 @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
|
1725 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
|
1726 @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
|
1727 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1728 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
|
1729 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
|
1730 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
|
1731 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1732 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
|
1733 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
|
1734 try: |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1735 # 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
|
1736 services = self.host.plugins["EXTRA-PEP"].get_followed_entities( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1737 profile_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1738 ) |
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
|
1739 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
|
1740 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
|
1741 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
|
1742 if services: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1743 log.debug( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1744 "Extra PEP followed entities: %s" |
3028 | 1745 % ", ".join([str(service) for service in services]) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1746 ) |
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
|
1747 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
|
1748 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1749 node_data = [] |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1750 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
|
1751 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
|
1752 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
|
1753 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1754 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
|
1755 """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
|
1756 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1757 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
|
1758 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
|
1759 @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
|
1760 """ |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1761 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
|
1762 if publishers: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1763 raise failure.Failure( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1764 ValueError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1765 "Can't use publishers with {} type".format(publishers_type) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1766 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1767 ) |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1768 else: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1769 publishers = None |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1770 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
|
1771 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
|
1772 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
|
1773 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1774 # subscribe # |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1775 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1776 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
|
1777 """ |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1778 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1779 @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
|
1780 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1781 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
|
1782 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
|
1783 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1784 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
|
1785 """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
|
1786 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1787 @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
|
1788 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
|
1789 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
|
1790 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
|
1791 @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
|
1792 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
|
1793 @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
|
1794 @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
|
1795 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1796 client, node_data = self._get_client_and_node_data( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1797 publishers_type, publishers, profile_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1798 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1799 return self._p.subscribe_to_many( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1800 node_data, client.jid.userhostJID(), profile_key=profile_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1801 ) |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
1802 |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1803 # get # |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1804 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1805 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
|
1806 """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
|
1807 |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1808 @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
|
1809 @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
|
1810 - 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
|
1811 - 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
|
1812 - service (unicode): pubsub service |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1813 - node (unicode): pubsub node |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1814 - 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
|
1815 - 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
|
1816 - 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
|
1817 @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
|
1818 """ |
4383
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1819 # FIXME: check if this code must be removed. |
7c1d77efc752
plugin XEP-0277: Make MbData a Pydantic model:
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
1820 raise NotImplementedError("Legacy code to be removed.") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1821 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1822 client = self.host.get_client(profile_key) |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1823 |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1824 def onSuccess(items_data): |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1825 """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
|
1826 d = self._p.trans_items_data_d( |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1827 items_data, |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1828 # FIXME: service and node should be used here |
4023
78b5f356900c
component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents:
4020
diff
changeset
|
1829 partial(self.item_2_mb_data, client), |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1830 serialise=True, |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1831 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1832 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
|
1833 return d |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1834 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1835 d = self._p.get_rt_results( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1836 session_id, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1837 on_success=onSuccess, |
3028 | 1838 on_error=lambda failure: (str(failure.value), ([], {})), |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
1839 profile=client.profile, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1840 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1841 d.addCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1842 lambda ret: ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1843 ret[0], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1844 [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1845 (service.full(), node, failure, items, metadata) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1846 for (service, node), (success, (failure, (items, metadata))) in ret[ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1847 1 |
3028 | 1848 ].items() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1849 ], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1850 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1851 ) |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1852 return d |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1853 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1854 def _mb_get_from_many( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1855 self, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1856 publishers_type, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1857 publishers, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1858 max_items=10, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1859 extra_dict=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1860 profile_key=C.PROF_KEY_NONE, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1861 ): |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1862 """ |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1863 @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
|
1864 """ |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1865 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
|
1866 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
|
1867 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
|
1868 return self.mb_get_from_many( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1869 publishers_type, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1870 publishers, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1871 max_items, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1872 extra.rsm_request, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1873 extra.extra, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1874 profile_key, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1875 ) |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1876 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1877 def mb_get_from_many( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1878 self, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1879 publishers_type, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1880 publishers, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1881 max_items=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1882 rsm_request=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1883 extra=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1884 profile_key=C.PROF_KEY_NONE, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1885 ): |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1886 """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
|
1887 |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1888 @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
|
1889 "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
|
1890 @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
|
1891 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
|
1892 @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
|
1893 @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
|
1894 @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
|
1895 @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
|
1896 @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
|
1897 """ |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1898 # 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
|
1899 client, node_data = self._get_client_and_node_data( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1900 publishers_type, publishers, profile_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1901 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1902 return self._p.get_from_many( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1903 node_data, max_items, rsm_request, profile_key=profile_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1904 ) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1905 |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1906 # comments # |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1907 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1908 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
|
1909 """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
|
1910 |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1911 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
|
1912 @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
|
1913 @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
|
1914 """ |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1915 ret = [] |
3028 | 1916 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
|
1917 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
|
1918 items = [] |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1919 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
|
1920 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
|
1921 items.append((item, item_metadata)) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1922 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
|
1923 |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
1924 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
|
1925 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1926 def _mb_get_from_many_with_comments_rt_result( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1927 self, session_id, profile_key=C.PROF_KEY_DEFAULT |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1928 ): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1929 """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
|
1930 |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1931 @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
|
1932 @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
|
1933 - 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
|
1934 - 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
|
1935 - 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
|
1936 - 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
|
1937 - 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
|
1938 - 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
|
1939 - 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
|
1940 - 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
|
1941 - 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
|
1942 - 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
|
1943 - 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
|
1944 - 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
|
1945 - 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
|
1946 - 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
|
1947 @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
|
1948 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
1949 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
|
1950 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
|
1951 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
|
1952 return d |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1953 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1954 def _mb_get_from_many_with_comments( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1955 self, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1956 publishers_type, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1957 publishers, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1958 max_items=10, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1959 max_comments=C.NO_LIMIT, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1960 extra_dict=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1961 extra_comments_dict=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1962 profile_key=C.PROF_KEY_NONE, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1963 ): |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1964 """ |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1965 @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
|
1966 @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
|
1967 limit |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1968 """ |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
1969 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
|
1970 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
|
1971 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
|
1972 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
|
1973 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
|
1974 return self.mb_get_from_many_with_comments( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1975 publishers_type, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1976 publishers, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1977 max_items, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1978 max_comments or None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1979 extra.rsm_request, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1980 extra.extra, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1981 extra_comments.rsm_request, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1982 extra_comments.extra, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1983 profile_key, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1984 ) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1985 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1986 def mb_get_from_many_with_comments( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1987 self, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1988 publishers_type, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1989 publishers, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1990 max_items=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1991 max_comments=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1992 rsm_request=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1993 extra=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1994 rsm_comments=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1995 extra_comments=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1996 profile_key=C.PROF_KEY_NONE, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
1997 ): |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
1998 """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
|
1999 |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2780
diff
changeset
|
2000 @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
|
2001 "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
|
2002 @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
|
2003 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
|
2004 @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
|
2005 @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
|
2006 @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
|
2007 @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
|
2008 @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
|
2009 @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
|
2010 @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
|
2011 @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
|
2012 """ |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
2013 # 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
|
2014 # 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
|
2015 # 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
|
2016 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
2017 client, node_data = self._get_client_and_node_data( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2018 publishers_type, publishers, profile_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2019 ) |
2360
72cbb6478f97
plugin XEP-0060: use client instead of profile_key in getItems
Goffi <goffi@goffi.org>
parents:
2341
diff
changeset
|
2020 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
2021 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
|
2022 """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
|
2023 |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
2024 @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
|
2025 @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
|
2026 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
|
2027 """ |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
2028 items, metadata = items_data |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2029 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
|
2030 for item in items: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2031 dlist = [] # deferred list for comments |
3028 | 2032 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
|
2033 # we look for comments |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2034 if key.startswith("comments") and key.endswith("_service"): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2035 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
|
2036 service_s = value |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
2037 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
|
2038 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
|
2039 # 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
|
2040 d = defer.ensureDeferred( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
2041 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
|
2042 client, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
2043 service, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
2044 node, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
2045 max_comments, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
2046 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
|
2047 extra=extra_comments, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3550
diff
changeset
|
2048 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2049 ) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
2050 # then serialise |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2051 d.addCallback( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
2052 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
|
2053 items_data, |
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
2054 partial( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
2055 self.item_2_mb_data, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
2056 client, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
2057 service=service, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
2058 node=node, |
3328
d49607e3a066
plugin XEP-0277: set "uri" in item2mbdata
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
2059 ), |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
2060 serialise=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2061 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2062 ) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
2063 # with failure handling |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2064 d.addCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2065 lambda serialised_items_data: ("",) + serialised_items_data |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2066 ) |
3028 | 2067 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
|
2068 # 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
|
2069 # comments nodes) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2070 d.addCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2071 lambda serialised, service_s=service_s, node=node: ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2072 service_s, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2073 node, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2074 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2075 + serialised |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2076 ) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
2077 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
|
2078 # 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
|
2079 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
|
2080 # and add them to the item data |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2081 comments_d.addCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2082 lambda comments_data, item=item: (item, comments_data) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2083 ) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
2084 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
|
2085 # 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
|
2086 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
|
2087 # 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
|
2088 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
|
2089 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
|
2090 |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
2091 deferreds = {} |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
2092 for service, node in node_data: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
2093 d = deferreds[(service, node)] = defer.ensureDeferred( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
2094 self._p.get_items( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
2095 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
|
2096 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4186
diff
changeset
|
2097 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2098 d.addCallback( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
2099 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
|
2100 items_data, |
4023
78b5f356900c
component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents:
4020
diff
changeset
|
2101 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
|
2102 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2103 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
2104 d.addCallback(get_comments) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2105 d.addCallback(lambda items_comments_data: ("", items_comments_data)) |
3028 | 2106 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
|
2107 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4023
diff
changeset
|
2108 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
|
2109 |
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
2110 |
3028 | 2111 @implementer(iwokkel.IDisco) |
2341
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
2112 class XEP_0277_handler(XMPPHandler): |
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
2113 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2114 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
|
2115 return [disco.DiscoFeature(NS_MICROBLOG)] |
f9580b4a105a
plugin XEP-0277: added microblog namespace to disco info
Goffi <goffi@goffi.org>
parents:
2322
diff
changeset
|
2116 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2117 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
|
2118 return [] |