Merge branch 'mkirk/group-soft-delete'

pull/1/head
Michael Kirk 6 years ago
commit 1bc81ad76e

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

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

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

@ -83,6 +83,15 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa
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) {

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

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

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

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

Loading…
Cancel
Save