Mercurial > libervia-backend
comparison sat/plugins/plugin_comp_ap_gateway/__init__.py @ 3856:bc7f9d0a404f
component AP gateway: when a repeated blog post is retracted, it converted to suitable Activity:
when a retract item is received, the former item is now retrieve from cache, and if it was
a "repeat" blog post, it is converted to the suitable `Undo` of `Announce` activity
(instead of the default `Delete` activity).
rel 370
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 14 Jul 2022 12:55:30 +0200 |
parents | 54305ebf5b94 |
children | 59fbb66b2923 |
comparison
equal
deleted
inserted
replaced
3855:54305ebf5b94 | 3856:bc7f9d0a404f |
---|---|
1776 @param item_id: ID of the item to delete | 1776 @param item_id: ID of the item to delete |
1777 it's the Pubsub ID or message's origin ID | 1777 it's the Pubsub ID or message's origin ID |
1778 @param public: if True, the activity will be addressed to public namespace | 1778 @param public: if True, the activity will be addressed to public namespace |
1779 @return: actor_id of the entity deleting the item, activity to send | 1779 @return: actor_id of the entity deleting the item, activity to send |
1780 """ | 1780 """ |
1781 if node is None: | |
1782 node = self._m.namespace | |
1783 | |
1781 author_account = await self.getAPAccountFromJidAndNode(jid_, node) | 1784 author_account = await self.getAPAccountFromJidAndNode(jid_, node) |
1782 author_actor_id = self.buildAPURL(TYPE_ACTOR, author_account) | 1785 author_actor_id = self.buildAPURL(TYPE_ACTOR, author_account) |
1786 | |
1787 items = await self.host.memory.storage.searchPubsubItems({ | |
1788 "profiles": [self.client.profile], | |
1789 "services": [jid_], | |
1790 "names": [item_id] | |
1791 }) | |
1792 if not items: | |
1793 log.warning( | |
1794 f"Deleting an unknown item at service {jid_}, node {node} and id " | |
1795 f"{item_id}" | |
1796 ) | |
1797 else: | |
1798 try: | |
1799 mb_data = await self._m.item2mbdata(self.client, items[0].data, jid_, node) | |
1800 if "repeated" in mb_data["extra"]: | |
1801 # we are deleting a repeated item, we must translate this to an | |
1802 # "Undo" of the "Announce" activity instead of a "Delete" one | |
1803 announce = await self.repeatedMB2APItem(mb_data) | |
1804 undo = self.createActivity("Undo", author_actor_id, announce) | |
1805 return author_actor_id, undo | |
1806 except Exception as e: | |
1807 log.debug( | |
1808 f"Can't parse item, maybe it's not a blog item: {e}\n" | |
1809 f"{items[0].toXml()}" | |
1810 ) | |
1811 | |
1783 url_item = self.buildAPURL(TYPE_ITEM, author_account, item_id) | 1812 url_item = self.buildAPURL(TYPE_ITEM, author_account, item_id) |
1784 ap_item = self.createActivity( | 1813 ap_item = self.createActivity( |
1785 "Delete", | 1814 "Delete", |
1786 author_actor_id, | 1815 author_actor_id, |
1787 { | 1816 { |
1789 "type": TYPE_TOMBSTONE | 1818 "type": TYPE_TOMBSTONE |
1790 } | 1819 } |
1791 ) | 1820 ) |
1792 if public: | 1821 if public: |
1793 ap_item["to"] = [NS_AP_PUBLIC] | 1822 ap_item["to"] = [NS_AP_PUBLIC] |
1794 url_actor = author_actor_id | 1823 return author_actor_id, ap_item |
1795 return url_actor, ap_item | |
1796 | 1824 |
1797 def _messageReceivedTrigger( | 1825 def _messageReceivedTrigger( |
1798 self, | 1826 self, |
1799 client: SatXMPPEntity, | 1827 client: SatXMPPEntity, |
1800 message_elt: domish.Element, | 1828 message_elt: domish.Element, |