From e1055c26a3f558073d6b49d0fec81853e8640959 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 18 Apr 2017 10:35:34 -0400 Subject: [PATCH] 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; }