From 4191c2864d3ebd0437065d58732c335a63a740b3 Mon Sep 17 00:00:00 2001 From: DaZZZl Date: Fri, 19 Feb 2016 17:31:34 +0100 Subject: [PATCH 1/3] sending read receipts --- session.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/session.py b/session.py index f1f6c34..dcdeb6c 100644 --- a/session.py +++ b/session.py @@ -78,6 +78,7 @@ class Session(YowsupApp): self.msgIDs = { } self.groupOfflineQueue = { } self.loggedIn = False + self.recvMsgIDs = [] self.timer = None self.password = None @@ -209,6 +210,12 @@ class Session(YowsupApp): self.onPresenceAvailable(number) else: self.onPresenceUnavailable(number) + def sendReadReceipts(self, buddy): + for _id, _from, participant in self.recvMsgIDs: + if _from == (buddy + '@s.whatsapp.net'): + self.sendReceipt(_id, _from, 'read', participant) + self.recvMsgIDs.remove((_id, _from, participant)) + self.logger.debug("Send read receipt to %s (ID: %s)", _from, _id) # Called by superclass def onAuthSuccess(self, status, kind, creation, @@ -285,6 +292,7 @@ class Session(YowsupApp): buddy = _from.split('@')[0] messageContent = utils.softToUni(body) self.sendReceipt(_id, _from, None, participant) + self.recvMsgIDs.append((_id, _from, participant)) self.logger.info("Message received from %s to %s: %s (at ts=%s)", buddy, self.legacyName, messageContent, timestamp) if participant is not None: # Group message or broadcast @@ -320,6 +328,8 @@ class Session(YowsupApp): self.sendMessageToXMPP(buddy, image.url, image.timestamp) self.sendMessageToXMPP(buddy, image.caption, image.timestamp) self.sendReceipt(image._id, image._from, None, image.participant) + self.recvMsgIDs.append((image._id, image._from, image.participant)) + # Called by superclass def onAudio(self, audio): @@ -337,6 +347,8 @@ class Session(YowsupApp): else: self.sendMessageToXMPP(buddy, message, audio.timestamp) self.sendReceipt(audio._id, audio._from, None, audio.participant) + self.recvMsgIDs.append((audio._id, audio._from, audio.participant)) + # Called by superclass def onVideo(self, video): @@ -355,6 +367,8 @@ class Session(YowsupApp): else: self.sendMessageToXMPP(buddy, message, video.timestamp) self.sendReceipt(video._id, video._from, None, video.participant) + self.recvMsgIDs.append((video._id, video._from, video.participant)) + def onLocation(self, location): buddy = location._from.split('@')[0] @@ -384,6 +398,8 @@ class Session(YowsupApp): self.sendMessageToXMPP(buddy, url, location.timestamp) self.sendMessageToXMPP(buddy, latlong, location.timestamp) self.sendReceipt(location._id, location._from, None, location.participant) + self.recvMsgIDs.append((loaction._id, location._from, location.participant)) + # Called by superclass @@ -407,6 +423,8 @@ class Session(YowsupApp): # self.sendMessageToXMPP(buddy, card_data) #self.transferFile(buddy, str(name), card_data) self.sendReceipt(_id, _from, None, participant) + self.recvMsgIDs.append((_id, _from, participant)) + def transferFile(self, buddy, name, data): # Not working @@ -560,6 +578,7 @@ class Session(YowsupApp): if buddy != "bot": self.logger.info("Started typing: %s to %s", self.legacyName, buddy) self.sendTyping(buddy, True) + self.sendReadReceipts(buddy) # If he is typing he is present # I really don't know where else to put this. # Ideally, this should be sent if the user is looking at his client @@ -569,6 +588,7 @@ class Session(YowsupApp): if buddy != "bot": self.logger.info("Stopped typing: %s to %s", self.legacyName, buddy) self.sendTyping(buddy, False) + self.sendReadReceipts(buddy) def sendImage(self, message, ID, to): if (".jpg" in message.lower()): @@ -610,6 +630,7 @@ class Session(YowsupApp): self.legacyName, sender, message, xhtml) message = message.encode("utf-8") + self.sendReadReceipts(sender) if sender == "bot": self.bot.parse(message) From 2683b774f07be8cdbdd33bf00e5b0ac72e2ba7fc Mon Sep 17 00:00:00 2001 From: DaZZZl Date: Fri, 19 Feb 2016 18:12:47 +0100 Subject: [PATCH 2/3] read receipts: fix group receipts --- session.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/session.py b/session.py index dcdeb6c..32caedc 100644 --- a/session.py +++ b/session.py @@ -212,7 +212,7 @@ class Session(YowsupApp): self.onPresenceUnavailable(number) def sendReadReceipts(self, buddy): for _id, _from, participant in self.recvMsgIDs: - if _from == (buddy + '@s.whatsapp.net'): + if _from.split('@')[0] == buddy: self.sendReceipt(_id, _from, 'read', participant) self.recvMsgIDs.remove((_id, _from, participant)) self.logger.debug("Send read receipt to %s (ID: %s)", _from, _id) From e357cef04716859829e28d18b2edefcb3ae6a890 Mon Sep 17 00:00:00 2001 From: DaZZZl Date: Tue, 5 Apr 2016 20:32:29 +0200 Subject: [PATCH 3/3] fix group receipt acks --- yowsupwrapper.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yowsupwrapper.py b/yowsupwrapper.py index f5bece2..0ac9a38 100644 --- a/yowsupwrapper.py +++ b/yowsupwrapper.py @@ -742,9 +742,9 @@ class YowsupAppLayer(YowInterfaceLayer): def onReceipt(self, entity): """Sends ack automatically""" # entity is IncomingReceiptProtocolEntity - ack = OutgoingAckProtocolEntity(entity.getId(), - 'receipt', entity.getType(), entity.getFrom()) - self.toLower(ack) + #ack = OutgoingAckProtocolEntity(entity.getId(), + # 'receipt', entity.getType(), entity.getFrom()) + self.toLower(entity.ack()) _id = entity._id _from = entity._from timestamp = entity.timestamp