From a21108db5c99a5673ab7057fca6ae31a81c9c3d0 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Thu, 13 Apr 2017 16:09:50 -0400 Subject: [PATCH 1/2] Log message type in prod // FREEBIE --- src/Messages/TSMessagesManager.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Messages/TSMessagesManager.m b/src/Messages/TSMessagesManager.m index 55418e1c4..4e302e7c2 100644 --- a/src/Messages/TSMessagesManager.m +++ b/src/Messages/TSMessagesManager.m @@ -404,21 +404,21 @@ NS_ASSUME_NONNULL_BEGIN }]; if (ignoreMessage) { // FIXME: https://github.com/WhisperSystems/Signal-iOS/issues/1340 - DDLogDebug(@"%@ Received message from group that I left or don't know about, ignoring", self.tag); + DDLogInfo(@"%@ Received message from group that I left or don't know about, ignoring", self.tag); return; } } if ((dataMessage.flags & OWSSignalServiceProtosDataMessageFlagsEndSession) != 0) { - DDLogVerbose(@"%@ Received end session message", self.tag); + DDLogInfo(@"%@ Received end session message", self.tag); [self handleEndSessionMessageWithEnvelope:incomingEnvelope dataMessage:dataMessage]; } else if ((dataMessage.flags & OWSSignalServiceProtosDataMessageFlagsExpirationTimerUpdate) != 0) { - DDLogVerbose(@"%@ Received expiration timer update message", self.tag); + DDLogInfo(@"%@ Received expiration timer update message", self.tag); [self handleExpirationTimerUpdateMessageWithEnvelope:incomingEnvelope dataMessage:dataMessage]; } else if (dataMessage.attachments.count > 0) { - DDLogVerbose(@"%@ Received media message attachment", self.tag); + DDLogInfo(@"%@ Received media message attachment", self.tag); [self handleReceivedMediaWithEnvelope:incomingEnvelope dataMessage:dataMessage]; } else { - DDLogVerbose(@"%@ Received data message.", self.tag); + DDLogInfo(@"%@ Received data message.", self.tag); [self handleReceivedTextMessageWithEnvelope:incomingEnvelope dataMessage:dataMessage]; if ([self isDataMessageGroupAvatarUpdate:dataMessage]) { DDLogVerbose(@"%@ Data message had group avatar attachment", self.tag); From e1055c26a3f558073d6b49d0fec81853e8640959 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 18 Apr 2017 10:35:34 -0400 Subject: [PATCH 2/2] Sync EndSession messages to linked devices Alternatively, I considered deleting *only* the session with the device which sent the message, but since other clients are deleting *all* sessions associated with the contact, it will be less disruptive to get in line with their behavior. Fixes the scenario wherein: * Alice.1 has a session with Bob.1 and Bob.2 * Bob.1 sends an EndSession to Alice * Thus Alice.1 deletes her sessions with Bob.1 and Bob.2 * Bob.2 sends Alice1 "hi" (with the existing session - as a regular WM, not a PKWM) * Alice has no session with Bob.2 so cannot decrypt the message. // FREEBIE --- src/Devices/OWSRecordTranscriptJob.m | 17 ++++++++++++++++- .../OWSIncomingSentMessageTranscript.h | 5 ++++- .../OWSIncomingSentMessageTranscript.m | 5 ++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Devices/OWSRecordTranscriptJob.m b/src/Devices/OWSRecordTranscriptJob.m index 2b7d2a8af..be351c83e 100644 --- a/src/Devices/OWSRecordTranscriptJob.m +++ b/src/Devices/OWSRecordTranscriptJob.m @@ -7,8 +7,9 @@ #import "OWSDisappearingMessagesJob.h" #import "OWSIncomingSentMessageTranscript.h" #import "OWSMessageSender.h" +#import "TSInfoMessage.h" #import "TSOutgoingMessage.h" -#import "TSStorageManager.h" +#import "TSStorageManager+SessionStore.h" NS_ASSUME_NONNULL_BEGIN @@ -17,6 +18,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) OWSIncomingSentMessageTranscript *incomingSentMessageTranscript; @property (nonatomic, readonly) OWSMessageSender *messageSender; @property (nonatomic, readonly) TSNetworkManager *networkManager; +@property (nonatomic, readonly) TSStorageManager *storageManager; @end @@ -34,6 +36,7 @@ NS_ASSUME_NONNULL_BEGIN _incomingSentMessageTranscript = incomingSentMessageTranscript; _messageSender = messageSender; _networkManager = networkManager; + _storageManager = [TSStorageManager sharedManager]; return self; } @@ -42,6 +45,18 @@ NS_ASSUME_NONNULL_BEGIN { OWSIncomingSentMessageTranscript *transcript = self.incomingSentMessageTranscript; DDLogDebug(@"%@ Recording transcript: %@", self.tag, transcript); + + if (transcript.isEndSessionMessage) { + DDLogInfo(@"%@ EndSession was sent to recipient: %@.", self.tag, transcript.recipientId); + [self.storageManager deleteAllSessionsForContact:transcript.recipientId]; + [[[TSInfoMessage alloc] initWithTimestamp:transcript.timestamp + inThread:transcript.thread + messageType:TSInfoMessageTypeSessionDidEnd] save]; + + // Don't continue processing lest we print a bubble for the session reset. + return; + } + TSThread *thread = transcript.thread; OWSAttachmentsProcessor *attachmentsProcessor = [[OWSAttachmentsProcessor alloc] initWithAttachmentProtos:transcript.attachmentPointerProtos diff --git a/src/Messages/DeviceSyncing/OWSIncomingSentMessageTranscript.h b/src/Messages/DeviceSyncing/OWSIncomingSentMessageTranscript.h index 9a86320fa..388a9d3da 100644 --- a/src/Messages/DeviceSyncing/OWSIncomingSentMessageTranscript.h +++ b/src/Messages/DeviceSyncing/OWSIncomingSentMessageTranscript.h @@ -1,4 +1,6 @@ -// Copyright © 2016 Open Whisper Systems. All rights reserved. +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// NS_ASSUME_NONNULL_BEGIN @@ -24,6 +26,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) TSThread *thread; @property (nonatomic, readonly) BOOL isGroupUpdate; @property (nonatomic, readonly) BOOL isExpirationTimerUpdate; +@property (nonatomic, readonly) BOOL isEndSessionMessage; @property (nullable, nonatomic, readonly) NSData *groupId; @property (nonatomic, readonly) NSString *body; @property (nonatomic, readonly) NSArray *attachmentPointerProtos; diff --git a/src/Messages/DeviceSyncing/OWSIncomingSentMessageTranscript.m b/src/Messages/DeviceSyncing/OWSIncomingSentMessageTranscript.m index 87821df9e..b88a07222 100644 --- a/src/Messages/DeviceSyncing/OWSIncomingSentMessageTranscript.m +++ b/src/Messages/DeviceSyncing/OWSIncomingSentMessageTranscript.m @@ -1,4 +1,6 @@ -// Copyright © 2016 Open Whisper Systems. All rights reserved. +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// #import "OWSIncomingSentMessageTranscript.h" #import "OWSAttachmentsProcessor.h" @@ -33,6 +35,7 @@ NS_ASSUME_NONNULL_BEGIN _groupId = _dataMessage.group.id; _isGroupUpdate = _dataMessage.hasGroup && (_dataMessage.group.type == OWSSignalServiceProtosGroupContextTypeUpdate); _isExpirationTimerUpdate = (_dataMessage.flags & OWSSignalServiceProtosDataMessageFlagsExpirationTimerUpdate) != 0; + _isEndSessionMessage = (_dataMessage.flags & OWSSignalServiceProtosDataMessageFlagsEndSession) != 0; return self; }