diff options
author | Philipp Hörist <philipp@hoerist.com> | 2023-06-18 17:12:01 +0300 |
---|---|---|
committer | Philipp Hörist <philipp@hoerist.com> | 2023-06-18 22:30:24 +0300 |
commit | a96ca2430e50fddfb4da19d00f3a1519d42e8331 (patch) | |
tree | dea3f5f25d3e02cca61145502fa2982315b6d11f | |
parent | d350651b1054c08fa56dbd208f660e160ddcf399 (diff) |
refactor: Simplify determining remote jid
-rw-r--r-- | nbxmpp/modules/message.py | 33 |
1 files 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 |