comparison sat/plugins/plugin_xep_0277.py @ 3519:02eec2a5b5f9

plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`): Those methods recreate an item to given new ID, and if successful, delete the former one.
author Goffi <goffi@goffi.org>
date Sat, 01 May 2021 18:37:57 +0200
parents 753d151da886
children 13e7ef106589
comparison
equal deleted inserted replaced
3518:b258dce27d6d 3519:02eec2a5b5f9
119 "mbGet", 119 "mbGet",
120 ".plugin", 120 ".plugin",
121 in_sign="ssiasa{ss}s", 121 in_sign="ssiasa{ss}s",
122 out_sign="s", 122 out_sign="s",
123 method=self._mbGet, 123 method=self._mbGet,
124 async_=True,
125 )
126 host.bridge.addMethod(
127 "mbRename",
128 ".plugin",
129 in_sign="sssss",
130 out_sign="",
131 method=self._mbRename,
124 async_=True, 132 async_=True,
125 ) 133 )
126 host.bridge.addMethod( 134 host.bridge.addMethod(
127 "mbSetAccess", 135 "mbSetAccess",
128 ".plugin", 136 ".plugin",
811 client, comments_service, comments_node, comments_affiliations 819 client, comments_service, comments_node, comments_affiliations
812 ) 820 )
813 821
814 def friendlyId(self, data): 822 def friendlyId(self, data):
815 """Generate a user friendly id from title or content""" 823 """Generate a user friendly id from title or content"""
816 id_base = regex.urlFriendlyText(data.get('title') or data.get('content', '')) 824 # TODO: rich content should be converted to plain text
825 id_base = regex.urlFriendlyText(
826 data.get('title')
827 or data.get('title_rich')
828 or data.get('content')
829 or data.get('content_rich')
830 or ''
831 )
817 return f"{id_base}-{token_urlsafe(3)}" 832 return f"{id_base}-{token_urlsafe(3)}"
818 833
819 def _mbSend(self, service, node, data, profile_key): 834 def _mbSend(self, service, node, data, profile_key):
820 service = jid.JID(service) if service else None 835 service = jid.JID(service) if service else None
821 node = node if node else NS_MICROBLOG 836 node = node if node else NS_MICROBLOG
951 extra=extra, 966 extra=extra,
952 ) 967 )
953 mb_data = yield self._p.transItemsDataD( 968 mb_data = yield self._p.transItemsDataD(
954 items_data, partial(self.item2mbdata, client, service=service, node=node)) 969 items_data, partial(self.item2mbdata, client, service=service, node=node))
955 defer.returnValue(mb_data) 970 defer.returnValue(mb_data)
971
972 def _mbRename(self, service, node, item_id, new_id, profile_key):
973 return defer.ensureDeferred(self.mbRename(
974 self.host.getClient(profile_key),
975 jid.JID(service) if service else None,
976 node or None,
977 item_id,
978 new_id
979 ))
980
981 async def mbRename(
982 self,
983 client: SatXMPPEntity,
984 service: Optional[jid.JID],
985 node: Optional[str],
986 item_id: str,
987 new_id: str
988 ) -> None:
989 if not node:
990 node = NS_MICROBLOG
991 await self._p.renameItem(client, service, node, item_id, new_id)
956 992
957 def parseCommentUrl(self, node_url): 993 def parseCommentUrl(self, node_url):
958 """Parse a XMPP URI 994 """Parse a XMPP URI
959 995
960 Determine the fields comments_service and comments_node of a microblog data 996 Determine the fields comments_service and comments_node of a microblog data