feat: delete message id when title no longer airing

This commit is contained in:
2024-09-19 15:31:14 -04:00
parent 027e8eaac5
commit 1ce79ed17a
4 changed files with 34 additions and 11 deletions

View File

@@ -2,6 +2,7 @@ import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
import { Client } from "@upstash/qstash";
import { env } from "hono/adapter";
import { deleteMessageIdForTitle } from "~/libs/deleteMessageIdForTitle";
import { maybeScheduleNextAiringEpisode } from "~/libs/maybeScheduleNextAiringEpisode";
import { verifyQstashHeader } from "~/libs/qstash/verifyQstashHeader";
import { readEnvVariable } from "~/libs/readEnvVariable";
@@ -95,20 +96,10 @@ app.openapi(route, async (c) => {
titleId,
);
} else if (wasDeleted) {
const messageId = await getTitleMessage(
await deleteMessageIdForTitle(
env<Env, typeof c>(c, "workerd"),
titleId,
);
if (messageId) {
try {
await client.messages.delete(messageId);
} catch (error) {
if (!error.message.contains("not found")) {
throw error;
}
}
await deleteTitleMessage(env<Env, typeof c>(c, "workerd"), titleId);
}
}
} catch (error) {
console.error(new Error("Error setting watch status", { cause: error }));