Skip to content

Commit

Permalink
Merge pull request #1020 from ONEARMY/alrhomh87-1008
Browse files Browse the repository at this point in the history
avoid-notif-on-user-edit-1008
  • Loading branch information
BenGamma authored Aug 25, 2020
2 parents 4d75866 + aa5529a commit 953ece8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion functions/src/Integrations/firebase-discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ export const notifyHowToAccepted = functions.firestore
.document('v3_howtos/{id}')
.onWrite(async (change, context) => {
const info = change.after.exists ? change.after.data() : null
if (info === null || info.moderation !== 'accepted') {
const prevInfo = change.before.exists ? change.before.data() : null
const beenAccepted =
prevInfo !== null ? prevInfo.moderation === 'accepted' : null
if (info === null || info.moderation !== 'accepted' || beenAccepted) {
return
}
const { _createdBy, title, slug } = info
Expand Down
8 changes: 8 additions & 0 deletions functions/src/Integrations/firebase-slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export const notifyNewPin = functions.firestore
if (info === null || info.moderation !== 'awaiting-moderation' || prevModeration === 'awaiting-moderation') {
return
}
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');
}

const id = info._id
const type = info.type
Expand All @@ -42,9 +45,14 @@ export const notifyNewHowTo = functions.firestore
.document('v3_howtos/{id}')
.onWrite((change, context) => {
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 === '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');
}

const user = info._createdBy
const title = info.title
Expand Down

0 comments on commit 953ece8

Please sign in to comment.