diff sat/plugins/plugin_comp_ap_gateway/__init__.py @ 3844:65e5718e7710

component AP gateway: `Announce` activity implementation: `Announce` and `Undo` of `Announce` are now implemented and converted to suitable XEP-0277 "repeat" items, or retract. rel 370
author Goffi <goffi@goffi.org>
date Thu, 14 Jul 2022 12:55:30 +0200
parents 17c757bd74bc
children 4f9d4650eab5
line wrap: on
line diff
--- a/sat/plugins/plugin_comp_ap_gateway/__init__.py	Thu Jul 14 12:55:30 2022 +0200
+++ b/sat/plugins/plugin_comp_ap_gateway/__init__.py	Thu Jul 14 12:55:30 2022 +0200
@@ -1267,7 +1267,10 @@
         item_elt = await self._m.data2entry(
             self.client, mb_data, mb_data["id"], None, self._m.namespace
         )
-        item_elt["publisher"] = mb_data["author_jid"]
+        if "repeated" in mb_data["extra"]:
+            item_elt["publisher"] = mb_data["extra"]["repeated"]["by"]
+        else:
+            item_elt["publisher"] = mb_data["author_jid"]
         return mb_data, item_elt
 
     async def apItem2Elt(self, ap_item: dict) -> domish.Element:
@@ -1360,6 +1363,8 @@
     async def apItem2MBdata(self, ap_item: dict) -> dict:
         """Convert AP activity or object to microblog data
 
+        @param ap_item: ActivityPub item to convert
+            Can be either an activity of an object
         @return: AP Item's Object and microblog data
         @raise exceptions.DataError: something is invalid in the AP item
         @raise NotImplemented: some AP data is not handled yet
@@ -1377,7 +1382,7 @@
         if not item_id:
             log.warning(f'No "id" found in AP item: {ap_object!r}')
             raise exceptions.DataError
-        mb_data = {"id": item_id}
+        mb_data = {"id": item_id, "extra": {}}
 
         # content
         try:
@@ -1428,6 +1433,10 @@
                 except dateutil.parser.ParserError as e:
                     log.warning(f"Can't parse {field!r} field: {e}")
 
+        # repeat
+        if "_repeated" in ap_item:
+            mb_data["extra"]["repeated"] = ap_item["_repeated"]
+
         # comments
         in_reply_to = ap_object.get("inReplyTo")
         __, comments_node = await self.getCommentsNodes(item_id, in_reply_to)
@@ -2194,6 +2203,7 @@
         @param node: XMPP pubsub node
         @param activity: parent AP activity
         @param item: AP object payload
+            only the "id" field is used
         """
         item_id = item.get("id")
         if not item_id: