From a96ca2430e50fddfb4da19d00f3a1519d42e8331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sun, 18 Jun 2023 16:12:01 +0200 Subject: refactor: Simplify determining remote jid --- nbxmpp/modules/message.py | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/nbxmpp/modules/message.py b/nbxmpp/modules/message.py index 0088f94..4036487 100644 --- a/nbxmpp/modules/message.py +++ b/nbxmpp/modules/message.py @@ -42,17 +42,9 @@ class BaseMessage(BaseModule): def _process_message_base(self, _client, stanza, properties): properties.type = self._parse_type(stanza) - # Determine remote JID - if properties.is_carbon_message and properties.carbon.is_sent: + own_jid = self._client.get_bound_jid() + if own_jid.bare_match(stanza.getFrom()): properties.jid = stanza.getTo() - - elif properties.is_mam_message and not properties.type.is_groupchat: - own_jid = self._client.get_bound_jid() - if own_jid.bare_match(stanza.getFrom()): - properties.jid = stanza.getTo() - else: - properties.jid = stanza.getFrom() - else: properties.jid = stanza.getFrom() @@ -66,6 +58,27 @@ class BaseMessage(BaseModule): if properties.type.is_error: properties.error = error_factory(stanza) + def _determine_remote_jid(self, stanza, properties) -> None: + if properties.type.is_groupchat: + return + muc_user = stanza.getTag('x', namespace=Namespace.MUC_USER) + if muc_user is not None: + return + + occupant_id = stanza.getTagAttr('occupant-id', + 'id', + namespace=Namespace.OCCUPANT_ID) + + properties.occupant_id = occupant_id + + # MUC Private message + if (properties.type.is_chat or + properties.type.is_error and + not muc_user.getChildren()): + properties.muc_private_message = True + return + + def _process_message_after_base(self, _client, stanza, properties): # This handler runs after decryption handlers had the chance # to decrypt the body -- cgit v1.2.3