Update buddies status when a notification is received

This commit is contained in:
moyamo 2015-12-14 20:27:10 +02:00
parent 7b327c2d0f
commit 16bdc85471
2 changed files with 25 additions and 0 deletions

View file

@ -447,6 +447,16 @@ class Session(YowsupApp):
room, participants) room, participants)
self.groups[room].removeParticipants(participants) self.groups[room].removeParticipants(participants)
# Called by superclass
def onContactStatusChanged(self, number, status):
self.logger.debug("%s changed their status to %s", number, status)
try:
buddy = self.buddies[number]
buddy.statusMsg = status
self.buddies.updateSpectrum(buddy)
except KeyError:
self.logger.debug("%s not in buddy list", number)
def onPresenceReceived(self, _type, name, jid, lastseen): def onPresenceReceived(self, _type, name, jid, lastseen):
self.logger.info("Presence received: %s %s %s %s", _type, name, jid, lastseen) self.logger.info("Presence received: %s %s %s %s", _type, name, jid, lastseen)
buddy = jid.split("@")[0] buddy = jid.split("@")[0]

View file

@ -35,6 +35,7 @@ from yowsup.layers.protocol_chatstate.protocolentities import *
from yowsup.layers.protocol_contacts.protocolentities import * from yowsup.layers.protocol_contacts.protocolentities import *
from yowsup.layers.protocol_groups.protocolentities import * from yowsup.layers.protocol_groups.protocolentities import *
from yowsup.layers.protocol_media.protocolentities import * from yowsup.layers.protocol_media.protocolentities import *
from yowsup.layers.protocol_notifications.protocolentities import *
from yowsup.layers.protocol_messages.protocolentities import * from yowsup.layers.protocol_messages.protocolentities import *
from yowsup.layers.protocol_presence.protocolentities import * from yowsup.layers.protocol_presence.protocolentities import *
from yowsup.layers.protocol_profiles.protocolentities import * from yowsup.layers.protocol_profiles.protocolentities import *
@ -545,6 +546,15 @@ class YowsupApp(object):
""" """
pass pass
def onContactStatusChanged(self, number, status):
"""Called when a contacts changes their status
Args
number: (str) the number of the contact who changed their status
status: (str) the new status
"""
pass
def sendEntity(self, entity): def sendEntity(self, entity):
"""Sends an entity down the stack (as if YowsupAppLayer called toLower)""" """Sends an entity down the stack (as if YowsupAppLayer called toLower)"""
self.stack.broadcastEvent(YowLayerEvent(YowsupAppLayer.TO_LOWER_EVENT, self.stack.broadcastEvent(YowLayerEvent(YowsupAppLayer.TO_LOWER_EVENT,
@ -651,6 +661,11 @@ class YowsupAppLayer(YowInterfaceLayer):
entity.getGroupId().split('@')[0], entity.getGroupId().split('@')[0],
entity.getParticipants().keys() entity.getParticipants().keys()
) )
elif isinstance(entity, StatusNotificationProtocolEntity):
self.caller.onContactStatusChanged(
entity._from.split('@')[0],
entity.status
)
@ProtocolEntityCallback('message') @ProtocolEntityCallback('message')
def onMessageReceived(self, entity): def onMessageReceived(self, entity):