Commit 56f7af5c authored by Andrey Gursky's avatar Andrey Gursky

Add photo hash mismatch to avatar logs

If photo hash is advertized in presence and the photo hash is not yet known,
vcard is being requested. After vcard has been received at least two failures
can occur:
- there is no photo at all;
- photo has different hash than advertized.
Let log them for quick identification

Addresses: #9171
parent ce789254
Pipeline #1610 passed with stages
in 1 minute and 49 seconds
......@@ -358,7 +358,7 @@ class ConnectionVcard:
else:
app.log('avatar').info(
'Request (vCard): %s', obj.jid)
self.request_vcard(self._on_avatar_received, obj.jid)
self.request_vcard(self._on_avatar_received, obj.jid, photo_hash=obj.avatar_sha)
else:
app.log('avatar').info(
......@@ -398,7 +398,7 @@ class ConnectionVcard:
app.log('avatar').info(
'Request (vCard): %s', obj.nick)
obj.conn.request_vcard(
self._on_avatar_received, obj.fjid, room=True)
self._on_avatar_received, obj.fjid, room=True, photo_hash=obj.avatar_sha)
return
if gc_contact.avatar_sha != obj.avatar_sha:
......@@ -437,7 +437,7 @@ class ConnectionVcard:
dict_[name][c.getName()] = c.getData()
return dict_
def request_vcard(self, callback, jid=None, room=False):
def request_vcard(self, callback, jid=None, room=False, photo_hash=None):
"""
Request the VCARD
"""
......@@ -455,7 +455,7 @@ class ConnectionVcard:
iq.setQuery('vCard').setNamespace(nbxmpp.NS_VCARD)
self.connection.SendAndCallForResponse(
iq, self._parse_vcard, {'callback': callback})
iq, self._parse_vcard, {'callback': callback, 'photo_hash': photo_hash})
def send_vcard(self, vcard, sha):
if not self.connection or self.connected < 2:
......@@ -537,7 +537,7 @@ class ConnectionVcard:
return avatar_sha, photo_decoded
def _parse_vcard(self, con, stanza, callback):
def _parse_vcard(self, con, stanza, callback, photo_hash):
frm_jid = stanza.getFrom()
room = False
if frm_jid is None:
......@@ -553,7 +553,7 @@ class ConnectionVcard:
'not-allowed'):
app.log('avatar').info('vCard not available: %s %s',
frm_jid, stanza_error)
callback(jid, resource, room, {})
callback(jid, resource, room, {}, photo_hash)
return
vcard_node = stanza.getTag('vCard', namespace=nbxmpp.NS_VCARD)
......@@ -572,9 +572,9 @@ class ConnectionVcard:
app.nec.push_incoming_event(
VcardReceivedEvent(None, conn=self, vcard_dict=vcard))
callback(jid, resource, room, vcard)
callback(jid, resource, room, vcard, photo_hash)
def _on_own_avatar_received(self, jid, resource, room, vcard):
def _on_own_avatar_received(self, jid, resource, room, vcard, photo_hash=None):
avatar_sha, photo_decoded = self._get_vcard_photo(vcard, jid)
......@@ -610,7 +610,7 @@ class ConnectionVcard:
self.send_avatar_presence()
self.avatar_presence_sent = True
def _on_room_avatar_received(self, jid, resource, room, vcard):
def _on_room_avatar_received(self, jid, resource, room, vcard, photo_hash=None):
avatar_sha, photo_decoded = self._get_vcard_photo(vcard, jid)
app.interface.save_avatar(photo_decoded)
......@@ -618,7 +618,7 @@ class ConnectionVcard:
app.contacts.set_avatar(self.name, jid, avatar_sha)
app.interface.update_avatar(self.name, jid, room_avatar=True)
def _on_avatar_received(self, jid, resource, room, vcard):
def _on_avatar_received(self, jid, resource, room, vcard, photo_hash):
"""
Called when we receive a vCard Parse the vCard and trigger Events
"""
......@@ -629,12 +629,18 @@ class ConnectionVcard:
if room:
app.log('avatar').info(
'Received (vCard): %s %s', resource, avatar_sha)
if avatar_sha != photo_hash:
app.log('avatar').warning(
'Photo hash mismatch, requested %s', photo_hash)
contact = app.contacts.get_gc_contact(self.name, jid, resource)
if contact is not None:
contact.avatar_sha = avatar_sha
app.interface.update_avatar(contact=contact)
else:
app.log('avatar').info('Received (vCard): %s %s', jid, avatar_sha)
if avatar_sha != photo_hash:
app.log('avatar').warning(
'Photo hash mismatch, requested %s', photo_hash)
own_jid = self.get_own_jid().getStripped()
app.logger.set_avatar_sha(own_jid, jid, avatar_sha)
app.contacts.set_avatar(self.name, jid, avatar_sha)
......
......@@ -261,7 +261,7 @@ class ProfileWindow:
self.progressbar.set_fraction(0)
self.update_progressbar_timeout_id = None
def _nec_vcard_received(self, jid, resource, room, vcard_):
def _nec_vcard_received(self, jid, resource, room, vcard_, photo_hash=None):
self.set_values(vcard_)
def add_to_vcard(self, vcard_, entry, txt):
......
......@@ -266,7 +266,7 @@ class VcardWindow:
widget.set_text('')
self.xml.get_object('DESC_textview').get_buffer().set_text('')
def _nec_vcard_received(self, jid, resource, room, vcard):
def _nec_vcard_received(self, jid, resource, room, vcard, photo_hash=None):
self.clear_values()
self._set_values(vcard, jid)
......
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