Philipp Hörist pushed to branch reactions at gajim / gajim


Commits:
331b680f by Philipp Hörist at 2024-05-20T15:50:15+02:00
refactor: Restrict handled message types for reactions

- - - - -


2 changed files:

- gajim/common/modules/message.py
- gajim/common/modules/reactions.py


Changes:

=====================================
gajim/common/modules/message.py
=====================================
@@ -24,6 +24,7 @@
 from gajim.common.events import RawMessageReceived
 from gajim.common.events import ReactionUpdated
 from gajim.common.modules.base import BaseModule
+from gajim.common.modules.contacts import GroupchatParticipant
 from gajim.common.modules.message_util import convert_message_type
 from gajim.common.modules.message_util import get_chat_type_and_direction
 from gajim.common.modules.message_util import get_eme_message
@@ -112,20 +113,23 @@ def _message_received(self,
             # TODO: Check where in Gajim and plugins we depend on that behavior
             stanza.setFrom(stanza.getTo())
 
+        timestamp = get_message_timestamp(properties)
+        remote_jid = properties.remote_jid
+        jid = properties.jid
+        assert remote_jid is not None
+        assert jid is not None
+
         muc_data = None
         if properties.type.is_groupchat:
-            muc_data = self._client.get_module('MUC').get_muc_data(
-                properties.remote_jid)
+            muc_data = self._client.get_module('MUC').get_muc_data(remote_jid)
             if muc_data is None:
-                self._log.warning('Groupchat message from unknown MUC: %s',
-                 properties.remote_jid)
+                self._log.warning(
+                    'Groupchat message from unknown MUC: %s', remote_jid
+                )
                 return
 
         m_type, direction = get_chat_type_and_direction(
             muc_data, self._client.get_own_jid(), properties)
-        timestamp = get_message_timestamp(properties)
-        remote_jid = properties.remote_jid
-        assert remote_jid is not None
 
         user_delay_ts = None
         if properties.user_timestamp is not None:
@@ -168,9 +172,12 @@ def _message_received(self,
                 return
 
         occupant = None
-        if m_type in (MessageType.GROUPCHAT, MessageType.PM):
+        if (m_type in (MessageType.GROUPCHAT, MessageType.PM)
+                and not jid.is_bare):
+
             contact = self._client.get_module('Contacts').get_contact(
-                    properties.jid, groupchat=True)
+                    jid, groupchat=True)
+            assert isinstance(contact, GroupchatParticipant)
 
             occupant = get_occupant_info(
                 self._account,
@@ -231,7 +238,7 @@ def _message_received(self,
             direction=direction,
             timestamp=timestamp,
             state=MessageState.ACKNOWLEDGED,
-            resource=properties.jid.resource,
+            resource=jid.resource,
             text=message_text,
             id=message_id,
             stanza_id=stanza_id,


=====================================
gajim/common/modules/reactions.py
=====================================
@@ -53,8 +53,23 @@ def _process_reaction(
         if properties.reactions is None:
             return
 
+        if properties.type.is_normal or properties.type.is_headline:
+            self._log.warning(
+                'Reaction with undefined message type %s', properties.type
+            )
+            raise NodeProcessed
+
         if properties.type.is_error:
-            return
+            # TODO: Maybe inform the user and delete
+            # the reactions from the database
+            # But this handler here is only executed if the
+            # server adds the message content to the error
+            raise NodeProcessed
+
+        assert properties.jid is not None
+        if (properties.type.is_groupchat and properties.jid.is_bare):
+            # Reactions from the bare groupchat jid are not defined
+            raise NodeProcessed
 
         remote_jid = properties.remote_jid
         assert remote_jid is not None



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/331b680f795c20e2063277aacbaa542489ff88bc

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/331b680f795c20e2063277aacbaa542489ff88bc
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to