From 75f3339c267169b9b4ed250e206b2f4ef33aab31 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Thu, 12 Sep 2019 12:08:14 -0600 Subject: [PATCH 1/2] soft delete contact threads --- .../ConversationView/ConversationViewController.m | 6 ++---- .../src/ViewControllers/HomeView/HomeViewController.m | 10 ++++++---- SignalServiceKit/src/Contacts/TSThread.h | 2 ++ SignalServiceKit/src/Contacts/TSThread.m | 10 ++++++++++ SignalServiceKit/src/Contacts/Threads/TSGroupThread.h | 2 -- SignalServiceKit/src/Contacts/Threads/TSGroupThread.m | 10 ---------- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 9204a10296..3d91aa8aa3 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -5262,12 +5262,10 @@ typedef enum : NSUInteger { [self.messageSenderJobQueue addMessage:message transaction:transaction]; [groupThread leaveGroupWithTransaction:transaction]; } - - [groupThread softDeleteGroupThreadWithTransaction:transaction]; - } else { - [self.thread anyRemoveWithTransaction:transaction]; } + [self.thread softDeleteThreadWithTransaction:transaction]; + [transaction addCompletionWithBlock:^{ [self.navigationController popViewControllerAnimated:YES]; }]; diff --git a/Signal/src/ViewControllers/HomeView/HomeViewController.m b/Signal/src/ViewControllers/HomeView/HomeViewController.m index bf465df554..3df5c7ba58 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewController.m +++ b/Signal/src/ViewControllers/HomeView/HomeViewController.m @@ -1378,12 +1378,14 @@ NSString *const kArchiveButtonPseudoGroup = @"kArchiveButtonPseudoGroup"; if ([thread isKindOfClass:[TSGroupThread class]]) { TSGroupThread *groupThread = (TSGroupThread *)thread; if (groupThread.isLocalUserInGroup) { - [groupThread softDeleteGroupThreadWithTransaction:transaction]; - return; + [groupThread softDeleteThreadWithTransaction:transaction]; + } else { + [groupThread anyRemoveWithTransaction:transaction]; } + } else { + // contact thread + [thread softDeleteThreadWithTransaction:transaction]; } - - [thread anyRemoveWithTransaction:transaction]; }]; [self updateViewState]; diff --git a/SignalServiceKit/src/Contacts/TSThread.h b/SignalServiceKit/src/Contacts/TSThread.h index eea74fd667..21e4c113b3 100644 --- a/SignalServiceKit/src/Contacts/TSThread.h +++ b/SignalServiceKit/src/Contacts/TSThread.h @@ -138,6 +138,8 @@ NS_SWIFT_NAME(init(uniqueId:archivalDate:archivedAsOfMessageSortId:conversationC */ - (void)archiveThreadWithTransaction:(SDSAnyWriteTransaction *)transaction; +- (void)softDeleteThreadWithTransaction:(SDSAnyWriteTransaction *)transaction; + /** * Unarchives a thread * diff --git a/SignalServiceKit/src/Contacts/TSThread.m b/SignalServiceKit/src/Contacts/TSThread.m index a8621c7452..fda0c6f701 100644 --- a/SignalServiceKit/src/Contacts/TSThread.m +++ b/SignalServiceKit/src/Contacts/TSThread.m @@ -447,6 +447,16 @@ isArchivedByLegacyTimestampForSorting:(BOOL)isArchivedByLegacyTimestampForSortin } } +- (void)softDeleteThreadWithTransaction:(SDSAnyWriteTransaction *)transaction +{ + [self removeAllThreadInteractionsWithTransaction:transaction]; + [self anyUpdateWithTransaction:transaction + block:^(TSThread *thread) { + thread.messageDraft = nil; + thread.shouldThreadBeVisible = NO; + }]; +} + #pragma mark - Disappearing Messages - (OWSDisappearingMessagesConfiguration *)disappearingMessagesConfigurationWithTransaction: diff --git a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h index 987064e550..824ce7a8a9 100644 --- a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h +++ b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h @@ -69,8 +69,6 @@ NS_SWIFT_NAME(init(uniqueId:archivalDate:archivedAsOfMessageSortId:conversationC - (void)leaveGroupWithSneakyTransaction; - (void)leaveGroupWithTransaction:(SDSAnyWriteTransaction *)transaction; -- (void)softDeleteGroupThreadWithTransaction:(SDSAnyWriteTransaction *)transaction; - #pragma mark - Avatar - (void)updateAvatarWithAttachmentStream:(TSAttachmentStream *)attachmentStream; diff --git a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m index 8ea2dcfb86..e6f79107c3 100644 --- a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m +++ b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m @@ -260,16 +260,6 @@ isArchivedByLegacyTimestampForSorting:isArchivedByLegacyTimestampForSorting }]; } -- (void)softDeleteGroupThreadWithTransaction:(SDSAnyWriteTransaction *)transaction -{ - [self removeAllThreadInteractionsWithTransaction:transaction]; - - [self anyUpdateGroupThreadWithTransaction:transaction - block:^(TSGroupThread *thread) { - thread.shouldThreadBeVisible = NO; - }]; -} - #pragma mark - Avatar - (void)updateAvatarWithAttachmentStream:(TSAttachmentStream *)attachmentStream From 4dbb7d0590a6256bae87288355666c895ae0a305 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Thu, 12 Sep 2019 11:37:53 -0700 Subject: [PATCH 2/2] remove deleted contact threads from search results --- SignalMessaging/utils/FullTextSearcher.swift | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/SignalMessaging/utils/FullTextSearcher.swift b/SignalMessaging/utils/FullTextSearcher.swift index 00a5b24e33..53f5b1dce7 100644 --- a/SignalMessaging/utils/FullTextSearcher.swift +++ b/SignalMessaging/utils/FullTextSearcher.swift @@ -290,12 +290,17 @@ public class FullTextSearcher: NSObject { let sortKey = ConversationSortKey(creationDate: thread.creationDate, lastMessageReceivedAtDate: thread.lastInteractionForInbox(transaction: transaction)?.receivedAtDate()) let searchResult = ConversationSearchResult(thread: threadViewModel, sortKey: sortKey) - - if let contactThread = thread as? TSContactThread { - existingConversationAddresses.insert(contactThread.contactAddress) + switch thread { + case is TSGroupThread: + conversations.append(searchResult) + case let contactThread as TSContactThread: + if contactThread.shouldThreadBeVisible { + existingConversationAddresses.insert(contactThread.contactAddress) + conversations.append(searchResult) + } + default: + owsFailDebug("unexpected thread: \(type(of: thread))") } - - conversations.append(searchResult) } else if let message = match as? TSMessage { let thread = message.thread(transaction: transaction)