diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index 33dfce0fb..0d272ee29 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -1075,6 +1075,13 @@ extension ConversationVC: .done { _ in // Delete the interaction (and associated data) from the database Storage.shared.writeAsync { db in + try Quote + .updateBeforeQuotedInterationDeletion( + db, + timestampMs: cellViewModel.timestampMs, + authorId: cellViewModel.authorId + ) + _ = try Interaction .filter(id: cellViewModel.id) .deleteAll(db) @@ -1155,6 +1162,13 @@ extension ConversationVC: // For incoming interactions or interactions with no serverHash just delete them locally guard cellViewModel.variant == .standardOutgoing, let serverHash: String = serverHash else { Storage.shared.writeAsync { db in + try Quote + .updateBeforeQuotedInterationDeletion( + db, + timestampMs: cellViewModel.timestampMs, + authorId: cellViewModel.authorId + ) + _ = try Interaction .filter(id: cellViewModel.id) .deleteAll(db) @@ -1178,6 +1192,13 @@ extension ConversationVC: let alertVC = UIAlertController.init(title: nil, message: nil, preferredStyle: .actionSheet) alertVC.addAction(UIAlertAction(title: "delete_message_for_me".localized(), style: .destructive) { [weak self] _ in Storage.shared.writeAsync { db in + try Quote + .updateBeforeQuotedInterationDeletion( + db, + timestampMs: cellViewModel.timestampMs, + authorId: cellViewModel.authorId + ) + _ = try Interaction .filter(id: cellViewModel.id) .deleteAll(db) diff --git a/SessionMessagingKit/Database/Models/Quote.swift b/SessionMessagingKit/Database/Models/Quote.swift index 2e7a3ce83..b6ba5b39f 100644 --- a/SessionMessagingKit/Database/Models/Quote.swift +++ b/SessionMessagingKit/Database/Models/Quote.swift @@ -76,6 +76,21 @@ public struct Quote: Codable, Equatable, Hashable, FetchableRecord, PersistableR } } +public extension Quote { + /// This method updates the all Quotes before the quoted interation is deleted + /// + static func updateBeforeQuotedInterationDeletion(_ db: Database, timestampMs: Int64, authorId: String) throws { + try Quote + .filter(Columns.authorId == authorId) + .filter(Columns.timestampMs == timestampMs) + .updateAll( + db, + Columns.body.set(to: "QUOTED_MESSAGE_NOT_FOUND".localized()), + Columns.attachmentId.set(to: nil) + ) + } +} + // MARK: - Protobuf public extension Quote {