Mercurial > libervia-backend
diff libervia/backend/plugins/plugin_comp_ap_gateway/events.py @ 4259:49019947cc76
component AP Gateway: implement HTTP GET signature.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 05 Jun 2024 22:34:09 +0200 |
parents | 4b842c1fb686 |
children | 0d7bb4df2343 |
line wrap: on
line diff
--- a/libervia/backend/plugins/plugin_comp_ap_gateway/events.py Wed Jun 05 22:33:37 2024 +0200 +++ b/libervia/backend/plugins/plugin_comp_ap_gateway/events.py Wed Jun 05 22:34:09 2024 +0200 @@ -104,7 +104,7 @@ """Convert event data to AP activity @param event_data: event data as used in [plugin_exp_events] - @param author_jid: jid of the published of the event + @param author_jid: jid of the publisher of the event @param is_new: if True, the item is a new one (no instance has been found in cache). If True, a "Create" activity will be generated, otherwise an "Update" one will @@ -236,9 +236,14 @@ activity["@context"].append(AP_EVENTS_CONTEXT) return activity - async def ap_item_2_event_data(self, ap_item: dict) -> dict: + async def ap_item_2_event_data( + self, + requestor_actor_id: str, + ap_item: dict + ) -> dict: """Convert AP activity or object to event data + @param requestor_actor_id: ID of the actor doing the request. @param ap_item: ActivityPub item to convert Can be either an activity of an object @return: AP Item's Object and event data @@ -246,7 +251,7 @@ """ is_activity = self.apg.is_activity(ap_item) if is_activity: - ap_object = await self.apg.ap_get_object(ap_item, "object") + ap_object = await self.apg.ap_get_object(requestor_actor_id, ap_item, "object") if not ap_object: log.warning(f'No "object" found in AP item {ap_item!r}') raise exceptions.DataError @@ -268,9 +273,9 @@ raise exceptions.DataError("AP Object is not an event") # author - actor = await self.apg.ap_get_sender_actor(ap_object) + actor = await self.apg.ap_get_sender_actor(requestor_actor_id, ap_object) - account = await self.apg.get_ap_account_from_id(actor) + account = await self.apg.get_ap_account_from_id(requestor_actor_id, actor) author_jid = self.apg.get_local_jid_from_account(account).full() # name, start, end @@ -370,7 +375,11 @@ # comments if ap_object.get("commentsEnabled"): - __, comments_node = await self.apg.get_comments_nodes(object_id, None) + __, comments_node = await self.apg.get_comments_nodes( + requestor_actor_id, + object_id, + None + ) event_data["comments"] = { "service": author_jid, "node": comments_node, @@ -391,17 +400,28 @@ async def ap_item_2_event_data_and_elt( self, + requestor_actor_id: str, ap_item: dict - ) -> Tuple[dict, domish.Element]: + ) -> tuple[dict, domish.Element]: """Convert AP item to parsed event data and corresponding item element""" - event_data = await self.ap_item_2_event_data(ap_item) + event_data = await self.ap_item_2_event_data( + requestor_actor_id, + ap_item + ) event_elt = self._events.event_data_2_event_elt(event_data) item_elt = domish.Element((None, "item")) item_elt["id"] = event_data["id"] item_elt.addChild(event_elt) return event_data, item_elt - async def ap_item_2_event_elt(self, ap_item: dict) -> domish.Element: + async def ap_item_2_event_elt( + self, + requestor_actor_id: str, + ap_item: dict + ) -> domish.Element: """Convert AP item to XMPP item element""" - __, item_elt = await self.ap_item_2_event_data_and_elt(ap_item) + __, item_elt = await self.ap_item_2_event_data_and_elt( + requestor_actor_id, + ap_item + ) return item_elt