diff --git a/session.py b/session.py index 2455f9e..becacb5 100644 --- a/session.py +++ b/session.py @@ -457,6 +457,11 @@ class Session(YowsupApp): except KeyError: self.logger.debug("%s not in buddy list", number) + # Called by superclass + def onContactPictureChanged(self, number): + self.logger.debug("%s changed their profile picture", number) + self.buddies.requestVCard(number) + def onPresenceReceived(self, _type, name, jid, lastseen): self.logger.info("Presence received: %s %s %s %s", _type, name, jid, lastseen) buddy = jid.split("@")[0] @@ -471,7 +476,7 @@ class Session(YowsupApp): if (lastseen == str(buddy.lastseen)) and (_type == buddy.presence): return - if ((lastseen != "deny") and (lastseen != None) and (lastseen != "none")): + if ((lastseen != "deny") and (lastseen != None) and (lastseen != "none")): buddy.lastseen = int(lastseen) if (_type == None): buddy.lastseen = time.time() diff --git a/yowsupwrapper.py b/yowsupwrapper.py index fa4819a..b0ed44b 100644 --- a/yowsupwrapper.py +++ b/yowsupwrapper.py @@ -549,12 +549,19 @@ class YowsupApp(object): def onContactStatusChanged(self, number, status): """Called when a contacts changes their status - Args + Args: number: (str) the number of the contact who changed their status status: (str) the new status """ pass + def onContactPictureChanged(self, number): + """Called when a contact changes their profile picture + Args + number: (str) the number of the contact who changed their picture + """ + pass + def sendEntity(self, entity): """Sends an entity down the stack (as if YowsupAppLayer called toLower)""" self.stack.broadcastEvent(YowLayerEvent(YowsupAppLayer.TO_LOWER_EVENT, @@ -666,6 +673,9 @@ class YowsupAppLayer(YowInterfaceLayer): entity._from.split('@')[0], entity.status ) + elif (isinstance(entity, SetPictureNotificationProtocolEntity) or + isinstance(entity, DeletePictureNotificationProtocolEntity)): + self.caller.onContactPictureChanged(entity.setJid.split('@')[0]) @ProtocolEntityCallback('message') def onMessageReceived(self, entity):