diff --git a/Signal/src/ViewControllers/HomeView/HomeViewController.m b/Signal/src/ViewControllers/HomeView/HomeViewController.m index 446326f74..586ef500e 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewController.m +++ b/Signal/src/ViewControllers/HomeView/HomeViewController.m @@ -1137,6 +1137,14 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations - (void)deleteThread:(TSThread *)thread { [self.editingDbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { + if ([thread isKindOfClass:[TSGroupThread class]]) { + TSGroupThread *groupThread = (TSGroupThread *)thread; + if (groupThread.isLocalUserInGroup) { + [groupThread softDeleteGroupThreadWithTransaction:transaction]; + return; + } + } + [thread removeWithTransaction:transaction]; }]; diff --git a/SignalMessaging/utils/ThreadUtil.m b/SignalMessaging/utils/ThreadUtil.m index b6d562279..068532fa1 100644 --- a/SignalMessaging/utils/ThreadUtil.m +++ b/SignalMessaging/utils/ThreadUtil.m @@ -806,7 +806,7 @@ NS_ASSUME_NONNULL_BEGIN if ([OWSProfileManager.sharedManager isThreadInProfileWhitelist:thread]) { return NO; } - if (!thread.hasEverHadMessage) { + if (!thread.shouldThreadBeVisible) { [OWSProfileManager.sharedManager addThreadToProfileWhitelist:thread]; return YES; } else { diff --git a/SignalServiceKit/src/Contacts/TSThread.h b/SignalServiceKit/src/Contacts/TSThread.h index 0bdc7c106..1b0228c0f 100644 --- a/SignalServiceKit/src/Contacts/TSThread.h +++ b/SignalServiceKit/src/Contacts/TSThread.h @@ -33,7 +33,7 @@ extern ConversationColorName const kConversationColorName_Default; @interface TSThread : TSYapDatabaseObject // YES IFF this thread has ever had a message. -@property (nonatomic) BOOL hasEverHadMessage; +@property (nonatomic) BOOL shouldThreadBeVisible; /** * Whether the object is a group thread or not. diff --git a/SignalServiceKit/src/Contacts/TSThread.m b/SignalServiceKit/src/Contacts/TSThread.m index 4d046f132..3a02af197 100644 --- a/SignalServiceKit/src/Contacts/TSThread.m +++ b/SignalServiceKit/src/Contacts/TSThread.m @@ -82,7 +82,16 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa if (!self) { return self; } - + + // renamed `hasEverHadMessage` -> `shouldThreadBeVisible` + if (!_shouldThreadBeVisible) { + NSNumber *_Nullable legacy_hasEverHadMessage = [coder decodeObjectForKey:@"hasEverHadMessage"]; + + if (legacy_hasEverHadMessage != nil) { + _shouldThreadBeVisible = legacy_hasEverHadMessage.boolValue; + } + } + if (_conversationColorName.length == 0) { NSString *_Nullable colorSeed = self.contactIdentifier; if (colorSeed.length > 0) { @@ -390,7 +399,7 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa return; } - self.hasEverHadMessage = YES; + self.shouldThreadBeVisible = YES; NSDate *lastMessageDate = [lastMessage dateForSorting]; if (!_lastMessageDate || [lastMessageDate timeIntervalSinceDate:self.lastMessageDate] > 0) { diff --git a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h index 3fe639295..bc214f93b 100644 --- a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h +++ b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h @@ -31,6 +31,8 @@ extern NSString *const TSGroupThread_NotificationKey_UniqueId; + (NSString *)defaultGroupName; +- (BOOL)isLocalUserInGroup; + // all group threads containing recipient as a member + (NSArray *)groupThreadsWithRecipientId:(NSString *)recipientId transaction:(YapDatabaseReadWriteTransaction *)transaction; @@ -38,6 +40,10 @@ extern NSString *const TSGroupThread_NotificationKey_UniqueId; - (void)leaveGroupWithSneakyTransaction; - (void)leaveGroupWithTransaction:(YapDatabaseReadWriteTransaction *)transaction; +- (void)softDeleteGroupThreadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction; + +#pragma mark - Avatar + - (void)updateAvatarWithAttachmentStream:(TSAttachmentStream *)attachmentStream; - (void)updateAvatarWithAttachmentStream:(TSAttachmentStream *)attachmentStream transaction:(YapDatabaseReadWriteTransaction *)transaction; diff --git a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m index 8ea47e1e2..af20285bb 100644 --- a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m +++ b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m @@ -173,6 +173,16 @@ NSString *const TSGroupThread_NotificationKey_UniqueId = @"TSGroupThread_Notific return true; } +- (BOOL)isLocalUserInGroup +{ + NSString *_Nullable localNumber = TSAccountManager.localNumber; + if (localNumber == nil) { + return NO; + } + + return [self.groupModel.groupMemberIds containsObject:localNumber]; +} + - (NSString *)name { // TODO sometimes groupName is set to the empty string. I'm hesitent to change @@ -203,6 +213,13 @@ NSString *const TSGroupThread_NotificationKey_UniqueId = @"TSGroupThread_Notific [self saveWithTransaction:transaction]; } +- (void)softDeleteGroupThreadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction +{ + [self removeAllThreadInteractionsWithTransaction:transaction]; + self.shouldThreadBeVisible = NO; + [self saveWithTransaction:transaction]; +} + #pragma mark - Avatar - (void)updateAvatarWithAttachmentStream:(TSAttachmentStream *)attachmentStream diff --git a/SignalServiceKit/src/Storage/FullTextSearchFinder.swift b/SignalServiceKit/src/Storage/FullTextSearchFinder.swift index 53e3e7147..10d0fa9a3 100644 --- a/SignalServiceKit/src/Storage/FullTextSearchFinder.swift +++ b/SignalServiceKit/src/Storage/FullTextSearchFinder.swift @@ -204,7 +204,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.hasEverHadMessage else { + guard contactThread.shouldThreadBeVisible 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 ade284d92..af7d7d1db 100644 --- a/SignalServiceKit/src/Storage/TSDatabaseView.m +++ b/SignalServiceKit/src/Storage/TSDatabaseView.m @@ -202,9 +202,7 @@ NSString *const TSLazyRestoreAttachmentsGroup = @"TSLazyRestoreAttachmentsGroup" } TSThread *thread = (TSThread *)object; - if (thread.isGroupThread) { - // Do nothing; we never hide group threads. - } else if (thread.hasEverHadMessage) { + if (thread.shouldThreadBeVisible) { // Do nothing; we never hide threads that have ever had a message. } else { YapDatabaseViewTransaction *viewTransaction = [transaction ext:TSMessageDatabaseViewExtensionName]; @@ -232,7 +230,7 @@ NSString *const TSLazyRestoreAttachmentsGroup = @"TSLazyRestoreAttachmentsGroup" [[YapWhitelistBlacklist alloc] initWithWhitelist:[NSSet setWithObject:[TSThread collection]]]; YapDatabaseView *databaseView = - [[YapDatabaseAutoView alloc] initWithGrouping:viewGrouping sorting:viewSorting versionTag:@"3" options:options]; + [[YapDatabaseAutoView alloc] initWithGrouping:viewGrouping sorting:viewSorting versionTag:@"4" options:options]; [storage asyncRegisterExtension:databaseView withName:TSThreadDatabaseViewExtensionName]; }