comparison sat/plugins/plugin_comp_ap_gateway/__init__.py @ 3845:4f9d4650eab5

component AP gateway: use `createActivity` in `mbdata2APitem`
author Goffi <goffi@goffi.org>
date Thu, 14 Jul 2022 12:55:30 +0200
parents 65e5718e7710
children cc13efdd8360
comparison
equal deleted inserted replaced
3844:65e5718e7710 3845:4f9d4650eab5
800 self, 800 self,
801 activity: str, 801 activity: str,
802 actor_id: str, 802 actor_id: str,
803 object_: Optional[Union[str, dict]] = None, 803 object_: Optional[Union[str, dict]] = None,
804 target: Optional[Union[str, dict]] = None, 804 target: Optional[Union[str, dict]] = None,
805 activity_id: Optional[str] = None,
805 **kwargs, 806 **kwargs,
806 ) -> Dict[str, Any]: 807 ) -> Dict[str, Any]:
807 """Generate base data for an activity 808 """Generate base data for an activity
808 809
809 @param activity: one of ACTIVITY_TYPES 810 @param activity: one of ACTIVITY_TYPES
816 ) 817 )
817 if target is None and activity in ACTIVITY_TARGET_MANDATORY: 818 if target is None and activity in ACTIVITY_TARGET_MANDATORY:
818 raise exceptions.InternalError( 819 raise exceptions.InternalError(
819 f'"target" is mandatory for activity {activity!r}' 820 f'"target" is mandatory for activity {activity!r}'
820 ) 821 )
821 activity_id = f"{actor_id}#{activity.lower()}_{shortuuid.uuid()}" 822 if activity_id is None:
823 activity_id = f"{actor_id}#{activity.lower()}_{shortuuid.uuid()}"
822 data: Dict[str, Any] = { 824 data: Dict[str, Any] = {
823 "@context": "https://www.w3.org/ns/activitystreams", 825 "@context": "https://www.w3.org/ns/activitystreams",
824 "actor": actor_id, 826 "actor": actor_id,
825 "id": activity_id, 827 "id": activity_id,
826 "type": activity, 828 "type": activity,
1613 ap_account, 1615 ap_account,
1614 parent_item, 1616 parent_item,
1615 mb_data 1617 mb_data
1616 ) 1618 )
1617 1619
1618 ap_item = { 1620 return self.createActivity(
1619 "@context": "https://www.w3.org/ns/activitystreams", 1621 "Create", url_actor, ap_object, activity_id=url_item
1620 "id": url_item, 1622 )
1621 "type": "Create",
1622 "actor": url_actor,
1623 "object": ap_object
1624 }
1625
1626 return ap_item
1627 1623
1628 async def publishMessage( 1624 async def publishMessage(
1629 self, 1625 self,
1630 client: SatXMPPEntity, 1626 client: SatXMPPEntity,
1631 mess_data: dict, 1627 mess_data: dict,