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 notification when user edits pin or howto and it was previuosly accepted. #1008 #1021

Merged
merged 2 commits into from
Sep 9, 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
12 changes: 9 additions & 3 deletions functions/src/Integrations/firebase-discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export const notifyPinAccepted = functions.firestore
const beenAccepted =
prevInfo !== null ? prevInfo.moderation === 'accepted' : null
if (info === null || info.moderation !== 'accepted' || beenAccepted) {
return
return null
}
if (info.previouslyAccepted) { // Skip after edition of previously accepted
return null
}
const { _id, type } = info
await axios
Expand All @@ -34,7 +37,10 @@ export const notifyHowToAccepted = functions.firestore
const beenAccepted =
prevInfo !== null ? prevInfo.moderation === 'accepted' : null
if (info === null || info.moderation !== 'accepted' || beenAccepted) {
return
return null
}
if (info.previouslyAccepted) { // Skip after edition of previously accepted
return null
}
const { _createdBy, title, slug } = info
await axios
Expand All @@ -51,7 +57,7 @@ export const notifyEventAccepted = functions.firestore
.onWrite(async (change, context) => {
const info = change.after.exists ? change.after.data() : null
if (info === null || info.moderation !== 'accepted') {
return
return null
}
const user = info._createdBy
const url = info.url
Expand Down
30 changes: 21 additions & 9 deletions functions/src/Integrations/firebase-slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ 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({
previouslyAccepted: true,
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 +53,17 @@ 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({
previouslyAccepted: true,
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 +93,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