From 63e469f351b7e09cd8e6285d2757d54679035fd6 Mon Sep 17 00:00:00 2001 From: Michael Piazza Date: Mon, 11 Jul 2022 16:13:14 -0700 Subject: [PATCH 1/4] Fix reaction parsing --- identity-service/src/routes/reactions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/identity-service/src/routes/reactions.js b/identity-service/src/routes/reactions.js index c77a7a7f3ed..15f2b8c3745 100644 --- a/identity-service/src/routes/reactions.js +++ b/identity-service/src/routes/reactions.js @@ -44,7 +44,7 @@ module.exports = function (app) { if (!senderWallet || !reactedTo || reactionValue === undefined) return errorResponseBadRequest(`Missing argument: ${JSON.stringify({ senderWallet, reactedTo, reactionValue })}`) const parsedReaction = parseInt(reactionValue) - if (!parsedReaction) return errorResponseBadRequest('Invalid reaction type') + if (parsedReaction === undefined) return errorResponseBadRequest('Invalid reaction type') const libs = req.app.get('audiusLibs') From 4f73250cb74552047305401d826b14823bf4d28b Mon Sep 17 00:00:00 2001 From: Michael Piazza Date: Tue, 12 Jul 2022 14:03:01 -0700 Subject: [PATCH 2/4] Unsend notif --- .../reactionNotification.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/identity-service/src/notifications/processNotifications/reactionNotification.js b/identity-service/src/notifications/processNotifications/reactionNotification.js index 8cf03c40104..0cd270e19d9 100644 --- a/identity-service/src/notifications/processNotifications/reactionNotification.js +++ b/identity-service/src/notifications/processNotifications/reactionNotification.js @@ -24,14 +24,19 @@ async function processReactionNotifications (notifications, tx) { }) // In the case that the notification already exists, avoid returning it to prevent - // sending it a second time. Just update the original reaction value. + // sending it a second time. Just update or delete the original reaction value. if (existingNotification) { - // Have to recreate the metadata object for save to work properly - existingNotification.metadata = { - ...existingNotification.metadata, - reactionValue + if (parseInt(reactionValue) === 0) { + // Destroy reaction if undoing reaction value + await existingNotification.destroy({ transaction: tx }) + } else { + // Have to recreate the metadata object for save to work properly + existingNotification.metadata = { + ...existingNotification.metadata, + reactionValue + } + await existingNotification.save({ transaction: tx }) } - await existingNotification.save({ transaction: tx }) } else { notifsToReturn.push(notification) await models.SolanaNotification.create({ From b3866c8e77ecb926121b65c217c65e9eb2a272d5 Mon Sep 17 00:00:00 2001 From: Michael Piazza Date: Tue, 12 Jul 2022 14:40:39 -0700 Subject: [PATCH 3/4] Fix NaN --- identity-service/src/routes/reactions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/identity-service/src/routes/reactions.js b/identity-service/src/routes/reactions.js index 15f2b8c3745..8960b7233f1 100644 --- a/identity-service/src/routes/reactions.js +++ b/identity-service/src/routes/reactions.js @@ -44,7 +44,7 @@ module.exports = function (app) { if (!senderWallet || !reactedTo || reactionValue === undefined) return errorResponseBadRequest(`Missing argument: ${JSON.stringify({ senderWallet, reactedTo, reactionValue })}`) const parsedReaction = parseInt(reactionValue) - if (parsedReaction === undefined) return errorResponseBadRequest('Invalid reaction type') + if (parsedReaction === NaN) return errorResponseBadRequest('Invalid reaction type') const libs = req.app.get('audiusLibs') From a09278d7b1d17e9fa5e03e82bbe8f1b4c8585a9f Mon Sep 17 00:00:00 2001 From: Michael Piazza Date: Tue, 12 Jul 2022 15:45:50 -0700 Subject: [PATCH 4/4] Use isNaN --- identity-service/src/routes/reactions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/identity-service/src/routes/reactions.js b/identity-service/src/routes/reactions.js index 8960b7233f1..4f499c05b39 100644 --- a/identity-service/src/routes/reactions.js +++ b/identity-service/src/routes/reactions.js @@ -44,7 +44,7 @@ module.exports = function (app) { if (!senderWallet || !reactedTo || reactionValue === undefined) return errorResponseBadRequest(`Missing argument: ${JSON.stringify({ senderWallet, reactedTo, reactionValue })}`) const parsedReaction = parseInt(reactionValue) - if (parsedReaction === NaN) return errorResponseBadRequest('Invalid reaction type') + if (isNaN(parsedReaction)) return errorResponseBadRequest('Invalid reaction type') const libs = req.app.get('audiusLibs')