Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_comp_ap_gateway/ad_hoc.py @ 4309:b56b1eae7994
component email gateway: add multicasting:
XEP-0033 multicasting is now supported both for incoming and outgoing messages. XEP-0033
metadata are converted to suitable Email headers and vice versa.
Email address and JID are both supported, and delivery is done by the gateway when
suitable on incoming messages.
rel 450
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 26 Sep 2024 16:12:01 +0200 |
parents | 0d7bb4df2343 |
children |
rev | line source |
---|---|
3904 | 1 #!/usr/bin/env python3 |
2 | |
3 # Libervia ActivityPub Gateway | |
4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) | |
5 | |
6 # This program is free software: you can redistribute it and/or modify | |
7 # it under the terms of the GNU Affero General Public License as published by | |
8 # the Free Software Foundation, either version 3 of the License, or | |
9 # (at your option) any later version. | |
10 | |
11 # This program is distributed in the hope that it will be useful, | |
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 # GNU Affero General Public License for more details. | |
15 | |
16 # You should have received a copy of the GNU Affero General Public License | |
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | |
19 from twisted.words.protocols.jabber import jid | |
20 from twisted.words.xish import domish | |
21 from wokkel import data_form | |
22 | |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
23 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
|
24 from libervia.backend.core.core_types import SatXMPPEntity |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
25 from libervia.backend.core.i18n import _ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
26 from libervia.backend.core.log import getLogger |
3904 | 27 |
28 | |
29 log = getLogger(__name__) | |
30 NS_XMPP_JID_NODE_2_AP = "https://libervia.org/ap_gateway/xmpp_jid_node_2_ap_actor" | |
31 | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
32 |
3904 | 33 class APAdHocService: |
34 """Ad-Hoc commands for AP Gateway""" | |
35 | |
36 def __init__(self, apg): | |
37 self.host = apg.host | |
38 self.apg = apg | |
39 self._c = self.host.plugins["XEP-0050"] | |
40 | |
41 def init(self, client: SatXMPPEntity) -> None: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3904
diff
changeset
|
42 self._c.add_ad_hoc_command( |
3904 | 43 client, |
44 self.xmpp_jid_node_2_ap_actor, | |
45 "Convert XMPP JID/Node to AP actor", | |
46 node=NS_XMPP_JID_NODE_2_AP, | |
47 allowed_magics=C.ENTITY_ALL, | |
48 ) | |
49 | |
50 async def xmpp_jid_node_2_ap_actor( | |
51 self, | |
52 client: SatXMPPEntity, | |
53 command_elt: domish.Element, | |
54 session_data: dict, | |
55 action: str, | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
56 node: str, |
3904 | 57 ): |
58 try: | |
59 x_elt = next(command_elt.elements(data_form.NS_X_DATA, "x")) | |
60 command_form = data_form.Form.fromElement(x_elt) | |
61 except StopIteration: | |
62 command_form = None | |
63 if command_form is None or len(command_form.fields) == 0: | |
64 # root request | |
65 status = self._c.STATUS.EXECUTING | |
66 form = data_form.Form( | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
67 "form", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
68 title="XMPP JID/node to AP actor conversion", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
69 formNamespace=NS_XMPP_JID_NODE_2_AP, |
3904 | 70 ) |
71 | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
72 field = data_form.Field("text-single", "jid", required=True) |
3904 | 73 form.addField(field) |
74 | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
75 field = data_form.Field("text-single", "node", required=False) |
3904 | 76 form.addField(field) |
77 | |
78 payload = form.toElement() | |
79 return payload, status, None, None | |
80 else: | |
81 xmpp_jid = jid.JID(command_form["jid"]) | |
82 xmpp_node = command_form.get("node") | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3904
diff
changeset
|
83 actor = await self.apg.get_ap_account_from_jid_and_node(xmpp_jid, xmpp_node) |
3904 | 84 note = (self._c.NOTE.INFO, actor) |
85 status = self._c.STATUS.COMPLETED | |
86 payload = None | |
87 return (payload, status, None, note) |