Skip to content

Commit

Permalink
Fixes ONEARMY#1008
Browse files Browse the repository at this point in the history
There was a mistake in 252df32, 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??
  • Loading branch information
alromh87 committed Aug 27, 2020
1 parent 1a20e43 commit 5eb443e
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions functions/src/Integrations/firebase-slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5eb443e

Please sign in to comment.