tweak: refactor reaction deletion

pull/680/head
ryanzhao 3 years ago
parent 82e55a8d5b
commit 6a8b14b8d2

@ -1139,7 +1139,11 @@ extension ConversationVC:
// Update the database // Update the database
if remove { if remove {
try pendingReaction?.delete(db) try Reaction
.filter(Reaction.Columns.interactionId == cellViewModel.id)
.filter(Reaction.Columns.authorId == cellViewModel.currentUserPublicKey)
.filter(Reaction.Columns.emoji == emoji)
.deleteAll(db)
} }
else { else {
try pendingReaction?.insert(db) try pendingReaction?.insert(db)
@ -1186,12 +1190,12 @@ extension ConversationVC:
} }
.catch { [weak self] _ in .catch { [weak self] _ in
OpenGroupManager.removePendingChange(pendingChange) OpenGroupManager.removePendingChange(pendingChange)
self?.handleReactionSentFailure( self?.handleReactionSentFailure(
pendingReaction, pendingReaction,
remove: remove remove: remove
) )
} }
.retainUntilComplete() .retainUntilComplete()
} else { } else {
@ -1258,13 +1262,18 @@ extension ConversationVC:
} }
func handleReactionSentFailure(_ pendingReaction: Reaction?, remove: Bool) { func handleReactionSentFailure(_ pendingReaction: Reaction?, remove: Bool) {
guard let pendingReaction = pendingReaction else { return }
Storage.shared.writeAsync { db in Storage.shared.writeAsync { db in
// Reverse the database // Reverse the database
if remove { if remove {
try pendingReaction?.insert(db) try pendingReaction.insert(db)
} }
else { else {
try pendingReaction?.delete(db) try Reaction
.filter(Reaction.Columns.interactionId == pendingReaction.interactionId)
.filter(Reaction.Columns.authorId == pendingReaction.authorId)
.filter(Reaction.Columns.emoji == pendingReaction.emoji)
.deleteAll(db)
} }
} }
} }

Loading…
Cancel
Save