From bbc038ec46d63dff0dcb79fc4f29d32fc5a4c67f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Mon, 3 Dec 2018 15:40:43 +0100 Subject: [PATCH] Handle presence without from attr correctly Fixes #9472 --- gajim/common/modules/caps.py | 11 +++++++++-- gajim/common/modules/chatstates.py | 4 ++-- gajim/common/modules/vcard_avatars.py | 7 +++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/gajim/common/modules/caps.py b/gajim/common/modules/caps.py index 959060a37..23433cbd2 100644 --- a/gajim/common/modules/caps.py +++ b/gajim/common/modules/caps.py @@ -42,6 +42,15 @@ class Caps: self._create_suitable_client_caps = caps_cache.create_suitable_client_caps def _presence_received(self, _con, stanza): + if stanza.getType() in ('unavailable', 'error'): + return + + from_ = stanza.getFrom() + if from_ is None: + # Presence from ourself + return + full_jid = str(from_) + hash_method = node = caps_hash = None caps = stanza.getTag('c', namespace=nbxmpp.NS_CAPS) @@ -50,8 +59,6 @@ class Caps: node = caps['node'] caps_hash = caps['ver'] - from_ = stanza.getFrom() - full_jid = str(from_) show = parse_show(stanza) type_ = parse_type(stanza) diff --git a/gajim/common/modules/chatstates.py b/gajim/common/modules/chatstates.py index 29e7d7cf5..f01268d2e 100644 --- a/gajim/common/modules/chatstates.py +++ b/gajim/common/modules/chatstates.py @@ -74,8 +74,8 @@ class Chatstate: return full_jid = stanza.getFrom() - - if self._con.get_own_jid().bareMatch(full_jid): + if full_jid is None or self._con.get_own_jid().bareMatch(full_jid): + # Presence from ourself return contact = app.contacts.get_gc_contact( diff --git a/gajim/common/modules/vcard_avatars.py b/gajim/common/modules/vcard_avatars.py index b08eddb55..a0a764f36 100644 --- a/gajim/common/modules/vcard_avatars.py +++ b/gajim/common/modules/vcard_avatars.py @@ -51,12 +51,15 @@ class VCardAvatars: app.config.set_per('accounts', self._account, 'avatar_sha', '') def _presence_received(self, _con, stanza): - update = stanza.getTag('x', namespace=nbxmpp.NS_VCARD_UPDATE) - if update is None: + if stanza.getType() in ('unavailable', 'error'): return jid = stanza.getFrom() + update = stanza.getTag('x', namespace=nbxmpp.NS_VCARD_UPDATE) + if update is None: + return + avatar_sha = update.getTagData('photo') if avatar_sha is None: log.info('%s is not ready to promote an avatar', jid)