changeset 4200:5d2de6c1156d

plugin XEP-0444: fix emoji check and ID used
author Goffi <goffi@goffi.org>
date Wed, 13 Dec 2023 22:00:25 +0100
parents 7eda7cb8a15c
children 6a8cc6d668a4
files libervia/backend/plugins/plugin_xep_0444.py
diffstat 1 files changed, 10 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/libervia/backend/plugins/plugin_xep_0444.py	Wed Dec 13 22:00:25 2023 +0100
+++ b/libervia/backend/plugins/plugin_xep_0444.py	Wed Dec 13 22:00:25 2023 +0100
@@ -88,7 +88,7 @@
         """
         profile_id = self.host.memory.storage.profiles[client.profile]
         async with self.host.memory.storage.session() as session:
-            if message_elt.type == C.MESS_TYPE_GROUPCHAT:
+            if message_elt.getAttribute("type") == C.MESS_TYPE_GROUPCHAT:
                 query = select(History).where(
                     History.profile_id == profile_id, History.stanza_id == reaction_id
                 )
@@ -126,8 +126,11 @@
                 reactions = set()
                 for reaction_elt in reactions_elt.elements("reaction"):
                     reaction = str(reaction_elt)
-                    if not emoji.is_emoji(reaction):
-                        log.warning(f"ignoring invalide reaction: {reaction_elt.toXml()}")
+                    if (
+                        not emoji.purely_emoji(reaction)
+                        or emoji.emoji_count(reaction) != 1
+                    ):
+                        log.warning(f"Ignoring invalid reaction: {reaction_elt.toXml()}.")
                         continue
                     reactions.add(reaction)
                 await self.update_history_reactions(client, history, from_jid, reactions)
@@ -184,7 +187,7 @@
         """Send the <message> stanza containing the reactions
 
         @param dest_jid: recipient of the reaction
-        @param message_id: either <origin-id> or message's ID
+        @param message_id: either origin ID or stanza ID
             see https://xmpp.org/extensions/xep-0444.html#business-id
         """
         message_elt = domish.Element((None, "message"))
@@ -312,10 +315,10 @@
             raise ValueError("message_id can't be empty")
 
         history = await self.get_history_from_uid(client, message_id)
-        if history.origin_id is not None:
+        if history.type == C.MESS_TYPE_GROUPCHAT:
+            mess_id = history.stanza_id
+        else:
             mess_id = history.origin_id
-        else:
-            mess_id = history.stanza_id
 
         if mess_id is None:
             raise exceptions.DataError(