minor refactor

pull/484/head
ryanzhao 4 years ago
parent 31cf0b7b20
commit 2e8e931551

@ -226,20 +226,24 @@ extension MessageReceiver {
guard message.sender == message.author else { return } guard message.sender == message.author else { return }
let userPublicKey = getUserHexEncodedPublicKey() let userPublicKey = getUserHexEncodedPublicKey()
let transaction = transaction as! YapDatabaseReadWriteTransaction let transaction = transaction as! YapDatabaseReadWriteTransaction
if let author = message.author, let timestamp = message.timestamp, if let author = message.author, let timestamp = message.timestamp {
let messageToDelete = userPublicKey == message.sender ? TSOutgoingMessage.find(withTimestamp: timestamp) : TSIncomingMessage.find(withAuthorId: author, timestamp: timestamp, transaction: transaction) { let localMessage: TSMessage?
if let incomingMessage = messageToDelete as? TSIncomingMessage { if userPublicKey == message.sender { localMessage = TSOutgoingMessage.find(withTimestamp: timestamp) }
incomingMessage.markAsReadNow(withSendReadReceipt: false, transaction: transaction) else { localMessage = TSIncomingMessage.find(withAuthorId: author, timestamp: timestamp, transaction: transaction) }
if let notificationIdentifier = incomingMessage.notificationIdentifier, !notificationIdentifier.isEmpty {
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [notificationIdentifier]) if let messageToDelete = localMessage {
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [notificationIdentifier]) if let incomingMessage = messageToDelete as? TSIncomingMessage {
incomingMessage.markAsReadNow(withSendReadReceipt: false, transaction: transaction)
if let notificationIdentifier = incomingMessage.notificationIdentifier, !notificationIdentifier.isEmpty {
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [notificationIdentifier])
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [notificationIdentifier])
}
} }
if let serverHash = messageToDelete.serverHash {
SnodeAPI.deleteMessage(publicKey: author, serverHashes: [serverHash]).retainUntilComplete()
}
messageToDelete.updateForDeletion(with: transaction)
} }
if let serverHash = messageToDelete.serverHash {
SnodeAPI.deleteMessage(publicKey: author, serverHashes: [serverHash]).retainUntilComplete()
}
messageToDelete.updateForDeletion(with: transaction)
} }
} }

Loading…
Cancel
Save