a tool for shared writing and social publishing
1"use server";
2import { getIdentityData } from "actions/getIdentityData";
3import { hydrateNotifications } from "src/notifications";
4import { supabaseServerClient } from "supabase/serverClient";
5
6export async function getNotifications(limit?: number) {
7 let identity = await getIdentityData();
8 if (!identity?.atp_did) return [];
9 let query = supabaseServerClient
10 .from("notifications")
11 .select("*")
12 .eq("recipient", identity.atp_did)
13 .order("created_at", { ascending: false });
14 if (limit) query.limit(limit);
15 let { data } = await query;
16 let notifications = await hydrateNotifications(data || []);
17 return notifications;
18}
19
20export async function markAsRead() {
21 let identity = await getIdentityData();
22 if (!identity?.atp_did) return [];
23 await supabaseServerClient
24 .from("notifications")
25 .update({ read: true })
26 .eq("recipient", identity.atp_did);
27 return;
28}