Replace isForceHidden with computed isSlaveThread

pull/182/head
Mikunj 5 years ago
parent 31bfa0888b
commit 4d0207f20a

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

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

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

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

@ -117,10 +117,6 @@ public final class SessionManagementProtocol : NSObject {
public static func getSessionResetMessageSend(for hexEncodedPublicKey: String, in transaction: YapDatabaseReadWriteTransaction) -> Promise<OWSMessageSend> {
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

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

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

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

Loading…
Cancel
Save