| ... |
... |
@@ -289,13 +289,14 @@ class ConnectionVcard: |
|
289
|
289
|
self.own_vcard = None
|
|
290
|
290
|
self.room_jids = []
|
|
291
|
291
|
self.avatar_presence_sent = False
|
|
|
292
|
+ self._requested_shas = {}
|
|
292
|
293
|
|
|
293
|
294
|
app.ged.register_event_handler('presence-received', ged.GUI2,
|
|
294
|
|
- self._vcard_presence_received)
|
|
|
295
|
+ self._vcard_presence_received)
|
|
295
|
296
|
app.ged.register_event_handler('gc-presence-received', ged.GUI2,
|
|
296
|
|
- self._vcard_gc_presence_received)
|
|
|
297
|
+ self._vcard_gc_presence_received)
|
|
297
|
298
|
app.ged.register_event_handler('room-avatar-received', ged.GUI2,
|
|
298
|
|
- self._vcard_presence_received)
|
|
|
299
|
+ self._vcard_presence_received)
|
|
299
|
300
|
|
|
300
|
301
|
def _vcard_presence_received(self, obj):
|
|
301
|
302
|
if obj.conn.name != self.name:
|
| ... |
... |
@@ -342,28 +343,32 @@ class ConnectionVcard: |
|
342
|
343
|
'Update (vCard): %s %s', obj.jid, obj.avatar_sha)
|
|
343
|
344
|
current_sha = app.contacts.get_avatar_sha(self.name, obj.jid)
|
|
344
|
345
|
|
|
345
|
|
- if obj.avatar_sha != current_sha:
|
|
346
|
|
- if room_avatar:
|
|
347
|
|
- # We dont save the room avatar hash in our DB, so check
|
|
348
|
|
- # if we previously downloaded it
|
|
349
|
|
- if app.interface.avatar_exists(obj.avatar_sha):
|
|
350
|
|
- app.contacts.set_avatar(self.name, obj.jid, obj.avatar_sha)
|
|
351
|
|
- app.interface.update_avatar(
|
|
352
|
|
- self.name, obj.jid, room_avatar=room_avatar)
|
|
353
|
|
- else:
|
|
354
|
|
- app.log('avatar').info(
|
|
355
|
|
- 'Request (vCard): %s', obj.jid)
|
|
356
|
|
- self.request_vcard(self._on_room_avatar_received, obj.jid)
|
|
|
346
|
+ if obj.avatar_sha == current_sha:
|
|
|
347
|
+ app.log('avatar').info(
|
|
|
348
|
+ 'Avatar already known (vCard): %s %s',
|
|
|
349
|
+ obj.jid, obj.avatar_sha)
|
|
|
350
|
+ return
|
|
357
|
351
|
|
|
358
|
|
- else:
|
|
|
352
|
+ if room_avatar:
|
|
|
353
|
+ # We dont save the room avatar hash in our DB, so check
|
|
|
354
|
+ # if we previously downloaded it
|
|
|
355
|
+ if app.interface.avatar_exists(obj.avatar_sha):
|
|
|
356
|
+ app.contacts.set_avatar(self.name, obj.jid, obj.avatar_sha)
|
|
|
357
|
+ app.interface.update_avatar(
|
|
|
358
|
+ self.name, obj.jid, room_avatar=room_avatar)
|
|
|
359
|
+ elif obj.jid not in self._requested_shas:
|
|
359
|
360
|
app.log('avatar').info(
|
|
360
|
361
|
'Request (vCard): %s', obj.jid)
|
|
361
|
|
- self.request_vcard(self._on_avatar_received, obj.jid)
|
|
|
362
|
+ self._requested_shas[obj.jid] = obj.avatar_sha
|
|
|
363
|
+ self.request_vcard(self._on_room_avatar_received, obj.jid)
|
|
|
364
|
+ return
|
|
362
|
365
|
|
|
363
|
|
- else:
|
|
|
366
|
+ if obj.jid not in self._requested_shas:
|
|
364
|
367
|
app.log('avatar').info(
|
|
365
|
|
- 'Avatar already known (vCard): %s %s',
|
|
366
|
|
- obj.jid, obj.avatar_sha)
|
|
|
368
|
+ 'Request (vCard): %s', obj.jid)
|
|
|
369
|
+ self._requested_shas[obj.jid] = obj.avatar_sha
|
|
|
370
|
+ self.request_vcard(self._on_avatar_received, obj.jid)
|
|
|
371
|
+
|
|
367
|
372
|
|
|
368
|
373
|
def _vcard_gc_presence_received(self, obj):
|
|
369
|
374
|
if obj.conn.name != self.name:
|
| ... |
... |
@@ -395,10 +400,12 @@ class ConnectionVcard: |
|
395
|
400
|
'Update (vCard): %s %s', obj.nick, obj.avatar_sha)
|
|
396
|
401
|
path = os.path.join(configpaths.get('AVATAR'), obj.avatar_sha)
|
|
397
|
402
|
if not os.path.isfile(path):
|
|
398
|
|
- app.log('avatar').info(
|
|
399
|
|
- 'Request (vCard): %s', obj.nick)
|
|
400
|
|
- obj.conn.request_vcard(
|
|
401
|
|
- self._on_avatar_received, obj.fjid, room=True)
|
|
|
403
|
+ if obj.fjid not in self._requested_shas:
|
|
|
404
|
+ app.log('avatar').info(
|
|
|
405
|
+ 'Request (vCard): %s', obj.nick)
|
|
|
406
|
+ self._requested_shas[obj.fjid] = obj.avatar_sha
|
|
|
407
|
+ obj.conn.request_vcard(
|
|
|
408
|
+ self._on_avatar_received, obj.fjid, room=True)
|
|
402
|
409
|
return
|
|
403
|
410
|
|
|
404
|
411
|
if gc_contact.avatar_sha != obj.avatar_sha:
|
| ... |
... |
@@ -531,7 +538,8 @@ class ConnectionVcard: |
|
531
|
538
|
try:
|
|
532
|
539
|
photo_decoded = base64.b64decode(photo.encode('utf-8'))
|
|
533
|
540
|
except binascii.Error as error:
|
|
534
|
|
- app.log('avatar').warning('Invalid avatar for %s: %s', jid, error)
|
|
|
541
|
+ app.log('avatar').warning('Invalid avatar for %s: %s',
|
|
|
542
|
+ jid, error)
|
|
535
|
543
|
return None, None
|
|
536
|
544
|
avatar_sha = hashlib.sha1(photo_decoded).hexdigest()
|
|
537
|
545
|
|
| ... |
... |
@@ -612,7 +620,14 @@ class ConnectionVcard: |
|
612
|
620
|
|
|
613
|
621
|
def _on_room_avatar_received(self, jid, resource, room, vcard):
|
|
614
|
622
|
avatar_sha, photo_decoded = self._get_vcard_photo(vcard, jid)
|
|
|
623
|
+ expected_avatar_sha = self._requested_shas[jid]
|
|
|
624
|
+ if expected_avatar_sha != avatar_sha:
|
|
|
625
|
+ app.log('avatar').warning(
|
|
|
626
|
+ 'Avatar mismatch (vCard): %s %s', jid, avatar_sha)
|
|
|
627
|
+ return
|
|
|
628
|
+
|
|
615
|
629
|
app.interface.save_avatar(photo_decoded)
|
|
|
630
|
+ self._requested_shas.pop(jid)
|
|
616
|
631
|
|
|
617
|
632
|
app.log('avatar').info('Received (vCard): %s %s', jid, avatar_sha)
|
|
618
|
633
|
app.contacts.set_avatar(self.name, jid, avatar_sha)
|
| ... |
... |
@@ -622,8 +637,19 @@ class ConnectionVcard: |
|
622
|
637
|
"""
|
|
623
|
638
|
Called when we receive a vCard Parse the vCard and trigger Events
|
|
624
|
639
|
"""
|
|
625
|
|
- avatar_sha, photo_decoded = self._get_vcard_photo(vcard, jid)
|
|
|
640
|
+ request_jid = jid
|
|
|
641
|
+ if room:
|
|
|
642
|
+ request_jid = '%s/%s' % (jid, resource)
|
|
|
643
|
+
|
|
|
644
|
+ avatar_sha, photo_decoded = self._get_vcard_photo(vcard, request_jid)
|
|
|
645
|
+ expected_avatar_sha = self._requested_shas[request_jid]
|
|
|
646
|
+ if expected_avatar_sha != avatar_sha:
|
|
|
647
|
+ app.log('avatar').warning(
|
|
|
648
|
+ 'Avatar mismatch (vCard): %s %s', request_jid, avatar_sha)
|
|
|
649
|
+ return
|
|
|
650
|
+
|
|
626
|
651
|
app.interface.save_avatar(photo_decoded)
|
|
|
652
|
+ self._requested_shas.pop(request_jid)
|
|
627
|
653
|
|
|
628
|
654
|
# Received vCard from a contact
|
|
629
|
655
|
if room:
|