Mercurial > libervia-backend
comparison libervia/backend/plugins/plugin_xep_0359.py @ 4156:2729d424dee7
plugin XEP-0359: use same ID as <message> for `origin_id`:
even if the XEP doesn't specify if Message ID must be the same as `origin_id`, using a
different one makes little sense, and is leading to bugs in other implementation (e.g.
Movim using the wrong ID for reactions).
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 22 Nov 2023 15:05:41 +0100 |
parents | 4b842c1fb686 |
children | 6784d07b99c8 |
comparison
equal
deleted
inserted
replaced
4155:453e53dfc50e | 4156:2729d424dee7 |
---|---|
63 if origin_id is not None: | 63 if origin_id is not None: |
64 mess_data['extra']['origin_id'] = origin_id | 64 mess_data['extra']['origin_id'] = origin_id |
65 return True | 65 return True |
66 | 66 |
67 def _send_message_data_trigger(self, client, mess_data): | 67 def _send_message_data_trigger(self, client, mess_data): |
68 origin_id = mess_data["extra"].get("origin_id") | 68 origin_id = mess_data["extra"].setdefault("origin_id", mess_data.get("uid")) |
69 if not origin_id: | 69 if not origin_id: |
70 origin_id = str(uuid.uuid4()) | 70 origin_id = str(uuid.uuid4()) |
71 mess_data["extra"]["origin_id"] = origin_id | 71 mess_data["extra"]["origin_id"] = origin_id |
72 message_elt = mess_data["xml"] | 72 message_elt = mess_data["xml"] |
73 self.add_origin_id(message_elt, origin_id) | 73 self.add_origin_id(message_elt, origin_id) |
114 except StopIteration: | 114 except StopIteration: |
115 return None | 115 return None |
116 else: | 116 else: |
117 return origin_elt.getAttribute("id") | 117 return origin_elt.getAttribute("id") |
118 | 118 |
119 def add_origin_id(self, element, origin_id=None): | 119 def add_origin_id(self, element: domish.Element, origin_id: str) -> None: |
120 """Add a <origin-id/> to a stanza | 120 """Add a <origin-id/> to a stanza |
121 | 121 |
122 @param element(domish.Element): stanza where the <origin-id/> must be added | 122 @param element(domish.Element): stanza where the <origin-id/> must be added |
123 @param origin_id(str): id to use, None to automatically generate | 123 @param origin_id(str): id to use, None to automatically generate |
124 @return (str): origin_id | 124 @return (str): origin_id |
125 """ | 125 """ |
126 if origin_id is None: | |
127 origin_id = str(uuid.uuid4()) | |
128 sid_elt = element.addElement((NS_SID, "origin-id")) | 126 sid_elt = element.addElement((NS_SID, "origin-id")) |
129 sid_elt["id"] = origin_id | 127 sid_elt["id"] = origin_id |
130 return origin_id | |
131 | 128 |
132 def get_handler(self, client): | 129 def get_handler(self, client): |
133 return XEP_0359_handler() | 130 return XEP_0359_handler() |
134 | 131 |
135 | 132 |