Fix DeletePictureNotification
This commit is contained in:
parent
8bbdbb970d
commit
2c2c0fde8d
11
buddy.py
11
buddy.py
|
@ -178,7 +178,10 @@ class BuddyList(dict):
|
||||||
# Get profile picture
|
# Get profile picture
|
||||||
self.logger.debug('Requesting profile picture of %s', buddy)
|
self.logger.debug('Requesting profile picture of %s', buddy)
|
||||||
response = deferred.Deferred()
|
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)
|
response = response.arg(0)
|
||||||
|
|
||||||
pictureData = response.pictureData()
|
pictureData = response.pictureData()
|
||||||
|
@ -188,6 +191,9 @@ class BuddyList(dict):
|
||||||
ID, response.pictureId(), pictureData.then(base64.b64encode))
|
ID, response.pictureId(), pictureData.then(base64.b64encode))
|
||||||
call(self.backend.handleVCard, self.user, ID, buddy, "", "",
|
call(self.backend.handleVCard, self.user, ID, buddy, "", "",
|
||||||
pictureData)
|
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
|
# Send image hash
|
||||||
if not buddy == self.session.legacyName:
|
if not buddy == self.session.legacyName:
|
||||||
|
@ -201,6 +207,9 @@ class BuddyList(dict):
|
||||||
image_hash = pictureData.then(utils.sha1hash)
|
image_hash = pictureData.then(utils.sha1hash)
|
||||||
call(self.logger.debug, 'Image hash is %s', image_hash)
|
call(self.logger.debug, 'Image hash is %s', image_hash)
|
||||||
call(self.update, buddy, nick, groups, 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):
|
def refresh(self, number):
|
||||||
self.session.unsubscribePresence(number)
|
self.session.unsubscribePresence(number)
|
||||||
|
|
|
@ -67,6 +67,12 @@ class Deferred(object):
|
||||||
return args[n]
|
return args[n]
|
||||||
return self.then(helper)
|
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):
|
def __getattr__(self, method_name):
|
||||||
return getattr(Then(self), method_name)
|
return getattr(Then(self), method_name)
|
||||||
|
|
||||||
|
@ -103,7 +109,7 @@ def call(func, *args, **kwargs):
|
||||||
colors = Deferred()
|
colors = Deferred()
|
||||||
colors.append('blue')
|
colors.append('blue')
|
||||||
colors.run(['red', 'green'])
|
colors.run(['red', 'green'])
|
||||||
call(print, colors) #=> ['red', 'green', 'blue']
|
call(print, colors) #=> ['red', 'green', 'blue']
|
||||||
call(print, 'hi', colors) #=> hi ['red', 'green', 'blue']
|
call(print, 'hi', colors) #=> hi ['red', 'green', 'blue']
|
||||||
"""
|
"""
|
||||||
for i, c in enumerate(args):
|
for i, c in enumerate(args):
|
||||||
|
|
|
@ -766,9 +766,10 @@ class YowsupAppLayer(YowInterfaceLayer):
|
||||||
entity._from.split('@')[0],
|
entity._from.split('@')[0],
|
||||||
entity.status
|
entity.status
|
||||||
)
|
)
|
||||||
elif (isinstance(entity, SetPictureNotificationProtocolEntity) or
|
elif isinstance(entity, SetPictureNotificationProtocolEntity):
|
||||||
isinstance(entity, DeletePictureNotificationProtocolEntity)):
|
|
||||||
self.caller.onContactPictureChanged(entity.setJid.split('@')[0])
|
self.caller.onContactPictureChanged(entity.setJid.split('@')[0])
|
||||||
|
elif isinstance(entity, DeletePictureNotificationProtocolEntity):
|
||||||
|
self.caller.onContactPictureChanged(entity.deleteJid.split('@')[0])
|
||||||
elif isinstance(entity, RemoveContactNotificationProtocolEntity):
|
elif isinstance(entity, RemoveContactNotificationProtocolEntity):
|
||||||
self.caller.onContactRemoved(entity.contactJid.split('@')[0])
|
self.caller.onContactRemoved(entity.contactJid.split('@')[0])
|
||||||
elif isinstance(entity, AddContactNotificationProtocolEntity):
|
elif isinstance(entity, AddContactNotificationProtocolEntity):
|
||||||
|
|
Loading…
Reference in a new issue