Mercurial > libervia-backend
comparison sat/plugins/plugin_comp_ap_gateway/__init__.py @ 3807:2032826cfbcf
component AP gateway typing + remove unused `activity` arg from `newAPDeleteItem`
rel 367
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 17 Jun 2022 15:50:34 +0200 |
parents | 36b167ddbfca |
children | 0b1c30ff2cbb |
comparison
equal
deleted
inserted
replaced
3806:adebd8036b68 | 3807:2032826cfbcf |
---|---|
40 from treq.response import _Response as TReqResponse | 40 from treq.response import _Response as TReqResponse |
41 from twisted.internet import defer, reactor, threads | 41 from twisted.internet import defer, reactor, threads |
42 from twisted.web import http | 42 from twisted.web import http |
43 from twisted.words.protocols.jabber import error, jid | 43 from twisted.words.protocols.jabber import error, jid |
44 from twisted.words.xish import domish | 44 from twisted.words.xish import domish |
45 from wokkel import rsm | 45 from wokkel import rsm, pubsub |
46 | 46 |
47 from sat.core import exceptions | 47 from sat.core import exceptions |
48 from sat.core.constants import Const as C | 48 from sat.core.constants import Const as C |
49 from sat.core.core_types import SatXMPPEntity | 49 from sat.core.core_types import SatXMPPEntity |
50 from sat.core.i18n import _ | 50 from sat.core.i18n import _ |
230 async def profileConnecting(self, client): | 230 async def profileConnecting(self, client): |
231 self.client = client | 231 self.client = client |
232 client.sendHistory = True | 232 client.sendHistory = True |
233 await self.init(client) | 233 await self.init(client) |
234 | 234 |
235 async def _itemsReceived(self, client, itemsEvent): | 235 async def _itemsReceived( |
236 self, | |
237 client: SatXMPPEntity, | |
238 itemsEvent: pubsub.ItemsEvent | |
239 ) -> None: | |
236 """Callback called when pubsub items are received | 240 """Callback called when pubsub items are received |
237 | 241 |
238 if the items are adressed to a JID corresponding to an AP actor, they are | 242 if the items are adressed to a JID corresponding to an AP actor, they are |
239 converted to AP items and sent to the corresponding AP server. | 243 converted to AP items and sent to the corresponding AP server. |
240 | 244 |
927 return defer.ensureDeferred(self.publishMessage(client, mess_data, service)) | 931 return defer.ensureDeferred(self.publishMessage(client, mess_data, service)) |
928 | 932 |
929 @async_lru(maxsize=LRU_MAX_SIZE) | 933 @async_lru(maxsize=LRU_MAX_SIZE) |
930 async def getAPActorIdFromAccount(self, account: str) -> str: | 934 async def getAPActorIdFromAccount(self, account: str) -> str: |
931 """Retrieve account ID from it's handle using WebFinger | 935 """Retrieve account ID from it's handle using WebFinger |
936 | |
937 Don't use this method to get local actor id from a local account derivated for | |
938 JID: in this case, the actor ID is retrieve with | |
939 ``self.buildAPURL(TYPE_ACTOR, ap_account)`` | |
932 | 940 |
933 @param account: AP handle (user@domain.tld) | 941 @param account: AP handle (user@domain.tld) |
934 @return: Actor ID (which is an URL) | 942 @return: Actor ID (which is an URL) |
935 """ | 943 """ |
936 if account.count("@") != 1 or "/" in account: | 944 if account.count("@") != 1 or "/" in account: |
1896 async def newAPDeleteItem( | 1904 async def newAPDeleteItem( |
1897 self, | 1905 self, |
1898 client: SatXMPPEntity, | 1906 client: SatXMPPEntity, |
1899 destinee: Optional[jid.JID], | 1907 destinee: Optional[jid.JID], |
1900 node: str, | 1908 node: str, |
1901 activity: dict, | |
1902 item: dict, | 1909 item: dict, |
1903 ) -> None: | 1910 ) -> None: |
1904 """Analyse, cache and send notification for received AP item | 1911 """Analyse, cache and send notification for received AP item |
1905 | 1912 |
1906 @param destinee: jid of the destinee, | 1913 @param destinee: jid of the destinee, |
1929 | 1936 |
1930 if history is not None: | 1937 if history is not None: |
1931 # it's a direct message | 1938 # it's a direct message |
1932 if history.source_jid != client.jid: | 1939 if history.source_jid != client.jid: |
1933 log.warning( | 1940 log.warning( |
1934 f"retractation received from an entity ''{client.jid}) which is " | 1941 f"retraction received from an entity ''{client.jid}) which is " |
1935 f"not the original sender of the message ({history.source_jid}), " | 1942 f"not the original sender of the message ({history.source_jid}), " |
1936 "hack attemps?" | 1943 "hack attemps?" |
1937 ) | 1944 ) |
1938 raise exceptions.PermissionError("forbidden") | 1945 raise exceptions.PermissionError("forbidden") |
1939 | 1946 |