Mercurial > libervia-backend
comparison libervia/backend/plugins/plugin_xep_0277.py @ 4186:c86a22009c1f
plugin XEP-0277: fix comments node handling when parent node doesn't exist.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 11 Dec 2023 00:46:34 +0100 |
parents | cf0ea77f9537 |
children | 0d7bb4df2343 |
comparison
equal
deleted
inserted
replaced
4185:c6d85c31a59f | 4186:c86a22009c1f |
---|---|
826 | 826 |
827 ## comments ## | 827 ## comments ## |
828 for comments_data in mb_data.get('comments', []): | 828 for comments_data in mb_data.get('comments', []): |
829 link_elt = entry_elt.addElement("link") | 829 link_elt = entry_elt.addElement("link") |
830 # XXX: "uri" is set in self._manage_comments if not already existing | 830 # XXX: "uri" is set in self._manage_comments if not already existing |
831 link_elt["href"] = comments_data["uri"] | 831 try: |
832 link_elt["rel"] = "replies" | 832 link_elt["href"] = comments_data["uri"] |
833 link_elt["title"] = "comments" | 833 except KeyError: |
834 log.warning(f"missing URI in comments data: {comments_data}") | |
835 entry_elt.children.remove(link_elt) | |
836 else: | |
837 link_elt["rel"] = "replies" | |
838 link_elt["title"] = "comments" | |
834 | 839 |
835 if "repeated" in extra: | 840 if "repeated" in extra: |
836 try: | 841 try: |
837 repeated = extra["repeated"] | 842 repeated = extra["repeated"] |
838 link_elt = entry_elt.addElement("link") | 843 link_elt = entry_elt.addElement("link") |
935 | 940 |
936 # we have usually a single comment node, but the spec allow several, so we need to | 941 # we have usually a single comment node, but the spec allow several, so we need to |
937 # handle this in a list | 942 # handle this in a list |
938 if len(mb_data.setdefault('comments', [])) == 0: | 943 if len(mb_data.setdefault('comments', [])) == 0: |
939 # we need at least one comment node | 944 # we need at least one comment node |
940 comments_data = {} | |
941 mb_data['comments'].append({}) | 945 mb_data['comments'].append({}) |
942 | 946 |
943 if access is None: | 947 if access is None: |
944 # TODO: cache access models per service/node | 948 # TODO: cache access models per service/node |
945 parent_node_config = await self._p.getConfiguration(client, service, node) | 949 try: |
946 access = parent_node_config.get(self._p.OPT_ACCESS_MODEL, self._p.ACCESS_OPEN) | 950 parent_node_config = await self._p.getConfiguration(client, service, node) |
951 except error.StanzaError as e: | |
952 log.debug(f"Can't get parent node configuration: {e}") | |
953 access = self._p.ACCESS_OPEN | |
954 else: | |
955 access = parent_node_config.get(self._p.OPT_ACCESS_MODEL, self._p.ACCESS_OPEN) | |
947 | 956 |
948 options = { | 957 options = { |
949 self._p.OPT_ACCESS_MODEL: access, | 958 self._p.OPT_ACCESS_MODEL: access, |
950 self._p.OPT_MAX_ITEMS: "max", | 959 self._p.OPT_MAX_ITEMS: "max", |
951 self._p.OPT_PERSIST_ITEMS: 1, | 960 self._p.OPT_PERSIST_ITEMS: 1, |
1010 ) | 1019 ) |
1011 # …except for "member", that we transform to publisher | 1020 # …except for "member", that we transform to publisher |
1012 # because we wants members to be able to write to comments | 1021 # because we wants members to be able to write to comments |
1013 for jid_, affiliation in list(comments_affiliations.items()): | 1022 for jid_, affiliation in list(comments_affiliations.items()): |
1014 if affiliation == "member": | 1023 if affiliation == "member": |
1015 comments_affiliations[jid_] == "publisher" | 1024 comments_affiliations[jid_] = "publisher" |
1016 | 1025 |
1017 await self._p.set_node_affiliations( | 1026 await self._p.set_node_affiliations( |
1018 client, comments_service, comments_node, comments_affiliations | 1027 client, comments_service, comments_node, comments_affiliations |
1019 ) | 1028 ) |
1020 | 1029 |