Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_comp_email_gateway/pubsub_service.py @ 4339:699aa8788d98
tests (unit/email gateway): add tests for pubsub service:
rel 453
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 03 Dec 2024 00:52:06 +0100 |
parents | 7c0b7ecb816f |
children |
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 typing import TYPE_CHECKING |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 from twisted.internet import defer |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 from twisted.words.protocols.jabber import jid, error |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from twisted.words.xish import domish |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from wokkel import data_form, disco, pubsub, rsm |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from libervia.backend.core.i18n import _ |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from libervia.backend.core.constants import Const as C |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from libervia.backend.core.log import getLogger |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from libervia.backend.plugins.plugin_xep_0498 import NodeData |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 from libervia.backend.tools.utils import ensure_deferred |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 if TYPE_CHECKING: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 from . import EmailGatewayComponent |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 |
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 log = getLogger(__name__) |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 # all nodes have the same config |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 NODE_CONFIG = [ |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 {"var": "pubsub#persist_items", "type": "boolean", "value": True}, |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 {"var": "pubsub#max_items", "value": "max"}, |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 {"var": "pubsub#access_model", "type": "list-single", "value": "open"}, |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 {"var": "pubsub#publish_model", "type": "list-single", "value": "open"}, |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 ] |
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 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
|
46 NODE_OPTIONS = {c["var"]: {} for c in NODE_CONFIG} |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 for c in NODE_CONFIG: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 NODE_OPTIONS[c["var"]].update( |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 {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
|
50 ) |
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 class EmailGWPubsubResource(pubsub.PubSubResource): |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 def __init__(self, service: "EmailGWPubsubService") -> None: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 self.gateway = service.gateway |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 self.host = self.gateway.host |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 self.service = service |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 self._pfs = service._pfs |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 super().__init__() |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 def getNodes( |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 self, requestor: jid.JID, service: jid.JID, nodeIdentifier: str |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 ) -> defer.Deferred[list[str]]: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 return defer.succeed([self._pfs.namespace]) |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 @ensure_deferred |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 async def items( |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 self, |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 request: rsm.PubSubRequest, |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 ) -> tuple[list[domish.Element], rsm.RSMResponse | None]: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 client = self.gateway.client |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 assert client is not None |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 sender = request.sender.userhostJID() |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 if not client.is_local(sender): |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 raise error.StanzaError("forbidden") |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 if request.nodeIdentifier != self._pfs.namespace: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 return [], None |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 files = await self.host.memory.get_files(client, sender) |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 node_data = NodeData.from_files_data(client.jid, files) |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 return node_data.to_elements(), None |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 @ensure_deferred |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 async def retract(self, request: rsm.PubSubRequest) -> None: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 client = self.gateway.client |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 assert client is not None |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 sender = request.sender.userhostJID() |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 if not client.is_local(sender): |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 raise error.StanzaError("forbidden") |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 if request.nodeIdentifier != self._pfs.namespace: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 raise error.StanzaError("bad-request") |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 for item_id in request.itemIdentifiers: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 try: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 # 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
|
98 # in XEP-0498. |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 file_id = item_id.rsplit("_", 1)[1] |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 except IndexError: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 file_id = "" |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 if not file_id: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 raise error.StanzaError("bad-request") |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 # 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
|
105 # too. |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 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
|
107 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 @ensure_deferred |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 async def subscribe(self, request: rsm.PubSubRequest): |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 raise rsm.Unsupported("subscribe") |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 @ensure_deferred |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 async def unsubscribe(self, request: rsm.PubSubRequest): |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 raise rsm.Unsupported("unsubscribe") |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 def getConfigurationOptions(self): |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 return NODE_OPTIONS |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 def getConfiguration( |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 self, requestor: jid.JID, service: jid.JID, nodeIdentifier: str |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 ) -> defer.Deferred: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 return defer.succeed(NODE_CONFIG_VALUES) |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 def getNodeInfo( |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 self, |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 requestor: jid.JID, |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 service: jid.JID, |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 nodeIdentifier: str, |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 pep: bool = False, |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 recipient: jid.JID | None = None, |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 ) -> dict | None: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 if not nodeIdentifier: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 return None |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 info = {"type": "leaf", "meta-data": NODE_CONFIG} |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 return info |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 |
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 class EmailGWPubsubService(rsm.PubSubService): |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 """Pubsub service for XMPP requests""" |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 def __init__(self, gateway: "EmailGatewayComponent"): |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 self.gateway = gateway |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 self._pfs = gateway._pfs |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 resource = EmailGWPubsubResource(self) |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 super().__init__(resource) |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 self.host = gateway.host |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 self.discoIdentity = { |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 "category": "pubsub", |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 "type": "service", |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 "name": "Libervia Email Gateway", |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 } |
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 @ensure_deferred |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 async def getDiscoInfo( |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 self, requestor: jid.JID, target: jid.JID, nodeIdentifier: str = "" |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 ) -> list[disco.DiscoFeature | disco.DiscoIdentity | data_form.Form]: |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 infos = await super().getDiscoInfo(requestor, target, nodeIdentifier) |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 infos.append(disco.DiscoFeature(self._pfs.namespace)) |
7c0b7ecb816f
component email gateway: Add a pubsub service:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 return infos |