From 133fe9c6febee6679614bf7c464a7f2176a607c8 Mon Sep 17 00:00:00 2001 From: Goffi Date: Wed, 13 Dec 2023 22:00:25 +0100 Subject: [PATCH] plugin XEP-0444: fix emoji check and ID used --- libervia/backend/plugins/plugin_xep_0444.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/libervia/backend/plugins/plugin_xep_0444.py b/libervia/backend/plugins/plugin_xep_0444.py index a61466c2..511ec7e8 100644 --- a/libervia/backend/plugins/plugin_xep_0444.py +++ b/libervia/backend/plugins/plugin_xep_0444.py @@ -88,7 +88,7 @@ class XEP_0444: """ 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 @@ class XEP_0444: 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 @@ class XEP_0444: """Send the stanza containing the reactions @param dest_jid: recipient of the reaction - @param message_id: either 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 @@ class XEP_0444: 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: - mess_id = history.origin_id - else: + if history.type == C.MESS_TYPE_GROUPCHAT: mess_id = history.stanza_id + else: + mess_id = history.origin_id if mess_id is None: raise exceptions.DataError(