mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Fix public chat deletion
This commit is contained in:
parent
f70b914d3e
commit
3769f50a21
4 changed files with 25 additions and 5 deletions
|
@ -1602,12 +1602,12 @@ static NSTimeInterval launchStartedAt;
|
|||
|
||||
- (LKRSSFeed *)lokiNewsFeed
|
||||
{
|
||||
return [[LKRSSFeed alloc] initWithId:@"loki.network.feed" server:@"https://loki.network/feed/" displayName:NSLocalizedString(@"Loki News", @"") isDeletable:true];
|
||||
return [[LKRSSFeed alloc] initWithId:@"loki.network.feed" server:@"https://loki.network/feed/" displayName:@"Loki News" isDeletable:true];
|
||||
}
|
||||
|
||||
- (LKRSSFeed *)lokiMessengerUpdatesFeed
|
||||
{
|
||||
return [[LKRSSFeed alloc] initWithId:@"loki.network.messenger-updates.feed" server:@"https://loki.network/category/messenger-updates/feed/" displayName:NSLocalizedString(@"Loki Messenger Updates", @"") isDeletable:false];
|
||||
return [[LKRSSFeed alloc] initWithId:@"loki.network.messenger-updates.feed" server:@"https://loki.network/category/messenger-updates/feed/" displayName:@"Loki Messenger Updates" isDeletable:false];
|
||||
}
|
||||
|
||||
- (void)setUpDefaultPublicChatsIfNeeded
|
||||
|
|
|
@ -323,12 +323,20 @@ final class HomeVC : UIViewController, UITableViewDataSource, UITableViewDelegat
|
|||
alert.addAction(UIAlertAction(title: NSLocalizedString("TXT_DELETE_TITLE", comment: ""), style: .destructive) { _ in
|
||||
guard let self = self else { return }
|
||||
self.editingDatabaseConnection.readWrite { transaction in
|
||||
if let publicChat = publicChat {
|
||||
var messageIDs: Set<String> = []
|
||||
thread.enumerateInteractions(with: transaction) { interaction, _ in
|
||||
messageIDs.insert(interaction.uniqueId!)
|
||||
}
|
||||
OWSPrimaryStorage.shared().updateMessageIDCollectionByPruningMessagesWithIDs(messageIDs, in: transaction)
|
||||
transaction.removeObject(forKey: "\(publicChat.server).\(publicChat.channel)", inCollection: LokiPublicChatAPI.lastMessageServerIDCollection)
|
||||
transaction.removeObject(forKey: "\(publicChat.server).\(publicChat.channel)", inCollection: LokiPublicChatAPI.lastDeletionServerIDCollection)
|
||||
let _ = LokiPublicChatAPI.leave(publicChat.channel, on: publicChat.server)
|
||||
}
|
||||
thread.removeAllThreadInteractions(with: transaction)
|
||||
thread.remove(with: transaction)
|
||||
}
|
||||
NotificationCenter.default.post(name: .threadDeleted, object: nil, userInfo: [ "threadId" : thread.uniqueId! ])
|
||||
if let publicChat = publicChat {
|
||||
let _ = LokiPublicChatAPI.leave(publicChat.channel, on: publicChat.server)
|
||||
}
|
||||
})
|
||||
alert.addAction(UIAlertAction(title: NSLocalizedString("TXT_CANCEL_TITLE", comment: ""), style: .default) { _ in })
|
||||
guard let self = self else { return }
|
||||
|
|
|
@ -35,6 +35,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
- (void)setIDForMessageWithServerID:(NSUInteger)serverID to:(NSString *)messageID in:(YapDatabaseReadWriteTransaction *)transaction;
|
||||
- (NSString *_Nullable)getIDForMessageWithServerID:(NSUInteger)serverID in:(YapDatabaseReadTransaction *)transaction;
|
||||
- (void)updateMessageIDCollectionByPruningMessagesWithIDs:(NSSet<NSString *> *)targetMessageIDs in:(YapDatabaseReadWriteTransaction *)transaction NS_SWIFT_NAME(updateMessageIDCollectionByPruningMessagesWithIDs(_:in:));
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -175,4 +175,15 @@
|
|||
return [transaction objectForKey:key inCollection:LKMessageIDCollection];
|
||||
}
|
||||
|
||||
- (void)updateMessageIDCollectionByPruningMessagesWithIDs:(NSSet<NSString *> *)targetMessageIDs in:(YapDatabaseReadWriteTransaction *)transaction {
|
||||
NSMutableArray<NSString *> *serverIDs = [NSMutableArray new];
|
||||
[transaction enumerateRowsInCollection:LKMessageIDCollection usingBlock:^(NSString *key, id object, id metadata, BOOL *stop) {
|
||||
if (![object isKindOfClass:NSString.class]) { return; }
|
||||
NSString *messageID = (NSString *)object;
|
||||
if (![targetMessageIDs containsObject:messageID]) { return; }
|
||||
[serverIDs addObject:key];
|
||||
}];
|
||||
[transaction removeObjectsForKeys:serverIDs inCollection:LKMessageIDCollection];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue