Commit 8ff675f5 authored by Philipp Hörist's avatar Philipp Hörist

Properties: Add is_from_us()

parent cf2b471a
Pipeline #7230 failed with stages
in 2 minutes and 36 seconds
......@@ -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:
......
......@@ -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
......
......@@ -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()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment