comparison sat/plugins/plugin_comp_ap_gateway/__init__.py @ 3853:a56d5ad466b3

component AP gateway: fix wrong exception + use of mb_data["xml"] when it may be absent
author Goffi <goffi@goffi.org>
date Thu, 14 Jul 2022 12:55:30 +0200
parents 384ad98ea9fe
children 54305ebf5b94
comparison
equal deleted inserted replaced
3852:384ad98ea9fe 3853:a56d5ad466b3
1402 1402
1403 @param ap_item: ActivityPub item to convert 1403 @param ap_item: ActivityPub item to convert
1404 Can be either an activity of an object 1404 Can be either an activity of an object
1405 @return: AP Item's Object and microblog data 1405 @return: AP Item's Object and microblog data
1406 @raise exceptions.DataError: something is invalid in the AP item 1406 @raise exceptions.DataError: something is invalid in the AP item
1407 @raise NotImplemented: some AP data is not handled yet 1407 @raise NotImplementedError: some AP data is not handled yet
1408 @raise error.StanzaError: error while contacting the AP server 1408 @raise error.StanzaError: error while contacting the AP server
1409 """ 1409 """
1410 is_activity = self.isActivity(ap_item) 1410 is_activity = self.isActivity(ap_item)
1411 if is_activity: 1411 if is_activity:
1412 ap_object = await self.apGetObject(ap_item, "object") 1412 ap_object = await self.apGetObject(ap_item, "object")
1749 this method handle the conversion to AP items and posting 1749 this method handle the conversion to AP items and posting
1750 """ 1750 """
1751 if client != self.client: 1751 if client != self.client:
1752 return mess_data 1752 return mess_data
1753 if mess_data["type"] not in ("chat", "normal"): 1753 if mess_data["type"] not in ("chat", "normal"):
1754 log.warning(f"ignoring message with unexpected type: {mess_data['xml'].toXml()}") 1754 log.warning(f"ignoring message with unexpected type: {mess_data}")
1755 return mess_data 1755 return mess_data
1756 if not self.isLocal(mess_data["from"]): 1756 if not self.isLocal(mess_data["from"]):
1757 log.warning(f"ignoring non local message: {mess_data['xml'].toXml()}") 1757 log.warning(f"ignoring non local message: {mess_data}")
1758 return mess_data 1758 return mess_data
1759 if not mess_data["to"].user: 1759 if not mess_data["to"].user:
1760 log.warning( 1760 log.warning(
1761 f"ignoring message addressed to gateway itself: {mess_data['xml'].toXml()}" 1761 f"ignoring message addressed to gateway itself: {mess_data}"
1762 ) 1762 )
1763 return mess_data 1763 return mess_data
1764 1764
1765 actor_account = self._e.unescape(mess_data["to"].user) 1765 actor_account = self._e.unescape(mess_data["to"].user)
1766 actor_id = await self.getAPActorIdFromAccount(actor_account) 1766 actor_id = await self.getAPActorIdFromAccount(actor_account)
1965 comment_node = parent_item_parsed["comments"][0]["node"] 1965 comment_node = parent_item_parsed["comments"][0]["node"]
1966 except (KeyError, IndexError): 1966 except (KeyError, IndexError):
1967 # we don't have a comment node set for this item 1967 # we don't have a comment node set for this item
1968 from sat.tools.xml_tools import ppElt 1968 from sat.tools.xml_tools import ppElt
1969 log.info(f"{ppElt(parent_item_elt.toXml())}") 1969 log.info(f"{ppElt(parent_item_elt.toXml())}")
1970 raise NotImplemented() 1970 raise NotImplementedError()
1971 else: 1971 else:
1972 __, item_elt = await self.apItem2MbDataAndElt(ap_item) 1972 __, item_elt = await self.apItem2MbDataAndElt(ap_item)
1973 await self._p.publish(client, comment_service, comment_node, [item_elt]) 1973 await self._p.publish(client, comment_service, comment_node, [item_elt])
1974 await self.notifyMentions( 1974 await self.notifyMentions(
1975 targets, mentions, comment_service, comment_node, item_elt["id"] 1975 targets, mentions, comment_service, comment_node, item_elt["id"]