From 1037ce51139b4408606c9c7a27ccc00a39756965 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Wed, 25 Nov 2020 16:21:04 +1100 Subject: [PATCH] WIP --- .../ConversationView/ConversationViewItem.h | 1 - SessionMessagingKit/Database/TSDatabaseView.m | 1 - ...SInvalidIdentityKeyReceivingErrorMessage.m | 1 - .../Messages/Signal/TSMessage.m | 416 ++++++++++++++++++ .../Meta/SessionMessagingKit.h | 1 + ...sappearingConfigurationUpdateInfoMessage.m | 1 - .../OWSDisappearingMessagesConfiguration.m | 1 - SessionMessagingKit/To Do/TSAccountManager.m | 4 - .../Utilities}/SignalRecipient.h | 0 .../Utilities}/SignalRecipient.m | 46 +- SessionUtilitiesKit/NSUserDefaults+OWS.m | 1 - Signal.xcodeproj/project.pbxproj | 12 +- SignalUtilitiesKit/Meta/SignalUtilitiesKit.h | 1 - 13 files changed, 425 insertions(+), 61 deletions(-) create mode 100644 SessionMessagingKit/Messages/Signal/TSMessage.m rename {SignalUtilitiesKit => SessionMessagingKit/Utilities}/SignalRecipient.h (100%) rename {SignalUtilitiesKit => SessionMessagingKit/Utilities}/SignalRecipient.m (83%) diff --git a/Session/Signal/ConversationView/ConversationViewItem.h b/Session/Signal/ConversationView/ConversationViewItem.h index 3464d077d..e26701080 100644 --- a/Session/Signal/ConversationView/ConversationViewItem.h +++ b/Session/Signal/ConversationView/ConversationViewItem.h @@ -3,7 +3,6 @@ // #import "ConversationViewLayout.h" -#import "OWSAudioPlayer.h" NS_ASSUME_NONNULL_BEGIN diff --git a/SessionMessagingKit/Database/TSDatabaseView.m b/SessionMessagingKit/Database/TSDatabaseView.m index 876063959..b59d16054 100644 --- a/SessionMessagingKit/Database/TSDatabaseView.m +++ b/SessionMessagingKit/Database/TSDatabaseView.m @@ -3,7 +3,6 @@ // #import "TSDatabaseView.h" -#import "TSAttachmentPointer+Backups.h" #import "OWSReadTracking.h" #import "TSAttachment.h" #import "TSAttachmentPointer.h" diff --git a/SessionMessagingKit/Messages/Signal/TSInvalidIdentityKeyReceivingErrorMessage.m b/SessionMessagingKit/Messages/Signal/TSInvalidIdentityKeyReceivingErrorMessage.m index c85c57276..1f2a562c1 100644 --- a/SessionMessagingKit/Messages/Signal/TSInvalidIdentityKeyReceivingErrorMessage.m +++ b/SessionMessagingKit/Messages/Signal/TSInvalidIdentityKeyReceivingErrorMessage.m @@ -4,7 +4,6 @@ #import "TSInvalidIdentityKeyReceivingErrorMessage.h" #import "OWSIdentityManager.h" -#import "OWSPrimaryStorage+SessionStore.h" #import "OWSPrimaryStorage.h" #import "SSKEnvironment.h" #import "TSContactThread.h" diff --git a/SessionMessagingKit/Messages/Signal/TSMessage.m b/SessionMessagingKit/Messages/Signal/TSMessage.m new file mode 100644 index 000000000..2fac7a6e6 --- /dev/null +++ b/SessionMessagingKit/Messages/Signal/TSMessage.m @@ -0,0 +1,416 @@ +// +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. +// + +#import "TSMessage.h" +#import "AppContext.h" +#import "MIMETypeUtil.h" +#import "OWSDisappearingMessagesConfiguration.h" +#import "TSAttachment.h" +#import "TSAttachmentStream.h" +#import "TSQuotedMessage.h" +#import "TSThread.h" +#import +#import +#import +#import +#import "OWSPrimaryStorage+Loki.h" +#import "TSContactThread.h" +#import + +NS_ASSUME_NONNULL_BEGIN + +static const NSUInteger OWSMessageSchemaVersion = 4; +const NSUInteger kOversizeTextMessageSizeThreshold = 2 * 1024; + +#pragma mark - + +@interface TSMessage () + +@property (nonatomic, nullable) NSString *body; +@property (nonatomic) uint32_t expiresInSeconds; +@property (nonatomic) uint64_t expireStartedAt; + +/** + * The version of the model class's schema last used to serialize this model. Use this to manage data migrations during + * object de/serialization. + * + * e.g. + * + * - (id)initWithCoder:(NSCoder *)coder + * { + * self = [super initWithCoder:coder]; + * if (!self) { return self; } + * if (_schemaVersion < 2) { + * _newName = [coder decodeObjectForKey:@"oldName"] + * } + * ... + * _schemaVersion = 2; + * } + */ +@property (nonatomic, readonly) NSUInteger schemaVersion; + +@end + +#pragma mark - + +@implementation TSMessage + +- (instancetype)initMessageWithTimestamp:(uint64_t)timestamp + inThread:(nullable TSThread *)thread + messageBody:(nullable NSString *)body + attachmentIds:(NSArray *)attachmentIds + expiresInSeconds:(uint32_t)expiresInSeconds + expireStartedAt:(uint64_t)expireStartedAt + quotedMessage:(nullable TSQuotedMessage *)quotedMessage + linkPreview:(nullable OWSLinkPreview *)linkPreview +{ + self = [super initInteractionWithTimestamp:timestamp inThread:thread]; + + if (!self) { + return self; + } + + _schemaVersion = OWSMessageSchemaVersion; + + _body = body; + _attachmentIds = attachmentIds ? [attachmentIds mutableCopy] : [NSMutableArray new]; + _expiresInSeconds = expiresInSeconds; + _expireStartedAt = expireStartedAt; + [self updateExpiresAt]; + _quotedMessage = quotedMessage; + _linkPreview = linkPreview; + _openGroupServerMessageID = -1; + + return self; +} + +- (nullable instancetype)initWithCoder:(NSCoder *)coder +{ + self = [super initWithCoder:coder]; + if (!self) { + return self; + } + + if (_schemaVersion < 2) { + // renamed _attachments to _attachmentIds + if (!_attachmentIds) { + _attachmentIds = [coder decodeObjectForKey:@"attachments"]; + } + } + + if (_schemaVersion < 3) { + _expiresInSeconds = 0; + _expireStartedAt = 0; + _expiresAt = 0; + } + + if (_schemaVersion < 4) { + // Wipe out the body field on these legacy attachment messages. + // + // Explantion: Historically, a message sent from iOS could be an attachment XOR a text message, + // but now we support sending an attachment+caption as a single message. + // + // Other clients have supported sending attachment+caption in a single message for a long time. + // So the way we used to handle receiving them was to make it look like they'd sent two messages: + // first the attachment+caption (we'd ignore this caption when rendering), followed by a separate + // message with just the caption (which we'd render as a simple independent text message), for + // which we'd offset the timestamp by a little bit to get the desired ordering. + // + // Now that we can properly render an attachment+caption message together, these legacy "dummy" text + // messages are not only unnecessary, but worse, would be rendered redundantly. For safety, rather + // than building the logic to try to find and delete the redundant "dummy" text messages which users + // have been seeing and interacting with, we delete the body field from the attachment message, + // which iOS users have never seen directly. + if (_attachmentIds.count > 0) { + _body = nil; + } + } + + if (!_attachmentIds) { + _attachmentIds = [NSMutableArray new]; + } + + _schemaVersion = OWSMessageSchemaVersion; + + return self; +} + +- (void)setExpiresInSeconds:(uint32_t)expiresInSeconds +{ + uint32_t maxExpirationDuration = [OWSDisappearingMessagesConfiguration maxDurationSeconds]; + + _expiresInSeconds = MIN(expiresInSeconds, maxExpirationDuration); + [self updateExpiresAt]; +} + +- (void)setExpireStartedAt:(uint64_t)expireStartedAt +{ + if (_expireStartedAt != 0 && _expireStartedAt < expireStartedAt) { + return; + } + + uint64_t now = [NSDate ows_millisecondTimeStamp]; + + _expireStartedAt = MIN(now, expireStartedAt); + [self updateExpiresAt]; +} + +- (BOOL)shouldStartExpireTimerWithTransaction:(YapDatabaseReadTransaction *)transaction +{ + return self.isExpiringMessage; +} + +// TODO a downloaded media doesn't start counting until download is complete. +- (void)updateExpiresAt +{ + if (_expiresInSeconds > 0 && _expireStartedAt > 0) { + _expiresAt = _expireStartedAt + _expiresInSeconds * 1000; + } else { + _expiresAt = 0; + } +} + +- (BOOL)hasAttachments +{ + return self.attachmentIds ? (self.attachmentIds.count > 0) : NO; +} + +- (NSArray *)allAttachmentIds +{ + NSMutableArray *result = [NSMutableArray new]; + if (self.attachmentIds.count > 0) { + [result addObjectsFromArray:self.attachmentIds]; + } + + if (self.quotedMessage) { + [result addObjectsFromArray:self.quotedMessage.thumbnailAttachmentStreamIds]; + } + + if (self.linkPreview.imageAttachmentId) { + [result addObject:self.linkPreview.imageAttachmentId]; + } + + return [result copy]; +} + +- (NSArray *)attachmentsWithTransaction:(YapDatabaseReadTransaction *)transaction +{ + NSMutableArray *attachments = [NSMutableArray new]; + for (NSString *attachmentId in self.attachmentIds) { + TSAttachment *_Nullable attachment = + [TSAttachment fetchObjectWithUniqueID:attachmentId transaction:transaction]; + if (attachment) { + [attachments addObject:attachment]; + } + } + return [attachments copy]; +} + +- (NSArray *)attachmentsWithTransaction:(YapDatabaseReadTransaction *)transaction + contentType:(NSString *)contentType +{ + NSArray *attachments = [self attachmentsWithTransaction:transaction]; + return [attachments filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(TSAttachment *evaluatedObject, + NSDictionary *_Nullable bindings) { + return [evaluatedObject.contentType isEqualToString:contentType]; + }]]; +} + +- (NSArray *)attachmentsWithTransaction:(YapDatabaseReadTransaction *)transaction + exceptContentType:(NSString *)contentType +{ + NSArray *attachments = [self attachmentsWithTransaction:transaction]; + return [attachments filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(TSAttachment *evaluatedObject, + NSDictionary *_Nullable bindings) { + return ![evaluatedObject.contentType isEqualToString:contentType]; + }]]; +} + +- (void)removeAttachment:(TSAttachment *)attachment transaction:(YapDatabaseReadWriteTransaction *)transaction; +{ + [attachment removeWithTransaction:transaction]; + + [self.attachmentIds removeObject:attachment.uniqueId]; + + [self saveWithTransaction:transaction]; +} + +- (void)addAttachmentWithID:(NSString *)attachmentID in:(YapDatabaseReadWriteTransaction *)transaction { + if (!self.attachmentIds) { return; } + [self.attachmentIds addObject:attachmentID]; + [self saveWithTransaction:transaction]; +} + +- (NSString *)debugDescription +{ + if ([self hasAttachments] && self.body.length > 0) { + NSString *attachmentId = self.attachmentIds[0]; + return [NSString + stringWithFormat:@"Media Message with attachmentId: %@ and caption: '%@'", attachmentId, self.body]; + } else if ([self hasAttachments]) { + NSString *attachmentId = self.attachmentIds[0]; + return [NSString stringWithFormat:@"Media Message with attachmentId: %@", attachmentId]; + } else { + return [NSString stringWithFormat:@"%@ with body: %@", [self class], self.body]; + } +} + +- (nullable TSAttachment *)oversizeTextAttachmentWithTransaction:(YapDatabaseReadTransaction *)transaction +{ + return [self attachmentsWithTransaction:transaction contentType:OWSMimeTypeOversizeTextMessage].firstObject; +} + +- (NSArray *)mediaAttachmentsWithTransaction:(YapDatabaseReadTransaction *)transaction +{ + return [self attachmentsWithTransaction:transaction exceptContentType:OWSMimeTypeOversizeTextMessage]; +} + +- (nullable NSString *)oversizeTextWithTransaction:(YapDatabaseReadTransaction *)transaction +{ + TSAttachment *_Nullable attachment = [self oversizeTextAttachmentWithTransaction:transaction]; + if (!attachment) { + return nil; + } + + if (![attachment isKindOfClass:TSAttachmentStream.class]) { + return nil; + } + + TSAttachmentStream *attachmentStream = (TSAttachmentStream *)attachment; + + NSData *_Nullable data = [NSData dataWithContentsOfFile:attachmentStream.originalFilePath]; + if (!data) { + return nil; + } + NSString *_Nullable text = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + if (!text) { + return nil; + } + return text.filterStringForDisplay; +} + +- (nullable NSString *)bodyTextWithTransaction:(YapDatabaseReadTransaction *)transaction +{ + NSString *_Nullable oversizeText = [self oversizeTextWithTransaction:transaction]; + if (oversizeText) { + return oversizeText; + } + + if (self.body.length > 0) { + return self.body.filterStringForDisplay; + } + + return nil; +} + +// TODO: This method contains view-specific logic and probably belongs in NotificationsManager, not in SSK. +- (NSString *)previewTextWithTransaction:(YapDatabaseReadTransaction *)transaction +{ + NSString *_Nullable bodyDescription = nil; + if (self.body.length > 0) { + bodyDescription = self.body; + } + + if (bodyDescription == nil) { + TSAttachment *_Nullable oversizeTextAttachment = [self oversizeTextAttachmentWithTransaction:transaction]; + if ([oversizeTextAttachment isKindOfClass:[TSAttachmentStream class]]) { + TSAttachmentStream *oversizeTextAttachmentStream = (TSAttachmentStream *)oversizeTextAttachment; + NSData *_Nullable data = [NSData dataWithContentsOfFile:oversizeTextAttachmentStream.originalFilePath]; + if (data) { + NSString *_Nullable text = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + if (text) { + bodyDescription = text.filterStringForDisplay; + } + } + } + } + + NSString *_Nullable attachmentDescription = nil; + TSAttachment *_Nullable mediaAttachment = [self mediaAttachmentsWithTransaction:transaction].firstObject; + if (mediaAttachment != nil) { + attachmentDescription = mediaAttachment.description; + } + + if (attachmentDescription.length > 0 && bodyDescription.length > 0) { + // Attachment with caption. + if ([CurrentAppContext() isRTL]) { + return [[bodyDescription stringByAppendingString:@": "] stringByAppendingString:attachmentDescription]; + } else { + return [[attachmentDescription stringByAppendingString:@": "] stringByAppendingString:bodyDescription]; + } + } else if (bodyDescription.length > 0) { + return bodyDescription; + } else if (attachmentDescription.length > 0) { + return attachmentDescription; + } else { + // TODO: We should do better here. + return @""; + } +} + +- (void)removeWithTransaction:(YapDatabaseReadWriteTransaction *)transaction +{ + [super removeWithTransaction:transaction]; + + for (NSString *attachmentId in self.allAttachmentIds) { + // We need to fetch each attachment, since [TSAttachment removeWithTransaction:] does important work. + TSAttachment *_Nullable attachment = + [TSAttachment fetchObjectWithUniqueID:attachmentId transaction:transaction]; + if (!attachment) { + continue; + } + [attachment removeWithTransaction:transaction]; + }; +} + +- (BOOL)isExpiringMessage +{ + return self.expiresInSeconds > 0; +} + +- (uint64_t)timestampForLegacySorting +{ + if ([self shouldUseReceiptDateForSorting] && self.receivedAtTimestamp > 0) { + return self.receivedAtTimestamp; + } else { + return self.timestamp; + } +} + +- (BOOL)shouldUseReceiptDateForSorting +{ + return YES; +} + +- (nullable NSString *)body +{ + return _body.filterStringForDisplay; +} + +- (void)setQuotedMessageThumbnailAttachmentStream:(TSAttachmentStream *)attachmentStream +{ + [self.quotedMessage setThumbnailAttachmentStream:attachmentStream]; +} + +#pragma mark - Update With... Methods + +- (void)updateWithExpireStartedAt:(uint64_t)expireStartedAt transaction:(YapDatabaseReadWriteTransaction *)transaction +{ + [self applyChangeToSelfAndLatestCopy:transaction + changeBlock:^(TSMessage *message) { + [message setExpireStartedAt:expireStartedAt]; + }]; +} + +- (void)updateWithLinkPreview:(OWSLinkPreview *)linkPreview transaction:(YapDatabaseReadWriteTransaction *)transaction +{ + [self applyChangeToSelfAndLatestCopy:transaction + changeBlock:^(TSMessage *message) { + [message setLinkPreview:linkPreview]; + }]; +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/SessionMessagingKit/Meta/SessionMessagingKit.h b/SessionMessagingKit/Meta/SessionMessagingKit.h index 07bef159a..b02e7609e 100644 --- a/SessionMessagingKit/Meta/SessionMessagingKit.h +++ b/SessionMessagingKit/Meta/SessionMessagingKit.h @@ -23,6 +23,7 @@ FOUNDATION_EXPORT const unsigned char SessionMessagingKitVersionString[]; #import #import #import +#import #import #import #import diff --git a/SessionMessagingKit/Sending & Receiving/Expiration/OWSDisappearingConfigurationUpdateInfoMessage.m b/SessionMessagingKit/Sending & Receiving/Expiration/OWSDisappearingConfigurationUpdateInfoMessage.m index 3b1c7250b..82c3071ae 100644 --- a/SessionMessagingKit/Sending & Receiving/Expiration/OWSDisappearingConfigurationUpdateInfoMessage.m +++ b/SessionMessagingKit/Sending & Receiving/Expiration/OWSDisappearingConfigurationUpdateInfoMessage.m @@ -3,7 +3,6 @@ // #import "OWSDisappearingConfigurationUpdateInfoMessage.h" -#import "NSString+SSK.h" #import "OWSDisappearingMessagesConfiguration.h" #import diff --git a/SessionMessagingKit/Sending & Receiving/Expiration/OWSDisappearingMessagesConfiguration.m b/SessionMessagingKit/Sending & Receiving/Expiration/OWSDisappearingMessagesConfiguration.m index 88e0ee576..9e93fbbff 100644 --- a/SessionMessagingKit/Sending & Receiving/Expiration/OWSDisappearingMessagesConfiguration.m +++ b/SessionMessagingKit/Sending & Receiving/Expiration/OWSDisappearingMessagesConfiguration.m @@ -3,7 +3,6 @@ // #import "OWSDisappearingMessagesConfiguration.h" -#import "NSString+SSK.h" #import #import diff --git a/SessionMessagingKit/To Do/TSAccountManager.m b/SessionMessagingKit/To Do/TSAccountManager.m index e30b00917..dc41c5c48 100644 --- a/SessionMessagingKit/To Do/TSAccountManager.m +++ b/SessionMessagingKit/To Do/TSAccountManager.m @@ -6,12 +6,8 @@ #import "AppContext.h" #import "AppReadiness.h" #import "NSNotificationCenter+OWS.h" -#import "NSURLSessionDataTask+StatusCode.h" -#import "OWSError.h" -#import "OWSPrimaryStorage+SessionStore.h" #import "ProfileManagerProtocol.h" #import "SSKEnvironment.h" -#import "TSPreKeyManager.h" #import "YapDatabaseConnection+OWS.h" #import "YapDatabaseTransaction+OWS.h" #import diff --git a/SignalUtilitiesKit/SignalRecipient.h b/SessionMessagingKit/Utilities/SignalRecipient.h similarity index 100% rename from SignalUtilitiesKit/SignalRecipient.h rename to SessionMessagingKit/Utilities/SignalRecipient.h diff --git a/SignalUtilitiesKit/SignalRecipient.m b/SessionMessagingKit/Utilities/SignalRecipient.m similarity index 83% rename from SignalUtilitiesKit/SignalRecipient.m rename to SessionMessagingKit/Utilities/SignalRecipient.m index 60932e04b..796105514 100644 --- a/SignalUtilitiesKit/SignalRecipient.m +++ b/SessionMessagingKit/Utilities/SignalRecipient.m @@ -3,11 +3,9 @@ // #import "SignalRecipient.h" - #import "ProfileManagerProtocol.h" #import "SSKEnvironment.h" #import "TSAccountManager.h" - #import NS_ASSUME_NONNULL_BEGIN @@ -36,8 +34,6 @@ NS_ASSUME_NONNULL_BEGIN - (TSAccountManager *)tsAccountManager { - OWSAssertDebug(SSKEnvironment.shared.tsAccountManager); - return SSKEnvironment.shared.tsAccountManager; } @@ -46,9 +42,6 @@ NS_ASSUME_NONNULL_BEGIN + (instancetype)getOrBuildUnsavedRecipientForRecipientId:(NSString *)recipientId transaction:(YapDatabaseReadTransaction *)transaction { - OWSAssertDebug(transaction); - OWSAssertDebug(recipientId.length > 0); - SignalRecipient *_Nullable recipient = [self registeredRecipientForRecipientId:recipientId mustHaveDevices:NO transaction:transaction]; if (!recipient) { @@ -84,7 +77,6 @@ NS_ASSUME_NONNULL_BEGIN // ensure the local user always has at least *this* device. if (![_devices containsObject:@(1)]) { if ([self.uniqueId isEqualToString:self.tsAccountManager.localNumber]) { - DDLogInfo(@"Adding primary device to self recipient."); [self addDevices:[NSSet setWithObject:@(1)]]; } } @@ -96,9 +88,6 @@ NS_ASSUME_NONNULL_BEGIN mustHaveDevices:(BOOL)mustHaveDevices transaction:(YapDatabaseReadTransaction *)transaction { - OWSAssertDebug(transaction); - OWSAssertDebug(recipientId.length > 0); - SignalRecipient *_Nullable signalRecipient = [self fetchObjectWithUniqueID:recipientId transaction:transaction]; if (mustHaveDevices && signalRecipient.devices.count < 1) { return nil; @@ -108,8 +97,6 @@ NS_ASSUME_NONNULL_BEGIN - (void)addDevices:(NSSet *)devices { - OWSAssertDebug(devices.count > 0); - NSMutableOrderedSet *updatedDevices = [self.devices mutableCopy]; [updatedDevices unionSet:devices]; self.devices = [updatedDevices copy]; @@ -117,8 +104,6 @@ NS_ASSUME_NONNULL_BEGIN - (void)removeDevices:(NSSet *)devices { - OWSAssertDebug(devices.count > 0); - NSMutableOrderedSet *updatedDevices = [self.devices mutableCopy]; [updatedDevices minusSet:devices]; self.devices = [updatedDevices copy]; @@ -127,9 +112,6 @@ NS_ASSUME_NONNULL_BEGIN - (void)updateRegisteredRecipientWithDevicesToAdd:(nullable NSArray *)devicesToAdd devicesToRemove:(nullable NSArray *)devicesToRemove transaction:(YapDatabaseReadWriteTransaction *)transaction { - OWSAssertDebug(transaction); - OWSAssertDebug(devicesToAdd.count > 0 || devicesToRemove.count > 0); - // Add before we remove, since removeDevicesFromRecipient:... // can markRecipientAsUnregistered:... if the recipient has // no devices left. @@ -143,10 +125,6 @@ NS_ASSUME_NONNULL_BEGIN - (void)addDevicesToRegisteredRecipient:(NSSet *)devices transaction:(YapDatabaseReadWriteTransaction *)transaction { - OWSAssertDebug(transaction); - OWSAssertDebug(devices.count > 0); - OWSLogDebug(@"adding devices: %@, to recipient: %@", devices, self); - [self reloadWithTransaction:transaction]; [self addDevices:devices]; [self saveWithTransaction_internal:transaction]; @@ -154,10 +132,6 @@ NS_ASSUME_NONNULL_BEGIN - (void)removeDevicesFromRecipient:(NSSet *)devices transaction:(YapDatabaseReadWriteTransaction *)transaction { - OWSAssertDebug(transaction); - OWSAssertDebug(devices.count > 0); - - OWSLogDebug(@"removing devices: %@, from registered recipient: %@", devices, self); [self reloadWithTransaction:transaction ignoreMissing:YES]; [self removeDevices:devices]; [self saveWithTransaction_internal:transaction]; @@ -181,8 +155,7 @@ NS_ASSUME_NONNULL_BEGIN // correspond to an instance of SignalRecipient in the database (although // they may correspond to an "unsaved" instance of SignalRecipient built // by getOrBuildUnsavedRecipientForRecipientId. - OWSFailDebug(@"Don't call removeWithTransaction."); - + [super removeWithTransaction:transaction]; } @@ -194,16 +167,13 @@ NS_ASSUME_NONNULL_BEGIN // be strict about using persisted SignalRecipients as a cache to // reflect "last known registration status". Forcing our codebase to // use those methods helps ensure that we update the cache deliberately. - OWSFailDebug(@"Don't call saveWithTransaction from outside this class."); - + [self saveWithTransaction_internal:transaction]; } - (void)saveWithTransaction_internal:(YapDatabaseReadWriteTransaction *)transaction { [super saveWithTransaction:transaction]; - - OWSLogVerbose(@"saved signal recipient: %@ (%lu)", self.recipientId, (unsigned long) self.devices.count); } + (BOOL)isRegisteredRecipient:(NSString *)recipientId transaction:(YapDatabaseReadTransaction *)transaction @@ -214,14 +184,10 @@ NS_ASSUME_NONNULL_BEGIN + (SignalRecipient *)markRecipientAsRegisteredAndGet:(NSString *)recipientId transaction:(YapDatabaseReadWriteTransaction *)transaction { - OWSAssertDebug(transaction); - OWSAssertDebug(recipientId.length > 0); - SignalRecipient *_Nullable instance = [self registeredRecipientForRecipientId:recipientId mustHaveDevices:YES transaction:transaction]; if (!instance) { - OWSLogDebug(@"creating recipient: %@", recipientId); instance = [[self alloc] initWithTextSecureIdentifier:recipientId]; [instance saveWithTransaction_internal:transaction]; @@ -233,12 +199,8 @@ NS_ASSUME_NONNULL_BEGIN deviceId:(UInt32)deviceId transaction:(YapDatabaseReadWriteTransaction *)transaction { - OWSAssertDebug(transaction); - OWSAssertDebug(recipientId.length > 0); - SignalRecipient *recipient = [self markRecipientAsRegisteredAndGet:recipientId transaction:transaction]; if (![recipient.devices containsObject:@(deviceId)]) { - OWSLogDebug(@"Adding device %u to existing recipient.", (unsigned int)deviceId); [recipient addDevices:[NSSet setWithObject:@(deviceId)]]; [recipient saveWithTransaction_internal:transaction]; @@ -247,12 +209,8 @@ NS_ASSUME_NONNULL_BEGIN + (void)markRecipientAsUnregistered:(NSString *)recipientId transaction:(YapDatabaseReadWriteTransaction *)transaction { - OWSAssertDebug(transaction); - OWSAssertDebug(recipientId.length > 0); - SignalRecipient *instance = [self getOrBuildUnsavedRecipientForRecipientId:recipientId transaction:transaction]; - OWSLogDebug(@"Marking recipient as not registered: %@", recipientId); if (instance.devices.count > 0) { [instance removeDevices:instance.devices.set]; } diff --git a/SessionUtilitiesKit/NSUserDefaults+OWS.m b/SessionUtilitiesKit/NSUserDefaults+OWS.m index 1bf02767e..a500f28b7 100644 --- a/SessionUtilitiesKit/NSUserDefaults+OWS.m +++ b/SessionUtilitiesKit/NSUserDefaults+OWS.m @@ -4,7 +4,6 @@ #import "NSUserDefaults+OWS.h" #import "AppContext.h" -#import NS_ASSUME_NONNULL_BEGIN diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 0f4163221..4d2f02407 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -456,7 +456,6 @@ C33FDCA2255A582000E217F9 /* OWSMessageUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = C33FDAE8255A580500E217F9 /* OWSMessageUtils.h */; settings = {ATTRIBUTES = (Public, ); }; }; C33FDCA3255A582000E217F9 /* SSKMessageSenderJobRecord.m in Sources */ = {isa = PBXBuildFile; fileRef = C33FDAE9255A580500E217F9 /* SSKMessageSenderJobRecord.m */; }; C33FDCA4255A582000E217F9 /* OWSBackupFragment.h in Headers */ = {isa = PBXBuildFile; fileRef = C33FDAEA255A580500E217F9 /* OWSBackupFragment.h */; settings = {ATTRIBUTES = (Public, ); }; }; - C33FDCA6255A582000E217F9 /* SignalRecipient.h in Headers */ = {isa = PBXBuildFile; fileRef = C33FDAEC255A580500E217F9 /* SignalRecipient.h */; settings = {ATTRIBUTES = (Public, ); }; }; C33FDCA7255A582000E217F9 /* SSKMessageSenderJobRecord.h in Headers */ = {isa = PBXBuildFile; fileRef = C33FDAED255A580500E217F9 /* SSKMessageSenderJobRecord.h */; settings = {ATTRIBUTES = (Public, ); }; }; C33FDCAD255A582000E217F9 /* OWSPrimaryStorage+SessionStore.m in Sources */ = {isa = PBXBuildFile; fileRef = C33FDAF3255A580500E217F9 /* OWSPrimaryStorage+SessionStore.m */; }; C33FDCB1255A582000E217F9 /* OWSPrimaryStorage+SignedPreKeyStore.m in Sources */ = {isa = PBXBuildFile; fileRef = C33FDAF7255A580600E217F9 /* OWSPrimaryStorage+SignedPreKeyStore.m */; }; @@ -501,7 +500,6 @@ C33FDD67255A582000E217F9 /* OWSRecordTranscriptJob.h in Headers */ = {isa = PBXBuildFile; fileRef = C33FDBAD255A581500E217F9 /* OWSRecordTranscriptJob.h */; settings = {ATTRIBUTES = (Public, ); }; }; C33FDD68255A582000E217F9 /* SignalAccount.h in Headers */ = {isa = PBXBuildFile; fileRef = C33FDBAE255A581500E217F9 /* SignalAccount.h */; settings = {ATTRIBUTES = (Public, ); }; }; C33FDD6E255A582000E217F9 /* NSURLSessionDataTask+StatusCode.m in Sources */ = {isa = PBXBuildFile; fileRef = C33FDBB4255A581600E217F9 /* NSURLSessionDataTask+StatusCode.m */; }; - C33FDD71255A582000E217F9 /* SignalRecipient.m in Sources */ = {isa = PBXBuildFile; fileRef = C33FDBB7255A581600E217F9 /* SignalRecipient.m */; }; C33FDD74255A582000E217F9 /* OWSPrimaryStorage+keyFromIntLong.h in Headers */ = {isa = PBXBuildFile; fileRef = C33FDBBA255A581600E217F9 /* OWSPrimaryStorage+keyFromIntLong.h */; settings = {ATTRIBUTES = (Public, ); }; }; C33FDD75255A582000E217F9 /* OWSPrimaryStorage+Loki.h in Headers */ = {isa = PBXBuildFile; fileRef = C33FDBBB255A581600E217F9 /* OWSPrimaryStorage+Loki.h */; settings = {ATTRIBUTES = (Public, ); }; }; C33FDD79255A582000E217F9 /* OWSHTTPSecurityPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = C33FDBBF255A581700E217F9 /* OWSHTTPSecurityPolicy.m */; }; @@ -737,6 +735,8 @@ C3A3A156256E1B91004D228D /* ProtoUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = C33FDA6C255A57FA00E217F9 /* ProtoUtils.m */; }; C3A3A15F256E1BB4004D228D /* ProtoUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = C33FDB91255A581200E217F9 /* ProtoUtils.h */; settings = {ATTRIBUTES = (Public, ); }; }; C3A3A171256E1D25004D228D /* SSKReachabilityManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3A3A170256E1D25004D228D /* SSKReachabilityManager.swift */; }; + C3A3A18A256E2092004D228D /* SignalRecipient.m in Sources */ = {isa = PBXBuildFile; fileRef = C33FDBB7255A581600E217F9 /* SignalRecipient.m */; }; + C3A3A193256E20D4004D228D /* SignalRecipient.h in Headers */ = {isa = PBXBuildFile; fileRef = C33FDAEC255A580500E217F9 /* SignalRecipient.h */; settings = {ATTRIBUTES = (Public, ); }; }; C3A71D0B2558989C0043A11F /* MessageWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3A71D0A2558989C0043A11F /* MessageWrapper.swift */; }; C3A71D1E25589AC30043A11F /* WebSocketProto.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3A71D1C25589AC30043A11F /* WebSocketProto.swift */; }; C3A71D1F25589AC30043A11F /* WebSocketResources.pb.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3A71D1D25589AC30043A11F /* WebSocketResources.pb.swift */; }; @@ -3016,8 +3016,6 @@ C33FDC06255A581D00E217F9 /* SignalAccount.m */, C33FDBD8255A581900E217F9 /* SignalIOS.pb.swift */, C33FDB40255A580C00E217F9 /* SignalIOSProto.swift */, - C33FDAEC255A580500E217F9 /* SignalRecipient.h */, - C33FDBB7255A581600E217F9 /* SignalRecipient.m */, C33FDAED255A580500E217F9 /* SSKMessageSenderJobRecord.h */, C33FDAE9255A580500E217F9 /* SSKMessageSenderJobRecord.m */, C33FDC12255A581E00E217F9 /* TSConstants.h */, @@ -3345,6 +3343,8 @@ C3BBE0B42554F0E10050F1E3 /* ProofOfWork.swift */, C33FDB91255A581200E217F9 /* ProtoUtils.h */, C33FDA6C255A57FA00E217F9 /* ProtoUtils.m */, + C33FDAEC255A580500E217F9 /* SignalRecipient.h */, + C33FDBB7255A581600E217F9 /* SignalRecipient.m */, C38EEF09255B49A8007E1867 /* SNProtoEnvelope+Conversion.swift */, C33FDB31255A580A00E217F9 /* SSKEnvironment.h */, C33FDAF4255A580600E217F9 /* SSKEnvironment.m */, @@ -3944,7 +3944,6 @@ C33FDC95255A582000E217F9 /* OWSFailedMessagesJob.h in Headers */, C38EF3F1255B6DF7007E1867 /* OWSSearchBar.h in Headers */, C33FDD75255A582000E217F9 /* OWSPrimaryStorage+Loki.h in Headers */, - C33FDCA6255A582000E217F9 /* SignalRecipient.h in Headers */, C38EF277255B6D7A007E1867 /* OWSDatabaseMigration.h in Headers */, C38EF294255B6D86007E1867 /* OWSSounds.h in Headers */, C38EF3F5255B6DF7007E1867 /* OWSTextField.h in Headers */, @@ -4058,6 +4057,7 @@ C32C5B6B256DC357003C73A2 /* OWSDisappearingConfigurationUpdateInfoMessage.h in Headers */, C32C5F23256DFCC0003C73A2 /* TSErrorMessage_privateConstructor.h in Headers */, C32C5BBA256DC7E3003C73A2 /* ProfileManagerProtocol.h in Headers */, + C3A3A193256E20D4004D228D /* SignalRecipient.h in Headers */, C32C5E7E256DE023003C73A2 /* YapDatabaseTransaction+OWS.h in Headers */, C32C5CAD256DD1DF003C73A2 /* TSAccountManager.h in Headers */, C3A3A0F5256E194C004D228D /* OWSRecipientIdentity.h in Headers */, @@ -4985,7 +4985,6 @@ C38EF2A6255B6D93007E1867 /* PlaceholderIcon.swift in Sources */, C38EF316255B6DBF007E1867 /* ProximityMonitoringManager.swift in Sources */, C38EF371255B6DCC007E1867 /* MessageApprovalViewController.swift in Sources */, - C33FDD71255A582000E217F9 /* SignalRecipient.m in Sources */, C33FDD92255A582000E217F9 /* SignalIOS.pb.swift in Sources */, C33FDC45255A581F00E217F9 /* AppVersion.m in Sources */, C38EF3C7255B6DE7007E1867 /* ImageEditorCanvasView.swift in Sources */, @@ -5253,6 +5252,7 @@ C32C5FBB256E0206003C73A2 /* OWSBackgroundTask.m in Sources */, C32C5C93256DD12D003C73A2 /* OWSUDManager.swift in Sources */, C32C5C3D256DCBAF003C73A2 /* AppReadiness.m in Sources */, + C3A3A18A256E2092004D228D /* SignalRecipient.m in Sources */, C3C2A74425539EB700C340D1 /* Message.swift in Sources */, C32C5F11256DF79A003C73A2 /* SSKIncrementingIdFinder.swift in Sources */, C32C5DBF256DD743003C73A2 /* ClosedGroupPoller.swift in Sources */, diff --git a/SignalUtilitiesKit/Meta/SignalUtilitiesKit.h b/SignalUtilitiesKit/Meta/SignalUtilitiesKit.h index 4594d9af8..7516c76f9 100644 --- a/SignalUtilitiesKit/Meta/SignalUtilitiesKit.h +++ b/SignalUtilitiesKit/Meta/SignalUtilitiesKit.h @@ -48,7 +48,6 @@ FOUNDATION_EXPORT const unsigned char SignalUtilitiesKitVersionString[]; #import #import #import -#import #import #import #import