comparison libervia/backend/plugins/plugin_xep_0277.py @ 4178:cf0ea77f9537

plugin XEP-0277, doc: conflict is now checked and avoided if `user_friendly_id_suffix` is `False`, doc updated
author Goffi <goffi@goffi.org>
date Tue, 05 Dec 2023 13:39:03 +0100
parents 30f7513e5590
children c86a22009c1f
comparison
equal deleted inserted replaced
4177:0f1a4ffcd419 4178:cf0ea77f9537
1066 1066
1067 item_id = data.get("id") 1067 item_id = data.get("id")
1068 if item_id is None: 1068 if item_id is None:
1069 if data.get("user_friendly_id", True): 1069 if data.get("user_friendly_id", True):
1070 item_id = self.friendly_id(data) 1070 item_id = self.friendly_id(data)
1071 else: 1071 if not data.get("user_friendly_id_suffix", True):
1072 item_id = str(shortuuid.uuid()) 1072 # we have no random suffix, which can lead to conflict, so we check if
1073 # the item doesn't already exist, and change ID if it's the case.
1074 try:
1075 items, __ = await self._p.get_items(
1076 client,
1077 service,
1078 node,
1079 item_ids = [item_id]
1080 )
1081 except exceptions.NotFound:
1082 pass
1083 else:
1084 # the item already exists
1085 log.info(
1086 f"there is already an item with ID {item_id}, we have to "
1087 ' set the "user_friendly_id_suffix" flag.'
1088 )
1089 data["user_friendly_id_suffix"] = True
1090 item_id = self.friendly_id(data)
1073 1091
1074 try: 1092 try:
1075 await self._manage_comments(client, data, service, node, item_id, access=None) 1093 await self._manage_comments(client, data, service, node, item_id, access=None)
1076 except error.StanzaError: 1094 except error.StanzaError:
1077 log.warning("Can't create comments node for item {}".format(item_id)) 1095 log.warning("Can't create comments node for item {}".format(item_id))