diff --git a/SignalServiceKit/src/Contacts/TSThread.h b/SignalServiceKit/src/Contacts/TSThread.h index 139f3a02d..d0998d905 100644 --- a/SignalServiceKit/src/Contacts/TSThread.h +++ b/SignalServiceKit/src/Contacts/TSThread.h @@ -43,7 +43,7 @@ extern ConversationColorName const kConversationColorName_Default; @property (nonatomic) NSInteger friendRequestStatus __deprecated_msg("use OWSPrimaryStorage.getFriendRequestStatusForContact:transaction: instead"); @property (nonatomic, readonly) BOOL isContactFriend; // ======== -@property (nonatomic) BOOL isForceHidden; // FIXME: Having both this and shouldThreadBeVisible is confusing +@property (atomic, readonly) BOOL isSlaveThread; /** * Whether the object is a group thread or not. diff --git a/SignalServiceKit/src/Contacts/TSThread.m b/SignalServiceKit/src/Contacts/TSThread.m index 8a7c1f731..33571237a 100644 --- a/SignalServiceKit/src/Contacts/TSThread.m +++ b/SignalServiceKit/src/Contacts/TSThread.m @@ -773,6 +773,11 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa return [LKFriendRequestProtocol getFriendRequestUIStatusForThread:self] == LKFriendRequestUIStatusFriends; } +- (BOOL)isSlaveThread +{ + return [LKMultiDeviceProtocol isSlaveThread:self]; +} + @end NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m index 2a817719c..9747e84fb 100644 --- a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m +++ b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m @@ -314,6 +314,11 @@ NSString *const TSGroupThread_NotificationKey_UniqueId = @"TSGroupThread_Notific return [self.class stableColorNameForNewConversationWithString:[self threadIdFromGroupId:groupId]]; } +- (BOOL)isContactFriend +{ + return true; +} + @end NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/src/Loki/Protocol/Multi Device/MultiDeviceProtocol.swift b/SignalServiceKit/src/Loki/Protocol/Multi Device/MultiDeviceProtocol.swift index a84b8024d..66b930464 100644 --- a/SignalServiceKit/src/Loki/Protocol/Multi Device/MultiDeviceProtocol.swift +++ b/SignalServiceKit/src/Loki/Protocol/Multi Device/MultiDeviceProtocol.swift @@ -151,10 +151,6 @@ public final class MultiDeviceProtocol : NSObject { @objc(getAutoGeneratedMultiDeviceFRMessageForHexEncodedPublicKey:in:) public static func getAutoGeneratedMultiDeviceFRMessage(for hexEncodedPublicKey: String, in transaction: YapDatabaseReadWriteTransaction) -> FriendRequestMessage { let thread = TSContactThread.getOrCreateThread(withContactId: hexEncodedPublicKey, transaction: transaction) - let masterHexEncodedPublicKey = storage.getMasterHexEncodedPublicKey(for: hexEncodedPublicKey, in: transaction) - let isSlaveDeviceThread = masterHexEncodedPublicKey != hexEncodedPublicKey - thread.isForceHidden = isSlaveDeviceThread // TODO: Could we make this computed? - thread.save(with: transaction) let result = FriendRequestMessage(outgoingMessageWithTimestamp: NSDate.ows_millisecondTimeStamp(), in: thread, messageBody: "Please accept to enable messages to be synced across devices", attachmentIds: [], expiresInSeconds: 0, expireStartedAt: 0, isVoiceMessage: false, @@ -264,6 +260,15 @@ public final class MultiDeviceProtocol : NSObject { } } } + + @objc public static func isSlaveThread(_ thread: TSThread) -> Bool { + guard let thread = thread as? TSContactThread else { return false; } + var isSlaveThread = false + Storage.read { transaction in + isSlaveThread = storage.getMasterHexEncodedPublicKey(for: thread.contactIdentifier(), in: transaction) != nil + } + return isSlaveThread + } } // MARK: - Sending (Part 2) diff --git a/SignalServiceKit/src/Loki/Protocol/Session Management/SessionManagementProtocol.swift b/SignalServiceKit/src/Loki/Protocol/Session Management/SessionManagementProtocol.swift index 4a722181d..90bd27d02 100644 --- a/SignalServiceKit/src/Loki/Protocol/Session Management/SessionManagementProtocol.swift +++ b/SignalServiceKit/src/Loki/Protocol/Session Management/SessionManagementProtocol.swift @@ -117,10 +117,6 @@ public final class SessionManagementProtocol : NSObject { public static func getSessionResetMessageSend(for hexEncodedPublicKey: String, in transaction: YapDatabaseReadWriteTransaction) -> Promise { let thread = TSContactThread.getOrCreateThread(withContactId: hexEncodedPublicKey, transaction: transaction) - let masterHexEncodedPublicKey = storage.getMasterHexEncodedPublicKey(for: hexEncodedPublicKey, in: transaction) - let isSlaveDeviceThread = masterHexEncodedPublicKey != hexEncodedPublicKey - thread.isForceHidden = isSlaveDeviceThread - thread.save(with: transaction) let message = getSessionResetMessage(for: hexEncodedPublicKey, in: transaction) let recipient = SignalRecipient.getOrBuildUnsavedRecipient(forRecipientId: hexEncodedPublicKey, transaction: transaction) let udManager = SSKEnvironment.shared.udManager diff --git a/SignalServiceKit/src/Loki/Protocol/Sync Messages/SyncMessagesProtocol.swift b/SignalServiceKit/src/Loki/Protocol/Sync Messages/SyncMessagesProtocol.swift index f86aa313b..da00355b5 100644 --- a/SignalServiceKit/src/Loki/Protocol/Sync Messages/SyncMessagesProtocol.swift +++ b/SignalServiceKit/src/Loki/Protocol/Sync Messages/SyncMessagesProtocol.swift @@ -41,7 +41,7 @@ public final class SyncMessagesProtocol : NSObject { TSContactThread.enumerateCollectionObjects { object, _ in guard let thread = object as? TSContactThread else { return } let hexEncodedPublicKey = thread.contactIdentifier() - guard thread.isContactFriend && thread.shouldThreadBeVisible && !thread.isForceHidden else { return } + guard thread.isContactFriend && thread.shouldThreadBeVisible && !thread.isSlaveThread else { return } friends.append(SignalAccount(recipientId: hexEncodedPublicKey)) } friends.append(SignalAccount(recipientId: getUserHexEncodedPublicKey())) // TODO: Are we sure about this? @@ -61,7 +61,7 @@ public final class SyncMessagesProtocol : NSObject { var groups: [TSGroupThread] = [] TSGroupThread.enumerateCollectionObjects { object, _ in guard let group = object as? TSGroupThread, group.groupModel.groupType == .closedGroup, - group.shouldThreadBeVisible, !group.isForceHidden else { return } + group.shouldThreadBeVisible else { return } groups.append(group) } let syncManager = SSKEnvironment.shared.syncManager @@ -168,30 +168,23 @@ public final class SyncMessagesProtocol : NSObject { // Try to establish sessions for hexEncodedPublicKey in hexEncodedPublicKeys { // We don't update the friend request status; that's done in OWSMessageSender.sendMessage(_:) - let thread = TSContactThread.getOrCreateThread(withContactId: hexEncodedPublicKey, transaction: transaction) let friendRequestStatus = storage.getFriendRequestStatus(for: hexEncodedPublicKey, transaction: transaction) switch friendRequestStatus { case .none, .requestExpired: let messageSender = SSKEnvironment.shared.messageSender // We need to send the FR message to all of the user's devices as the contact sync message excludes slave devices let autoGeneratedFRMessage = MultiDeviceProtocol.getAutoGeneratedMultiDeviceFRMessage(for: hexEncodedPublicKey, in: transaction) - thread.isForceHidden = true - thread.save(with: transaction) // This takes into account multi device messageSender.send(autoGeneratedFRMessage, success: { DispatchQueue.main.async { storage.dbReadWriteConnection.readWrite { transaction in autoGeneratedFRMessage.remove(with: transaction) - thread.isForceHidden = false - thread.save(with: transaction) } } }, failure: { error in DispatchQueue.main.async { storage.dbReadWriteConnection.readWrite { transaction in autoGeneratedFRMessage.remove(with: transaction) - thread.isForceHidden = false - thread.save(with: transaction) } } }) diff --git a/SignalServiceKit/src/Storage/FullTextSearchFinder.swift b/SignalServiceKit/src/Storage/FullTextSearchFinder.swift index fe6b49b83..4d1fde2f3 100644 --- a/SignalServiceKit/src/Storage/FullTextSearchFinder.swift +++ b/SignalServiceKit/src/Storage/FullTextSearchFinder.swift @@ -215,7 +215,7 @@ public class FullTextSearchFinder: NSObject { if let groupThread = object as? TSGroupThread { return self.groupThreadIndexer.index(groupThread, transaction: transaction) } else if let contactThread = object as? TSContactThread { - guard contactThread.shouldThreadBeVisible && !contactThread.isForceHidden else { + guard contactThread.shouldThreadBeVisible && !contactThread.isSlaveThread else { // If we've never sent/received a message in a TSContactThread, // then we want it to appear in the "Other Contacts" section rather // than in the "Conversations" section. diff --git a/SignalServiceKit/src/Storage/TSDatabaseView.m b/SignalServiceKit/src/Storage/TSDatabaseView.m index 04507c32b..868b06c74 100644 --- a/SignalServiceKit/src/Storage/TSDatabaseView.m +++ b/SignalServiceKit/src/Storage/TSDatabaseView.m @@ -281,14 +281,15 @@ NSString *const TSLazyRestoreAttachmentsGroup = @"TSLazyRestoreAttachmentsGroup" return nil; } TSThread *thread = (TSThread *)object; + if (thread.isSlaveThread) { return nil; } - if (thread.shouldThreadBeVisible && !thread.isForceHidden) { + if (thread.shouldThreadBeVisible) { // Do nothing; we never hide threads that have ever had a message. } else { YapDatabaseViewTransaction *viewTransaction = [transaction ext:TSMessageDatabaseViewExtensionName]; OWSAssertDebug(viewTransaction); NSUInteger threadMessageCount = [viewTransaction numberOfItemsInGroup:thread.uniqueId]; - if (threadMessageCount < 1 || thread.isForceHidden) { + if (threadMessageCount < 1) { return nil; } }