From 752be7bdb85932c5adc8714918c66637ea9faff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sun, 18 Jun 2023 16:28:47 +0200 Subject: feat: MessageProperties: Add remote_jid attribute --- nbxmpp/modules/message.py | 23 ++++++++++------------- nbxmpp/modules/muc/muc.py | 7 ------- nbxmpp/structs.py | 1 + 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/nbxmpp/modules/message.py b/nbxmpp/modules/message.py index 4036487..1af46e9 100644 --- a/nbxmpp/modules/message.py +++ b/nbxmpp/modules/message.py @@ -48,6 +48,9 @@ class BaseMessage(BaseModule): else: properties.jid = stanza.getFrom() + self._parse_if_private_message(stanza, properties) + + properties.remote_jid = self._determine_remote_jid(properties) properties.from_ = stanza.getFrom() properties.to = stanza.getTo() properties.id = stanza.getID() @@ -58,26 +61,20 @@ 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 + def _determine_remote_jid(self, properties): + if properties.is_muc_pm: + return properties.jid + return properties.jid.new_as_bare() + + def _parse_if_private_message(self, stanza, properties) -> None: muc_user = stanza.getTag('x', namespace=Namespace.MUC_USER) - if muc_user is not None: + if muc_user is 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 diff --git a/nbxmpp/modules/muc/muc.py b/nbxmpp/modules/muc/muc.py index 700a236..c7c66a9 100644 --- a/nbxmpp/modules/muc/muc.py +++ b/nbxmpp/modules/muc/muc.py @@ -245,13 +245,6 @@ class MUC(BaseModule): 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 - if properties.is_muc_invite_or_decline: return diff --git a/nbxmpp/structs.py b/nbxmpp/structs.py index 717d9d4..d21cce8 100644 --- a/nbxmpp/structs.py +++ b/nbxmpp/structs.py @@ -971,6 +971,7 @@ class MessageProperties: from_: Optional[JID] = None to: Optional[JID] = None jid: Optional[JID] = None + remote_jid: Optional[JID] = None subject = None body: Optional[str] = None thread: Optional[str] = None -- cgit v1.2.3