Send presence requests

This commit is contained in:
moyamo 2015-06-21 17:16:04 +02:00
parent 8b6a12c798
commit 85c320e24c

View file

@ -175,7 +175,7 @@ class Session():
buddy = sender buddy = sender
if message == "\\lastseen": if message == "\\lastseen":
self.presenceRequested.append(buddy) self.presenceRequested.append(buddy)
self.call("presence_request", (buddy + "@s.whatsapp.net",)) self.call("presence_request", buddy = (buddy + "@s.whatsapp.net",))
else: else:
self.call("message_send", to=buddy + "@s.whatsapp.net", message=message) self.call("message_send", to=buddy + "@s.whatsapp.net", message=message)
@ -260,11 +260,6 @@ class Session():
else: else:
self.logger.warn("Room doesn't exist: %s", room) self.logger.warn("Room doesn't exist: %s", room)
def onDisconnected(self, reason):
self.logger.info("Disconnected from whatsapp: %s (%s)", self.legacyName, reason)
self.backend.handleDisconnected(self.user, 0, reason)
def onMediaReceived(self, messageId, jid, preview, url, size, receiptRequested, isBroadcast): def onMediaReceived(self, messageId, jid, preview, url, size, receiptRequested, isBroadcast):
buddy = jid.split("@")[0] buddy = jid.split("@")[0]
@ -434,7 +429,7 @@ class SpectrumLayer(YowInterfaceLayer):
elif layerEvent.getName() == YowNetworkLayer.EVENT_STATE_DISCONNECTED: elif layerEvent.getName() == YowNetworkLayer.EVENT_STATE_DISCONNECTED:
reason = layerEvent.getArg("reason") reason = layerEvent.getArg("reason")
self.logger.info("Disconnected: %s (%s)", self.user, reason) self.logger.info("Disconnected: %s (%s)", self.user, reason)
self.backend.handleDisconnected(sefl.user, 0, reason) self.backend.handleDisconnected(self.user, 0, reason)
elif layerEvent.getName() == 'presence_sendAvailable': elif layerEvent.getName() == 'presence_sendAvailable':
entity = AvailablePresenceProtocolEntity() entity = AvailablePresenceProtocolEntity()
self.toLower(entity) self.toLower(entity)
@ -467,10 +462,15 @@ class SpectrumLayer(YowInterfaceLayer):
) )
self.toLower(state) self.toLower(state)
retval = True retval = True
elif layerEvent.getName() == 'presence_request':
buddy = layerEvent.getArg('buddy')
sub = SubscribePresenceProtocolEntity(buddy)
self.toLower(sub)
self.logger.debug("EVENT %s", layerEvent.getName()) self.logger.debug("EVENT %s", layerEvent.getName())
return retval return retval
@ProtocolEntityCallback("success") @ProtocolEntityCallback("success")
def onAuthSuccess(self, entity): def onAuthSuccess(self, entity):
self.logger.info("Auth success: %s", self.user) self.logger.info("Auth success: %s", self.user)