diff --git a/functions/src/definitions/eventHandlers/onMessageUpdate.ts b/functions/src/definitions/eventHandlers/onMessageUpdate.ts index 2a98040..ee5d10d 100644 --- a/functions/src/definitions/eventHandlers/onMessageUpdate.ts +++ b/functions/src/definitions/eventHandlers/onMessageUpdate.ts @@ -9,8 +9,6 @@ import { onDocumentUpdated } from "firebase-functions/v2/firestore" import { tabulateVoteStats } from "../common/statistics" import { logger } from "firebase-functions" -const ADMIN_CHAT_ID = String(process.env.ADMIN_CHAT_ID) - const onMessageUpdateV2 = onDocumentUpdated( { document: "messages/{messageId}", @@ -35,7 +33,6 @@ const onMessageUpdateV2 = onDocumentUpdated( // If changes from not assessed to assessed if (!preChangeSnap.data().isAssessed && messageData.isAssessed) { - await postChangeSnap.ref.update({ assessedTimestamp: Timestamp.fromDate(new Date()), }) diff --git a/functions/src/definitions/eventHandlers/onMessageWrite.ts b/functions/src/definitions/eventHandlers/onMessageWrite.ts index 64ef456..53a8fe0 100644 --- a/functions/src/definitions/eventHandlers/onMessageWrite.ts +++ b/functions/src/definitions/eventHandlers/onMessageWrite.ts @@ -33,7 +33,7 @@ const adminMessageHandler = onDocumentWritten( ) const machineCategory = docSnap.get("machineCategory") const isMachineCategorised = docSnap.get("isMachineCategorised") - if (isMachineCategorised) { + if (isMachineCategorised && machineCategory !== null) { await sendVotingUpdate({ messageId: docSnap.get("adminGroupSentMessageId"), machineCategory: machineCategory, @@ -51,11 +51,7 @@ const adminMessageHandler = onDocumentWritten( const communityNoteAfter = docSnap.get("communityNote") ?? null const primaryCategoryBefore = before.get("primaryCategory") ?? null const primaryCategoryAfter = docSnap.get("primaryCategory") ?? null - - if ( - communityNoteBefore === null && - communityNoteAfter !== null - ) { + if (communityNoteBefore === null && communityNoteAfter !== null) { //if community note was newly generated await sendCommunityNoteNotification( docSnap.get("communityNote"), @@ -63,7 +59,7 @@ const adminMessageHandler = onDocumentWritten( docSnap.ref ) } - if (isAssessedBefore === null && isAssessedAfter) { + if (!isAssessedBefore && isAssessedAfter) { //if message was newly assessed await sendVotingUpdate({ messageId: docSnap.get("adminGroupSentMessageId"), @@ -81,7 +77,12 @@ const adminMessageHandler = onDocumentWritten( currentCategory: primaryCategoryAfter, }) } - if (!communityNoteBefore.downvoted && communityNoteAfter.downvoted) { + if ( + communityNoteBefore !== null && + communityNoteAfter !== null && + !communityNoteBefore.downvoted && + communityNoteAfter.downvoted + ) { //if community note got downvoted await sendVotingUpdate({ messageId: docSnap.get( diff --git a/functions/src/services/admin/notificationService.ts b/functions/src/services/admin/notificationService.ts index ae6aa24..85e5dde 100644 --- a/functions/src/services/admin/notificationService.ts +++ b/functions/src/services/admin/notificationService.ts @@ -83,7 +83,7 @@ export async function sendCommunityNoteNotification( replyId ?? topicId ) const messageId = response?.data.result.message_id - if (messageId) { + if (messageId && communityNote !== null) { await messageRef.update({ "communityNote.adminGroupCommunityNoteSentMessageId": messageId, })