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
pull/1/head
Michael Kirk 8 years ago
parent a21108db5c
commit e1055c26a3

@ -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

@ -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<OWSSignalServiceProtosAttachmentPointer *> *attachmentPointerProtos;

@ -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;
}

Loading…
Cancel
Save