diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 037d2383a..91a0d8720 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // #import "ConversationViewController.h" @@ -497,7 +497,7 @@ typedef enum : NSUInteger { } TSGroupThread *groupThread = (TSGroupThread *)self.thread; - return ![groupThread.groupModel.groupMemberIds containsObject:self.tsAccountManager.localNumber]; + return !groupThread.isLocalUserInGroup; } - (void)hideInputIfNeeded @@ -1258,8 +1258,7 @@ typedef enum : NSUInteger { } else { OWSAssertDebug(self.thread.contactIdentifier); - BOOL isNoteToSelf = [self.thread.contactIdentifier isEqualToString:self.tsAccountManager.localNumber]; - if (isNoteToSelf) { + if (self.thread.isNoteToSelf) { name = [[NSAttributedString alloc] initWithString:NSLocalizedString(@"NOTE_TO_SELF", @"Label for 1:1 conversation with yourself.") attributes:@{ diff --git a/Signal/src/ViewControllers/HomeView/HomeViewCell.m b/Signal/src/ViewControllers/HomeView/HomeViewCell.m index 5a86f96c6..820598db2 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewCell.m +++ b/Signal/src/ViewControllers/HomeView/HomeViewCell.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // #import "HomeViewCell.h" @@ -517,8 +517,7 @@ NS_ASSUME_NONNULL_BEGIN name = [[NSAttributedString alloc] initWithString:thread.name]; } } else { - BOOL isNoteToSelf = [self.thread.contactIdentifier isEqualToString:self.tsAccountManager.localNumber]; - if (isNoteToSelf) { + if (self.thread.threadRecord.isNoteToSelf) { name = [[NSAttributedString alloc] initWithString:NSLocalizedString(@"NOTE_TO_SELF", @"Label for 1:1 conversation with yourself.") attributes:@{ diff --git a/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m b/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m index 8a89940ca..4df03214e 100644 --- a/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m +++ b/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // #import "OWSConversationSettingsViewController.h" @@ -310,8 +310,7 @@ const CGFloat kIconViewLength = 24; OWSTableContents *contents = [OWSTableContents new]; contents.title = NSLocalizedString(@"CONVERSATION_SETTINGS", @"title for conversation settings screen"); - BOOL isNoteToSelf = (!self.thread.isGroupThread && - [self.thread.contactIdentifier isEqualToString:self.tsAccountManager.localNumber]); + BOOL isNoteToSelf = self.thread.isNoteToSelf; __weak OWSConversationSettingsViewController *weakSelf = self; @@ -1085,8 +1084,7 @@ const CGFloat kIconViewLength = 24; { if (self.isGroupThread) { TSGroupThread *groupThread = (TSGroupThread *)self.thread; - BOOL inGroup = [groupThread.groupModel.groupMemberIds containsObject:TSAccountManager.localNumber]; - return !inGroup; + return !groupThread.isLocalUserInGroup; } return NO; diff --git a/SignalServiceKit/src/Account/TSAccountManager.h b/SignalServiceKit/src/Account/TSAccountManager.h index bf6f6cd95..dece93ae6 100644 --- a/SignalServiceKit/src/Account/TSAccountManager.h +++ b/SignalServiceKit/src/Account/TSAccountManager.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // #import "TSConstants.h" @@ -59,7 +59,7 @@ typedef NS_ENUM(NSUInteger, OWSRegistrationState) { - (nullable NSString *)localNumber; // A variant of localNumber that never opens a "sneaky" transaction. -- (nullable NSString *)storedLocalNumber:(YapDatabaseReadTransaction *)transaction; +- (nullable NSString *)storedOrCachedLocalNumber:(YapDatabaseReadTransaction *)transaction; /** * Symmetric key that's used to encrypt message payloads from the server, diff --git a/SignalServiceKit/src/Account/TSAccountManager.m b/SignalServiceKit/src/Account/TSAccountManager.m index ea80c5f1a..21798c5b3 100644 --- a/SignalServiceKit/src/Account/TSAccountManager.m +++ b/SignalServiceKit/src/Account/TSAccountManager.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // #import "TSAccountManager.h" @@ -220,8 +220,14 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa } } -- (nullable NSString *)storedLocalNumber:(YapDatabaseReadTransaction *)transaction +- (nullable NSString *)storedOrCachedLocalNumber:(YapDatabaseReadTransaction *)transaction { + @synchronized(self) { + if (self.cachedLocalNumber) { + return self.cachedLocalNumber; + } + } + return [transaction stringForKey:TSAccountManager_RegisteredNumberKey inCollection:TSAccountManager_UserAccountCollection]; } diff --git a/SignalServiceKit/src/Contacts/TSThread.h b/SignalServiceKit/src/Contacts/TSThread.h index 0b2b3dd32..2aa098655 100644 --- a/SignalServiceKit/src/Contacts/TSThread.h +++ b/SignalServiceKit/src/Contacts/TSThread.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // #import "TSYapDatabaseObject.h" @@ -68,6 +68,8 @@ extern ConversationColorName const kConversationColorName_Default; */ @property (nonatomic, readonly) NSArray *recipientIdentifiers; +- (BOOL)isNoteToSelf; + #pragma mark Interactions /** diff --git a/SignalServiceKit/src/Contacts/TSThread.m b/SignalServiceKit/src/Contacts/TSThread.m index 7ab1e04fa..26eb0b697 100644 --- a/SignalServiceKit/src/Contacts/TSThread.m +++ b/SignalServiceKit/src/Contacts/TSThread.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // #import "TSThread.h" @@ -7,6 +7,8 @@ #import "OWSDisappearingMessagesConfiguration.h" #import "OWSPrimaryStorage.h" #import "OWSReadTracking.h" +#import "SSKEnvironment.h" +#import "TSAccountManager.h" #import "TSDatabaseView.h" #import "TSIncomingMessage.h" #import "TSInfoMessage.h" @@ -55,6 +57,17 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa @implementation TSThread +#pragma mark - Dependencies + +- (TSAccountManager *)tsAccountManager +{ + OWSAssertDebug(SSKEnvironment.shared.tsAccountManager); + + return SSKEnvironment.shared.tsAccountManager; +} + +#pragma mark - + + (NSString *)collection { return @"TSThread"; } @@ -179,7 +192,13 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa } } -#pragma mark To be subclassed. +- (BOOL)isNoteToSelf +{ + return (!self.isGroupThread && self.contactIdentifier != nil && + [self.contactIdentifier isEqualToString:self.tsAccountManager.localNumber]); +} + +#pragma mark - To be subclassed. - (BOOL)isGroupThread { OWSAbstractMethod(); @@ -211,7 +230,7 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa return NO; } -#pragma mark Interactions +#pragma mark - Interactions /** * Iterate over this thread's interactions @@ -405,7 +424,7 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa } } -#pragma mark Disappearing Messages +#pragma mark - Disappearing Messages - (OWSDisappearingMessagesConfiguration *)disappearingMessagesConfigurationWithTransaction: (YapDatabaseReadTransaction *)transaction diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index 9e776942a..ecc24734e 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // #import "OWSMessageManager.h" @@ -511,7 +511,7 @@ NS_ASSUME_NONNULL_BEGIN if (groupThread) { if (dataMessage.group.type != SSKProtoGroupContextTypeUpdate) { - if (![groupThread.groupModel.groupMemberIds containsObject:self.tsAccountManager.localNumber]) { + if (!groupThread.isLocalUserInGroup) { OWSLogInfo(@"Ignoring messages for left group."); return; } @@ -705,7 +705,7 @@ NS_ASSUME_NONNULL_BEGIN if (typingMessage.hasGroupID) { TSGroupThread *groupThread = [TSGroupThread threadWithGroupId:typingMessage.groupID transaction:transaction]; - if (![groupThread.groupModel.groupMemberIds containsObject:self.tsAccountManager.localNumber]) { + if (!groupThread.isLocalUserInGroup) { OWSLogInfo(@"Ignoring messages for left group."); return; } @@ -1135,8 +1135,7 @@ NS_ASSUME_NONNULL_BEGIN } // Ensure we are in the group. - NSString *localNumber = self.tsAccountManager.localNumber; - if (![gThread.groupModel.groupMemberIds containsObject:localNumber]) { + if (!gThread.isLocalUserInGroup) { OWSLogWarn(@"Ignoring 'Request Group Info' message for group we no longer belong to."); return; } diff --git a/SignalServiceKit/src/Storage/FullTextSearchFinder.swift b/SignalServiceKit/src/Storage/FullTextSearchFinder.swift index 899a3e96d..234c45287 100644 --- a/SignalServiceKit/src/Storage/FullTextSearchFinder.swift +++ b/SignalServiceKit/src/Storage/FullTextSearchFinder.swift @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // import Foundation @@ -192,7 +192,7 @@ public class FullTextSearchFinder: NSObject { var result = "\(recipientId) \(nationalNumber) \(displayName)" - if let localNumber = tsAccountManager.storedLocalNumber(transaction) { + if let localNumber = tsAccountManager.storedOrCachedLocalNumber(transaction) { if localNumber == recipientId { let noteToSelfLabel = NSLocalizedString("NOTE_TO_SELF", comment: "Label for 1:1 conversation with yourself.") result += " \(noteToSelfLabel)"