From 61dcfeb69ff131b1db9a252dddf69c7d2509eae8 Mon Sep 17 00:00:00 2001 From: mini-bomba <55105495+mini-bomba@users.noreply.github.com> Date: Sat, 3 Aug 2024 21:10:06 +0200 Subject: [PATCH] Don't send to #dearrow-locked-titles when downvoting unlocked title voteType passed to sendWebhooks() function to avoid confusion in the future should someone forget about the if statement --- src/routes/postBranding.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/routes/postBranding.ts b/src/routes/postBranding.ts index 33128e7..7fa2e6b 100644 --- a/src/routes/postBranding.ts +++ b/src/routes/postBranding.ts @@ -113,7 +113,7 @@ export async function postBranding(req: Request, res: Response) { await db.prepare("run", `UPDATE "titleVotes" as tv SET "locked" = 0 FROM "titles" t WHERE tv."UUID" = t."UUID" AND tv."UUID" != ? AND t."videoID" = ?`, [UUID, videoID]); } - sendWebhooks(videoID, UUID).catch((e) => Logger.error(e)); + sendWebhooks(videoID, UUID, voteType).catch((e) => Logger.error(e)); } })(), (async () => { if (thumbnail) { @@ -290,7 +290,9 @@ export async function verifyOldSubmissions(hashedUserID: HashedUserID, verificat } } -async function sendWebhooks(videoID: VideoID, UUID: BrandingUUID) { +async function sendWebhooks(videoID: VideoID, UUID: BrandingUUID, voteType: BrandingVoteType) { + if (voteType === BrandingVoteType.Downvote) return; // Don't send messages to dearrow-locked-titles on downvotes + const lockedSubmission = await db.prepare("get", `SELECT "titleVotes"."votes", "titles"."title", "titles"."userID" FROM "titles" JOIN "titleVotes" ON "titles"."UUID" = "titleVotes"."UUID" WHERE "titles"."videoID" = ? AND "titles"."UUID" != ? AND "titleVotes"."locked" = 1`, [videoID, UUID]); if (lockedSubmission) { @@ -336,4 +338,4 @@ async function checkForWrongVideoDuration(videoID: VideoID, duration: number): P const apiDuration = apiVideoDetails?.duration; return apiDuration && apiDuration > 2 && duration && duration > 2 && Math.abs(apiDuration - duration) > 3; -} \ No newline at end of file +}