Philipp Hörist pushed to branch nbxmpp_2.0 at gajim / python-nbxmpp
Commits: 3d8345c7 by lovetox at 2021-02-06T13:47:36+01:00 Properties: Add is_from_us()
- - - - -
3 changed files:
- nbxmpp/dispatcher.py - nbxmpp/structs.py - nbxmpp/util.py
Changes:
===================================== nbxmpp/dispatcher.py ===================================== @@ -369,7 +369,7 @@ class StanzaDispatcher(Observable): return
own_jid = self._client.get_bound_jid() - properties = get_properties_struct(name) + properties = get_properties_struct(name, own_jid)
if name == 'iq': if stanza.getFrom() is None and own_jid is not None:
===================================== nbxmpp/structs.py ===================================== @@ -649,7 +649,8 @@ class Properties:
class MessageProperties: - def __init__(self): + def __init__(self, own_jid): + self._own_jid = own_jid self.carbon = None self.type = MessageType.NORMAL self.id = None @@ -696,6 +697,14 @@ class MessageProperties: self.security_label = None self.chatstate = None
+ def is_from_us(self, bare_match=True): + if self.from_ is None: + raise ValueError('from attribute missing') + + if bare_match: + return self._own_jid.bare_match(self.from_) + return self._own_jid == self.from_ + @property def has_user_delay(self): return self.user_timestamp is not None @@ -813,7 +822,8 @@ class MessageProperties:
class IqProperties: - def __init__(self): + def __init__(self, own_jid): + self._own_jid = own_jid self.type = None self.jid = None self.id = None @@ -838,7 +848,8 @@ class IqProperties:
class PresenceProperties: - def __init__(self): + def __init__(self, own_jid): + self._own_jid = own_jid self.type = None self.priority = None self.show = None
===================================== nbxmpp/util.py ===================================== @@ -70,13 +70,13 @@ def b64encode(data, return_type=str): return result.decode()
-def get_properties_struct(name): +def get_properties_struct(name, own_jid): if name == 'message': - return MessageProperties() + return MessageProperties(own_jid) if name == 'iq': - return IqProperties() + return IqProperties(own_jid) if name == 'presence': - return PresenceProperties() + return PresenceProperties(own_jid) return Properties()
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/-/commit/3d8345c7ea51b7b248161e2fd...