diff libervia/backend/plugins/plugin_misc_lists.py @ 4271:a5d27f69eedb

plugin misc list: Comments node creation can now be specified with `comments` field in `extra`.
author Goffi <goffi@goffi.org>
date Thu, 20 Jun 2024 14:36:09 +0200
parents 0d7bb4df2343
children
line wrap: on
line diff
--- a/libervia/backend/plugins/plugin_misc_lists.py	Wed Jun 19 18:44:57 2024 +0200
+++ b/libervia/backend/plugins/plugin_misc_lists.py	Thu Jun 20 14:36:09 2024 +0200
@@ -322,13 +322,23 @@
         @param extra(dict, None): same as for [XEP-0060.send_item] with additional keys:
             - update(bool): if True, get previous item data to merge with current one
                 if True, item_id must be set
+            - comments(bool): indicate if a new comment node must be created.
+                If True a new comment node will be create, and replace existing one if
+                there is already one.
+                If not set, comment node will be create if not ``item_id`` is specified,
+                and won't be modified otherwise.
         other arguments are same as for [self._s.send_data_form_item]
         @return (unicode): id of the created item
         """
         if not node:
             node = self.namespace
 
-        if not item_id:
+        if extra is None:
+            extra = {}
+
+        # FIXME: presence of a field where comments node can be added must be checked.
+        add_comments_node = extra.get("comments")
+        if add_comments_node or (add_comments_node is None and not item_id):
             comments_service = await self._m.get_comments_service(client, service)
 
             # we need to use uuid for comments node, because we don't know item id in