Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid-notif-on-user-edit-1008 #1020

Merged
merged 2 commits into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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