Fix DeletePictureNotification

This commit is contained in:
moyamo 2016-01-07 23:04:20 +02:00
parent 8bbdbb970d
commit 2c2c0fde8d
3 changed files with 20 additions and 4 deletions

View File

@ -178,7 +178,10 @@ class BuddyList(dict):
# Get profile picture
self.logger.debug('Requesting profile picture of %s', buddy)
response = deferred.Deferred()
self.session.requestProfilePicture(buddy, onSuccess = response.run)
# Error probably means image doesn't exist
error = deferred.Deferred()
self.session.requestProfilePicture(buddy, onSuccess=response.run,
onFailure=error.run)
response = response.arg(0)
pictureData = response.pictureData()
@ -188,6 +191,9 @@ class BuddyList(dict):
ID, response.pictureId(), pictureData.then(base64.b64encode))
call(self.backend.handleVCard, self.user, ID, buddy, "", "",
pictureData)
# If error
error.when(self.logger.debug, 'Sending VCard (%s) without image', ID)
error.when(self.backend.handleVCard, self.user, ID, buddy, "", "", "")
# Send image hash
if not buddy == self.session.legacyName:
@ -201,6 +207,9 @@ class BuddyList(dict):
image_hash = pictureData.then(utils.sha1hash)
call(self.logger.debug, 'Image hash is %s', image_hash)
call(self.update, buddy, nick, groups, image_hash)
# No image
error.when(self.logger.debug, 'No image')
error.when(self.update, buddy, nick, groups, '')
def refresh(self, number):
self.session.unsubscribePresence(number)

View File

@ -67,6 +67,12 @@ class Deferred(object):
return args[n]
return self.then(helper)
def when(self, func, *args, **kwargs):
""" Calls when func(*args, **kwargs) when deferred gets a value """
def helper(*args2, **kwargs2):
func(*args, **kwargs)
self.then(helper)
def __getattr__(self, method_name):
return getattr(Then(self), method_name)
@ -103,7 +109,7 @@ def call(func, *args, **kwargs):
colors = Deferred()
colors.append('blue')
colors.run(['red', 'green'])
call(print, colors) #=> ['red', 'green', 'blue']
call(print, colors) #=> ['red', 'green', 'blue']
call(print, 'hi', colors) #=> hi ['red', 'green', 'blue']
"""
for i, c in enumerate(args):

View File

@ -766,9 +766,10 @@ class YowsupAppLayer(YowInterfaceLayer):
entity._from.split('@')[0],
entity.status
)
elif (isinstance(entity, SetPictureNotificationProtocolEntity) or
isinstance(entity, DeletePictureNotificationProtocolEntity)):
elif isinstance(entity, SetPictureNotificationProtocolEntity):
self.caller.onContactPictureChanged(entity.setJid.split('@')[0])
elif isinstance(entity, DeletePictureNotificationProtocolEntity):
self.caller.onContactPictureChanged(entity.deleteJid.split('@')[0])
elif isinstance(entity, RemoveContactNotificationProtocolEntity):
self.caller.onContactRemoved(entity.contactJid.split('@')[0])
elif isinstance(entity, AddContactNotificationProtocolEntity):