Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(api): handle anon_view type in notifications endpoint
Richie McIlroyb1d7d195c048
diff --git a/apps/web/app/api/notifications/route.ts b/apps/web/app/api/notifications/route.tsindex 5fecdf2bd..6c101cb02 100644--- a/apps/web/app/api/notifications/route.ts+++ b/apps/web/app/api/notifications/route.ts@@ -6,22 +6,9 @@ import { ImageUploads } from "@cap/web-backend";import { and, desc, eq, isNull, sql } from "drizzle-orm";import { Effect } from "effect";import { NextResponse } from "next/server";-import { z } from "zod";-import type { NotificationType } from "@/lib/Notification";import { runPromise } from "@/lib/server";import { jsonExtractString } from "@/utils/sql";-const _notificationDataSchema = z.object({- authorId: z.string(),- content: z.string().optional(),- videoId: z.string(),-});--type NotificationsKeys = (typeof notifications.$inferSelect)["type"];-type NotificationsKeysWithReplies =- | Exclude<`${NotificationsKeys}s`, "replys">- | "replies";-export const dynamic = "force-dynamic";export async function GET() {@@ -78,18 +65,22 @@ export async function GET() {).groupBy(notifications.type);- const formattedCountResults: Record<NotificationType, number> = {+ const formattedCountResults: Record<string, number> = {view: 0,comment: 0,reply: 0,reaction: 0,- // recordings: 0,- // mentions: 0,};- countResults.forEach(({ type, count }) => {- formattedCountResults[type] = Number(count);- });+ for (const { type, count } of countResults) {+ if (type === "anon_view") {+ formattedCountResults.view =+ (formattedCountResults.view ?? 0) + Number(count);+ } else {+ formattedCountResults[type] =+ (formattedCountResults[type] ?? 0) + Number(count);+ }+ }const formattedNotifications = await Effect.gen(function* () {const imageUploads = yield* ImageUploads;@@ -97,7 +88,18 @@ export async function GET() {return yield* Effect.all(notificationsWithAuthors.map(({ notification, author }) =>Effect.gen(function* () {- // all notifications currently require an author+ if (notification.type === "anon_view") {+ return APINotification.parse({+ id: notification.id,+ type: "anon_view",+ readAt: notification.readAt,+ videoId: notification.data.videoId,+ createdAt: notification.createdAt,+ anonName: notification.data.anonName ?? "Anonymous Viewer",+ location: notification.data.location ?? null,+ });+ }+if (!author) return null;const resolvedAvatar = author.avatar