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