Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_comp_email_gateway/pubsub_service.py @ 4338:7c0b7ecb816f
component email gateway: Add a pubsub service:
a pubsub service is implemented to retrieve and manage attachments using XEP-0498.
rel 453
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 03 Dec 2024 00:13:23 +0100 |
parents | |
children | 699aa8788d98 |
rev | line source |
---|---|
4338
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 # Libervia ActivityPub Gateway |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # (at your option) any later version. |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # GNU Affero General Public License for more details. |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 from pathlib import Path |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 from typing import TYPE_CHECKING |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 from twisted.internet import defer |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from twisted.words.protocols.jabber import jid, error |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from twisted.words.xish import domish |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from wokkel import data_form, disco, pubsub, rsm |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from libervia.backend.core.i18n import _ |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from libervia.backend.core.constants import Const as C |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from libervia.backend.core.log import getLogger |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 from libervia.backend.plugins.plugin_xep_0498 import NodeData |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 from libervia.backend.tools.utils import ensure_deferred |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 if TYPE_CHECKING: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 from . import EmailGatewayComponent |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 log = getLogger(__name__) |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 # all nodes have the same config |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 NODE_CONFIG = [ |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 {"var": "pubsub#persist_items", "type": "boolean", "value": True}, |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 {"var": "pubsub#max_items", "value": "max"}, |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 {"var": "pubsub#access_model", "type": "list-single", "value": "open"}, |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 {"var": "pubsub#publish_model", "type": "list-single", "value": "open"}, |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 ] |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 NODE_CONFIG_VALUES = {c["var"]: c["value"] for c in NODE_CONFIG} |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 NODE_OPTIONS = {c["var"]: {} for c in NODE_CONFIG} |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 for c in NODE_CONFIG: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 NODE_OPTIONS[c["var"]].update( |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 {k: v for k, v in c.items() if k not in ("var", "value")} |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 ) |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 class EmailGWPubsubResource(pubsub.PubSubResource): |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 def __init__(self, service: "EmailGWPubsubService") -> None: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 self.gateway = service.gateway |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 self.host = self.gateway.host |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 self.service = service |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 self._pfs = service._pfs |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 super().__init__() |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 def getNodes( |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 self, requestor: jid.JID, service: jid.JID, nodeIdentifier: str |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 ) -> defer.Deferred[list[str]]: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 return defer.succeed([self._pfs.namespace]) |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 @ensure_deferred |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 async def items( |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 self, |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 request: rsm.PubSubRequest, |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 ) -> tuple[list[domish.Element], rsm.RSMResponse | None]: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 client = self.gateway.client |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 assert client is not None |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 sender = request.sender.userhostJID() |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 if not client.is_local(sender): |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 raise error.StanzaError("forbidden") |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 if request.nodeIdentifier != self._pfs.namespace: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 return [], None |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 files = await self.host.memory.get_files(client, sender) |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 node_data = NodeData.from_files_data(client.jid, files) |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 return node_data.to_elements(), None |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 @ensure_deferred |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 async def retract(self, request: rsm.PubSubRequest) -> None: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 client = self.gateway.client |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 assert client is not None |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 sender = request.sender.userhostJID() |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 if not client.is_local(sender): |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 raise error.StanzaError("forbidden") |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 if request.nodeIdentifier != self._pfs.namespace: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 raise error.StanzaError("bad-request") |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 for item_id in request.itemIdentifiers: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 try: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 # FIXME: item ID naming convention must be hanlded using dedicated methods |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 # in XEP-0498. |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 file_id = item_id.rsplit("_", 1)[1] |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 except IndexError: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 file_id = "" |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 if not file_id: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 raise error.StanzaError("bad-request") |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 # Ownership is checked by ``file_delete``, and payload deletion is done there |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 # too. |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 await self.host.memory.file_delete(client, sender.userhostJID(), file_id) |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 @ensure_deferred |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 async def subscribe(self, request: rsm.PubSubRequest): |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 raise rsm.Unsupported("subscribe") |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 @ensure_deferred |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 async def unsubscribe(self, request: rsm.PubSubRequest): |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 raise rsm.Unsupported("unsubscribe") |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 def getConfigurationOptions(self): |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 return NODE_OPTIONS |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 def getConfiguration( |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 self, requestor: jid.JID, service: jid.JID, nodeIdentifier: str |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 ) -> defer.Deferred: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 return defer.succeed(NODE_CONFIG_VALUES) |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 def getNodeInfo( |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 self, |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 requestor: jid.JID, |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 service: jid.JID, |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 nodeIdentifier: str, |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 pep: bool = False, |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 recipient: jid.JID | None = None, |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 ) -> dict | None: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 if not nodeIdentifier: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 return None |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 info = {"type": "leaf", "meta-data": NODE_CONFIG} |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 return info |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 class EmailGWPubsubService(rsm.PubSubService): |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 """Pubsub service for XMPP requests""" |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 def __init__(self, gateway: "EmailGatewayComponent"): |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 self.gateway = gateway |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 self._pfs = gateway._pfs |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 resource = EmailGWPubsubResource(self) |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 super().__init__(resource) |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 self.host = gateway.host |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 self.discoIdentity = { |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 "category": "pubsub", |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 "type": "service", |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 "name": "Libervia Email Gateway", |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 } |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 @ensure_deferred |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 async def getDiscoInfo( |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 self, requestor: jid.JID, target: jid.JID, nodeIdentifier: str = "" |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 ) -> list[disco.DiscoFeature | disco.DiscoIdentity | data_form.Form]: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 infos = await super().getDiscoInfo(requestor, target, nodeIdentifier) |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 infos.append(disco.DiscoFeature(self._pfs.namespace)) |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 return infos |