Allow user to set their whatsapp profile picture

This commit is contained in:
moyamo 2015-12-25 16:38:09 +02:00
parent dbf4a477ec
commit 8bbdbb970d
3 changed files with 21 additions and 3 deletions

View File

@ -142,3 +142,6 @@ class RegisterSession(YowsupApp):
def requestVCard(self, buddy, ID):
pass
def setProfilePicture(self, previewPicture, fullPicture = None):
pass

View File

@ -117,6 +117,10 @@ class WhatsAppBackend(SpectrumBackend):
self.logger.debug("handleVCardRequest(user=%s, buddy=%s, ID=%s)", user, buddy, ID)
self.sessions[user].requestVCard(buddy, ID)
def handleVCardUpdatedRequest(self, user, photo, nickname):
self.logger.debug("handleVCardUpdatedRequest(user=%s, nickname=%s)", user, photo, nickname)
self.session[user].setProfilePicture(photo)
def relogin(self, user, legacyName, password, extra):
"""
Used to re-initialize the session object. Used when finished with
@ -136,8 +140,6 @@ class WhatsAppBackend(SpectrumBackend):
def handleBuddyBlockToggled(self, user, buddy, blocked):
pass
def handleVCardUpdatedRequest(self, user, photo, nickname):
pass
def handleAttentionRequest(self, user, buddy, message):
pass

View File

@ -259,7 +259,20 @@ class YowsupApp(object):
"""
iq = SetStatusIqProtocolEntity(statusText)
self.sendIq(iq)
def setProfilePicture(self, previewPicture, fullPicture = None):
"""
Requests profile picture of whatsapp user
Args:
- previewPicture: (bytes) The preview picture
- fullPicture: (bytes) The full profile picture
"""
if fullPicture == None:
fullPicture = previewPicture
ownJid = self.stack.getLayerInterface(YowAuthenticationProtocolLayer).getUsername(full = True)
iq = SetPictureIqProtocolEntity(ownJid, previewPicture, fullPicture)
self.sendIq(iq)
def sendTyping(self, phoneNumber, typing):
"""
Notify buddy using phoneNumber that you are typing to him