From beb02afce9bb4c3fc19ddc0f7aa45cf45db10443 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 11 Dec 2018 15:07:50 -0700 Subject: [PATCH] Soft delete group threads --- .../ViewControllers/HomeView/HomeViewController.m | 8 ++++++++ .../src/Contacts/Threads/TSGroupThread.h | 6 ++++++ .../src/Contacts/Threads/TSGroupThread.m | 12 ++++++++++++ SignalServiceKit/src/Storage/TSDatabaseView.m | 6 ++---- 4 files changed, 28 insertions(+), 4 deletions(-) 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/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..bb892b0c1 100644 --- a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m +++ b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m @@ -173,6 +173,11 @@ NSString *const TSGroupThread_NotificationKey_UniqueId = @"TSGroupThread_Notific return true; } +- (BOOL)isLocalUserInGroup +{ + return [self.groupModel.groupMemberIds containsObject:TSAccountManager.localNumber]; +} + - (NSString *)name { // TODO sometimes groupName is set to the empty string. I'm hesitent to change @@ -203,6 +208,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/TSDatabaseView.m b/SignalServiceKit/src/Storage/TSDatabaseView.m index e309b2365..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.shouldThreadBeVisible) { + 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]; }