Remove legacy Error backdating - no changes in functionality

Historically we would backdate the SN change messages, but since adopting
non-blocking SN changes long ago, they're already sorted properly by creation
time, so backdating has been unnecessary for a while.

I also audited that all other error messages are saved directly after creation.

I applied deprecation attributes as appropriate as I audited.
This commit is contained in:
Michael Kirk 2018-09-20 13:29:59 -06:00
parent 550e7ba63b
commit 00d0d1e002
22 changed files with 74 additions and 77 deletions

View File

@ -1890,7 +1890,11 @@ typedef enum : NSUInteger {
// DEPRECATED: we're no longer creating these incoming SN error's per message,
// but there will be some legacy ones in the wild, behind which await
// as-of-yet-undecrypted messages
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
if ([errorMessage isKindOfClass:[TSInvalidIdentityKeyReceivingErrorMessage class]]) {
#pragma clang diagnostic pop
[errorMessage acceptNewIdentityKey];
}
}];

View File

@ -3598,11 +3598,14 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
withTransaction:transaction]];
[result addObject:[TSErrorMessage corruptedMessageWithEnvelope:[self createEnvelopeForThread:thread]
withTransaction:transaction]];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
TSInvalidIdentityKeyReceivingErrorMessage *_Nullable blockingSNChangeMessage =
[TSInvalidIdentityKeyReceivingErrorMessage untrustedKeyWithEnvelope:[self createEnvelopeForThread:thread]
withTransaction:transaction];
#pragma clang diagnostic pop
OWSAssertDebug(blockingSNChangeMessage);
[result addObject:blockingSNChangeMessage];
// MJK TODO - should be safe to remove this senderTimestamp

View File

@ -22,7 +22,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
// MJK TODO Remove this timestamp param?
// MJK TODO should be safe to remove this timestamp param
- (instancetype)initContactOffersWithSenderTimestamp:(uint64_t)timestamp
thread:(TSThread *)thread
hasBlockOffer:(BOOL)hasBlockOffer

View File

@ -7,6 +7,7 @@
NS_ASSUME_NONNULL_BEGIN
// This class is vestigial.
__attribute__((deprecated))
@interface TSUnreadIndicatorInteraction : TSInteraction
- (instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;

View File

@ -6,7 +6,10 @@
NS_ASSUME_NONNULL_BEGIN
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
@implementation TSUnreadIndicatorInteraction
#pragma clang diagnostic pop
- (instancetype)initWithCoder:(NSCoder *)coder
{

View File

@ -49,7 +49,6 @@ FOUNDATION_EXPORT const unsigned char SignalMessagingVersionString[];
#import <SignalMessaging/SelectRecipientViewController.h>
#import <SignalMessaging/SharingThreadPickerViewController.h>
#import <SignalMessaging/SignalKeyingStorage.h>
#import <SignalMessaging/TSUnreadIndicatorInteraction.h>
#import <SignalMessaging/Theme.h>
#import <SignalMessaging/ThreadUtil.h>
#import <SignalMessaging/ThreadViewHelper.h>

View File

@ -305,20 +305,31 @@ NS_ASSUME_NONNULL_BEGIN
enumerateRowsInGroup:thread.uniqueId
usingBlock:^(
NSString *collection, NSString *key, id object, id metadata, NSUInteger index, BOOL *stop) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
if ([object isKindOfClass:[OWSUnknownContactBlockOfferMessage class]]) {
#pragma clang diagnostic pop
// Delete this legacy interactions, which has been superseded by
// the OWSContactOffersInteraction.
[interactionsToDelete addObject:object];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
} else if ([object isKindOfClass:[OWSAddToContactsOfferMessage class]]) {
#pragma clang diagnostic pop
// Delete this legacy interactions, which has been superseded by
// the OWSContactOffersInteraction.
[interactionsToDelete addObject:object];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
} else if ([object isKindOfClass:[OWSAddToProfileWhitelistOfferMessage class]]) {
#pragma clang diagnostic pop
// Delete this legacy interactions, which has been superseded by
// the OWSContactOffersInteraction.
[interactionsToDelete addObject:object];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
} else if ([object isKindOfClass:[TSUnreadIndicatorInteraction class]]) {
#pragma clang diagnostic pop
// Remove obsolete unread indicator interactions;
[interactionsToDelete addObject:object];
} else if ([object isKindOfClass:[OWSContactOffersInteraction class]]) {
@ -465,7 +476,6 @@ NS_ASSUME_NONNULL_BEGIN
= (shouldHaveBlockOffer || shouldHaveAddToContactsOffer || shouldHaveAddToProfileWhitelistOffer);
if (isContactThread) {
TSContactThread *contactThread = (TSContactThread *)thread;
// MJK only place where `hasDismissedOffers` is read
if (contactThread.hasDismissedOffers) {
shouldHaveContactOffers = NO;
}

View File

@ -58,7 +58,10 @@ NS_ASSUME_NONNULL_BEGIN
/**
* Get all messages in the thread we weren't able to decrypt
*/
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (NSArray<TSInvalidIdentityKeyReceivingErrorMessage *> *)receivedMessagesForInvalidKey:(NSData *)key;
#pragma clang diagnostic pop
- (NSUInteger)unreadMessageCountWithTransaction:(YapDatabaseReadTransaction *)transaction
NS_SWIFT_NAME(unreadMessageCount(transaction:));

View File

@ -206,6 +206,8 @@ NS_ASSUME_NONNULL_BEGIN
return [interactions copy];
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (NSArray<TSInvalidIdentityKeyReceivingErrorMessage *> *)receivedMessagesForInvalidKey:(NSData *)key
{
NSMutableArray *errorMessages = [NSMutableArray new];
@ -220,6 +222,7 @@ NS_ASSUME_NONNULL_BEGIN
return [errorMessages copy];
}
#pragma clang diagnostic pop
- (NSUInteger)numberOfInteractions
{

View File

@ -70,7 +70,7 @@ NS_ASSUME_NONNULL_BEGIN
if (transcript.isEndSessionMessage) {
OWSLogInfo(@"EndSession was sent to recipient: %@.", transcript.recipientId);
[self.primaryStorage deleteAllSessionsForContact:transcript.recipientId protocolContext:transaction];
// MJK TODO - verify we can delete this senderTimestamp
// MJK TODO - we don't use this timestamp, safe to remove
[[[TSInfoMessage alloc] initWithSenderTimestamp:transcript.timestamp
inThread:transcript.thread
messageType:TSInfoMessageTypeSessionDidEnd]

View File

@ -51,10 +51,6 @@ typedef NS_ENUM(int32_t, TSErrorMessageType) {
failedMessageType:(TSErrorMessageType)errorMessageType
recipientId:(nullable NSString *)recipientId NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithSenderTimestamp:(uint64_t)timestamp
inThread:(nullable TSThread *)thread
failedMessageType:(TSErrorMessageType)errorMessageType;
+ (instancetype)corruptedMessageWithEnvelope:(SSKProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction;

View File

@ -91,18 +91,11 @@ NSUInteger TSErrorMessageSchemaVersion = 1;
TSContactThread *contactThread =
[TSContactThread getOrCreateThreadWithContactId:envelope.source transaction:transaction];
// MJK FIXME - cannot rely on envelope timestamp for sorting, ensure this is saved immediately.
// Legit usage of senderTimestamp. We don't actually currently surface it in the UI, but it serves as
// a reference to the envelope which we failed to process.
return [self initWithSenderTimestamp:envelope.timestamp inThread:contactThread failedMessageType:errorMessageType];
}
- (instancetype)initWithFailedMessageType:(TSErrorMessageType)errorMessageType
{
// MJK FIXME - cannot rely on envelope timestamp for sorting, ensure this is saved immediately.
return [self initWithSenderTimestamp:[NSDate ows_millisecondTimeStamp]
inThread:nil
failedMessageType:errorMessageType];
}
- (OWSInteractionType)interactionType
{
return OWSInteractionType_Error;
@ -160,7 +153,10 @@ NSUInteger TSErrorMessageSchemaVersion = 1;
+ (instancetype)corruptedMessageInUnknownThread
{
return [[self alloc] initWithFailedMessageType:TSErrorMessageInvalidMessage];
// MJK TODO - Seems like we could safely remove this timestamp
return [[self alloc] initWithSenderTimestamp:[NSDate ows_millisecondTimeStamp]
inThread:nil
failedMessageType:TSErrorMessageInvalidMessage];
}
+ (instancetype)invalidVersionWithEnvelope:(SSKProtoEnvelope *)envelope

View File

@ -4,17 +4,16 @@
#import "TSErrorMessage.h"
NS_ASSUME_NONNULL_BEGIN
@interface TSErrorMessage ()
- (instancetype)initWithSenderTimestamp:(uint64_t)timestamp
inThread:(TSThread *)thread
inThread:(nullable TSThread *)thread
failedMessageType:(TSErrorMessageType)errorMessageType NS_DESIGNATED_INITIALIZER;
@property (atomic, nullable) NSData *envelopeData;
@property NSDictionary *pendingOutgoingMessage;
#define TSPendingOutgoingMessageKey @"TSPendingOutgoingMessageKey"
#define TSPendingOutgoingMessageRecipientKey @"TSPendingOutgoingMessageRecipientKey"
@end
NS_ASSUME_NONNULL_END

View File

@ -10,10 +10,13 @@ NS_ASSUME_NONNULL_BEGIN
// DEPRECATED - we no longer create new instances of this class (as of mid-2017); However, existing instances may
// exist, so we should keep this class around to honor their old behavior.
__attribute__((deprecated))
@interface TSInvalidIdentityKeyReceivingErrorMessage : TSInvalidIdentityKeyErrorMessage
#ifdef DEBUG
+ (nullable instancetype)untrustedKeyWithEnvelope:(SSKProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction;
#endif
@end

View File

@ -19,7 +19,7 @@
NS_ASSUME_NONNULL_BEGIN
/// TODO we can eventually deprecate this, since incoming messages are now always decrypted.
__attribute__((deprecated))
@interface TSInvalidIdentityKeyReceivingErrorMessage ()
@property (nonatomic, readonly, copy) NSString *authorId;
@ -33,13 +33,16 @@ NS_ASSUME_NONNULL_BEGIN
@synthesize envelopeData = _envelopeData;
#ifdef DEBUG
// We no longer create these messages, but they might exist on legacy clients so it's useful to be able to
// create them with the debug UI
+ (nullable instancetype)untrustedKeyWithEnvelope:(SSKProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction
{
TSContactThread *contactThread =
[TSContactThread getOrCreateThreadWithContactId:envelope.source transaction:transaction];
// MJK - FIXME, can't rely on envelope.timestamp for sorting, ensure this is saved immediately.
// Legit usage of senderTimestamp, references message which failed to decrypt
TSInvalidIdentityKeyReceivingErrorMessage *errorMessage =
[[self alloc] initForUnknownIdentityKeyWithSenderTimestamp:envelope.timestamp
inThread:contactThread
@ -69,6 +72,7 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
#endif
- (nullable SSKProtoEnvelope *)envelope
{

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSInvalidIdentityKeyErrorMessage.h"
@ -13,6 +13,9 @@ NS_ASSUME_NONNULL_BEGIN
extern NSString *TSInvalidPreKeyBundleKey;
extern NSString *TSInvalidRecipientKey;
// DEPRECATED - we no longer create new instances of this class (as of mid-2017); However, existing instances may
// exist, so we should keep this class around to honor their old behavior.
__attribute__((deprecated))
@interface TSInvalidIdentityKeySendingErrorMessage : TSInvalidIdentityKeyErrorMessage
@property (nonatomic, readonly) NSString *messageId;

View File

@ -24,27 +24,12 @@ NSString *TSInvalidRecipientKey = @"TSInvalidRecipientKey";
@end
// DEPRECATED - we no longer create new instances of this class (as of mid-2017); However, existing instances may
// exist, so we should keep this class around to honor their old behavior.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
@implementation TSInvalidIdentityKeySendingErrorMessage
- (instancetype)initWithOutgoingMessage:(TSOutgoingMessage *)message
inThread:(TSThread *)thread
forRecipient:(NSString *)recipientId
preKeyBundle:(PreKeyBundle *)preKeyBundle
{
// We want the error message to appear after the message.
// MJK FIXME - we can't rely on sort order like this.
self = [super initWithSenderTimestamp:message.timestamp + 1
inThread:thread
failedMessageType:TSErrorMessageWrongTrustedIdentityKey
recipientId:recipientId];
if (self) {
_messageId = message.uniqueId;
_preKeyBundle = preKeyBundle;
}
return self;
}
#pragma clang diagnostic pop
- (void)acceptNewIdentityKey
{

View File

@ -16,7 +16,10 @@ NS_ASSUME_NONNULL_BEGIN
// This is a deprecated class, we're keeping it around to avoid YapDB serialization errors
// TODO - remove this class, clean up existing instances, ensure any missed ones don't explode (UnknownDBObject)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
@implementation OWSAddToContactsOfferMessage
#pragma clang diagnostic pop
+ (instancetype)addToContactsOfferMessageWithSenderTimestamp:(uint64_t)timestamp
thread:(TSThread *)thread

View File

@ -9,7 +9,10 @@ NS_ASSUME_NONNULL_BEGIN
// This is a deprecated class, we're keeping it around to avoid YapDB serialization errors
// TODO - remove this class, clean up existing instances, ensure any missed ones don't explode (UnknownDBObject)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
@implementation OWSAddToProfileWhitelistOfferMessage
#pragma clang diagnostic pop
+ (instancetype)addToProfileWhitelistOfferMessageWithSenderTimestamp:(uint64_t)timestamp thread:(TSThread *)thread
{

View File

@ -528,6 +528,7 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
[messages addObject:[TSErrorMessage nonblockingIdentityChangeInThread:groupThread recipientId:recipientId]];
}
// MJK TODO - why not save immediately, why build up this array?
for (TSMessage *message in messages) {
[message saveWithTransaction:transaction];
}

View File

@ -8,11 +8,8 @@ NS_ASSUME_NONNULL_BEGIN
// This is a deprecated class, we're keeping it around to avoid YapDB serialization errors
// TODO - remove this class, clean up existing instances, ensure any missed ones don't explode (UnknownDBObject)
__attribute__((deprecated)) @interface OWSUnknownContactBlockOfferMessage : TSErrorMessage
+ (instancetype)unknownContactBlockOfferMessageWithSenderTimestamp:(uint64_t)timestamp
thread:(TSThread *)thread
contactId:(NSString *)contactId;
__attribute__((deprecated))
@interface OWSUnknownContactBlockOfferMessage : TSErrorMessage
@property (nonatomic, readonly) NSString *contactId;

View File

@ -16,29 +16,10 @@ NS_ASSUME_NONNULL_BEGIN
// This is a deprecated class, we're keeping it around to avoid YapDB serialization errors
// TODO - remove this class, clean up existing instances, ensure any missed ones don't explode (UnknownDBObject)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
@implementation OWSUnknownContactBlockOfferMessage
+ (instancetype)unknownContactBlockOfferMessageWithSenderTimestamp:(uint64_t)timestamp
thread:(TSThread *)thread
contactId:(NSString *)contactId
{
return [[OWSUnknownContactBlockOfferMessage alloc] initWithSenderTimestamp:timestamp
thread:thread
contactId:contactId];
}
- (instancetype)initWithSenderTimestamp:(uint64_t)timestamp thread:(TSThread *)thread contactId:(NSString *)contactId
{
self = [super initWithSenderTimestamp:timestamp
inThread:thread
failedMessageType:TSErrorMessageUnknownContactBlockOffer];
if (self) {
_contactId = contactId;
}
return self;
}
#pragma clang diagnostic pop
- (BOOL)shouldUseReceiptDateForSorting
{