Soft delete group threads

This commit is contained in:
Michael Kirk 2018-12-11 15:07:50 -07:00
parent c0cb7df10a
commit beb02afce9
4 changed files with 28 additions and 4 deletions

View File

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

View File

@ -31,6 +31,8 @@ extern NSString *const TSGroupThread_NotificationKey_UniqueId;
+ (NSString *)defaultGroupName;
- (BOOL)isLocalUserInGroup;
// all group threads containing recipient as a member
+ (NSArray<TSGroupThread *> *)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;

View File

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

View File

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