|
|
@ -2121,6 +2121,7 @@ extension ConversationVC:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Delete the message from the open group
|
|
|
|
// Delete the message from the open group
|
|
|
|
|
|
|
|
self.hideInputAccessoryView()
|
|
|
|
deleteRemotely(
|
|
|
|
deleteRemotely(
|
|
|
|
from: self,
|
|
|
|
from: self,
|
|
|
|
request: Storage.shared
|
|
|
|
request: Storage.shared
|
|
|
@ -2145,13 +2146,14 @@ extension ConversationVC:
|
|
|
|
userPublicKey :
|
|
|
|
userPublicKey :
|
|
|
|
cellViewModel.threadId
|
|
|
|
cellViewModel.threadId
|
|
|
|
)
|
|
|
|
)
|
|
|
|
let serverHash: String? = Storage.shared.read { db -> String? in
|
|
|
|
let serverHashes: Set<String> = Storage.shared
|
|
|
|
try Interaction
|
|
|
|
.read { db -> Set<String> in
|
|
|
|
.select(.serverHash)
|
|
|
|
try Interaction.serverHashesForDeletion(
|
|
|
|
.filter(id: cellViewModel.id)
|
|
|
|
db,
|
|
|
|
.asRequest(of: String.self)
|
|
|
|
interactionIds: [cellViewModel.id]
|
|
|
|
.fetchOne(db)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.defaulting(to: [])
|
|
|
|
let unsendRequest: UnsendRequest = UnsendRequest(
|
|
|
|
let unsendRequest: UnsendRequest = UnsendRequest(
|
|
|
|
timestamp: UInt64(cellViewModel.timestampMs),
|
|
|
|
timestamp: UInt64(cellViewModel.timestampMs),
|
|
|
|
author: (cellViewModel.variant == .standardOutgoing ?
|
|
|
|
author: (cellViewModel.variant == .standardOutgoing ?
|
|
|
@ -2165,7 +2167,7 @@ extension ConversationVC:
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// For incoming interactions or interactions with no serverHash just delete them locally
|
|
|
|
// For incoming interactions or interactions with no serverHash just delete them locally
|
|
|
|
guard cellViewModel.variant == .standardOutgoing, let serverHash: String = serverHash else {
|
|
|
|
guard cellViewModel.variant == .standardOutgoing, !serverHashes.isEmpty else {
|
|
|
|
Storage.shared.writeAsync { db in
|
|
|
|
Storage.shared.writeAsync { db in
|
|
|
|
_ = try Interaction
|
|
|
|
_ = try Interaction
|
|
|
|
.filter(id: cellViewModel.id)
|
|
|
|
.filter(id: cellViewModel.id)
|
|
|
@ -2173,7 +2175,7 @@ extension ConversationVC:
|
|
|
|
|
|
|
|
|
|
|
|
// No need to send the unsendRequest if there is no serverHash (ie. the message
|
|
|
|
// No need to send the unsendRequest if there is no serverHash (ie. the message
|
|
|
|
// was outgoing but never got to the server)
|
|
|
|
// was outgoing but never got to the server)
|
|
|
|
guard serverHash != nil else { return }
|
|
|
|
guard !serverHashes.isEmpty else { return }
|
|
|
|
|
|
|
|
|
|
|
|
MessageSender
|
|
|
|
MessageSender
|
|
|
|
.send(
|
|
|
|
.send(
|
|
|
@ -2221,7 +2223,6 @@ extension ConversationVC:
|
|
|
|
actionSheet.addAction(UIAlertAction(
|
|
|
|
actionSheet.addAction(UIAlertAction(
|
|
|
|
title: {
|
|
|
|
title: {
|
|
|
|
switch (cellViewModel.threadVariant, cellViewModel.threadId) {
|
|
|
|
switch (cellViewModel.threadVariant, cellViewModel.threadId) {
|
|
|
|
case (.legacyGroup, _), (.group, _): return "clearMessagesForEveryone".localized()
|
|
|
|
|
|
|
|
case (_, userPublicKey): return "deleteMessageDevicesAll".localized()
|
|
|
|
case (_, userPublicKey): return "deleteMessageDevicesAll".localized()
|
|
|
|
default: return "deleteMessageEveryone".localized()
|
|
|
|
default: return "deleteMessageEveryone".localized()
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -2231,6 +2232,10 @@ extension ConversationVC:
|
|
|
|
) { [weak self] _ in
|
|
|
|
) { [weak self] _ in
|
|
|
|
let completeServerDeletion = {
|
|
|
|
let completeServerDeletion = {
|
|
|
|
Storage.shared.writeAsync { db in
|
|
|
|
Storage.shared.writeAsync { db in
|
|
|
|
|
|
|
|
_ = try Interaction
|
|
|
|
|
|
|
|
.filter(id: cellViewModel.id)
|
|
|
|
|
|
|
|
.deleteAll(db)
|
|
|
|
|
|
|
|
|
|
|
|
try MessageSender
|
|
|
|
try MessageSender
|
|
|
|
.send(
|
|
|
|
.send(
|
|
|
|
db,
|
|
|
|
db,
|
|
|
@ -2240,7 +2245,15 @@ extension ConversationVC:
|
|
|
|
threadVariant: cellViewModel.threadVariant,
|
|
|
|
threadVariant: cellViewModel.threadVariant,
|
|
|
|
using: dependencies
|
|
|
|
using: dependencies
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// We should also remove the `SnodeReceivedMessageInfo` entries for the hashes (otherwise we
|
|
|
|
|
|
|
|
/// might try to poll for a hash which no longer exists, resulting in fetching the last 14 days of messages)
|
|
|
|
|
|
|
|
try SnodeReceivedMessageInfo.handlePotentialDeletedOrInvalidHash(
|
|
|
|
|
|
|
|
db,
|
|
|
|
|
|
|
|
potentiallyInvalidHashes: Array(serverHashes)
|
|
|
|
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self?.showInputAccessoryView()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// We can only delete messages on the server for `contact` and `group` conversations
|
|
|
|
// We can only delete messages on the server for `contact` and `group` conversations
|
|
|
@ -2253,7 +2266,7 @@ extension ConversationVC:
|
|
|
|
request: SnodeAPI
|
|
|
|
request: SnodeAPI
|
|
|
|
.deleteMessages(
|
|
|
|
.deleteMessages(
|
|
|
|
swarmPublicKey: targetPublicKey,
|
|
|
|
swarmPublicKey: targetPublicKey,
|
|
|
|
serverHashes: [serverHash]
|
|
|
|
serverHashes: Array(serverHashes)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.map { _ in () }
|
|
|
|
.map { _ in () }
|
|
|
|
.eraseToAnyPublisher()
|
|
|
|
.eraseToAnyPublisher()
|
|
|
|