From 5eb443e1ff376e0989a32c977f5d8370420d430b Mon Sep 17 00:00:00 2001 From: Alejandro Romero Herrera Date: Fri, 28 Aug 2020 01:08:25 +0300 Subject: [PATCH] Fixes #1008 There was a mistake in 252df324af4ff4fb40ccbc119f6084887f9cbb4b, firebase syntax was used instead of firestore. Avoid notification when user edits pin or howto and it was previuosly accepted. Notification will be triggered if user reverts to draft and then try to publish after being accepted. Note: will trigger disscord message, maybe we could add field in DB to know it has been accepted before.... Would it brake frontend?? --- functions/src/Integrations/firebase-slack.ts | 28 +++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/functions/src/Integrations/firebase-slack.ts b/functions/src/Integrations/firebase-slack.ts index 41d736c649..97489ff29a 100644 --- a/functions/src/Integrations/firebase-slack.ts +++ b/functions/src/Integrations/firebase-slack.ts @@ -13,11 +13,16 @@ export const notifyNewPin = functions.firestore const info = change.after.exists ? change.after.data() : null const prevInfo = change.before.exists ? change.before.data() : null const prevModeration = (prevInfo !== null) ? prevInfo.moderation : null; - if (info === null || info.moderation !== 'awaiting-moderation' || prevModeration === 'awaiting-moderation') { - return + if (prevModeration === info.moderation){ // Avoid infinite loop + return null + } + if (prevModeration === 'accepted' && info.moderation === 'awaiting-moderation'){ // If edited after being accepted keep it accepted and avoid message #1008 + return change.after.ref.set({ + moderation: 'accepted' + }, {merge: true}); } - if (prevModeration === 'accepted' && info.moderation !== 'awaiting-moderation'){ // If edited after being accepted keep it accepted and avoid message #1008 - return change.after.ref.parent.child('moderation').set('accepted'); + if (info === null || info.moderation !== 'awaiting-moderation' || prevModeration === 'awaiting-moderation') { + return null } const id = info._id @@ -47,11 +52,16 @@ export const notifyNewHowTo = functions.firestore const info = change.after.exists ? change.after.data() : null const prevInfo = change.before.exists ? change.before.data() : null const prevModeration = (prevInfo !== null) ? prevInfo.moderation : null; - if (info === null || info.moderation !== 'awaiting-moderation') { - return + if (prevModeration === info.moderation){ // Avoid infinite loop + return null + } + if (prevModeration === 'accepted' && info.moderation === 'awaiting-moderation'){ // If edited after being accepted keep it accepted and avoid message #1008 + return change.after.ref.set({ + moderation: 'accepted' + }, {merge: true}); } - if (prevModeration === 'accepted' && info.moderation !== 'awaiting-moderation'){ // If edited after being accepted keep it accepted and avoid message #1008 - return change.after.ref.parent.child('moderation').set('accepted'); + if (info === null || info.moderation !== 'awaiting-moderation') { + return null } const user = info._createdBy @@ -81,7 +91,7 @@ export const notifyNewEvent = functions.firestore .onWrite((change, context) => { const info = change.after.exists ? change.after.data() : null if (info === null || info.moderation !== 'awaiting-moderation') { - return + return null } const user = info._createdBy