Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { supabase } from "@/integrations/supabase/client";
|
|
import type { Database } from "@/integrations/supabase/types";
|
|
|
|
export type NotificationKind = Database["public"]["Enums"]["notification_kind"];
|
|
|
|
export interface CreateNotificationInput {
|
|
user_id: string;
|
|
kind: NotificationKind;
|
|
title: string;
|
|
body?: string | null;
|
|
link?: string | null;
|
|
task_id?: string | null;
|
|
case_id?: string | null;
|
|
conversation_id?: string | null;
|
|
created_by?: string | null;
|
|
}
|
|
|
|
export async function createNotifications(rows: CreateNotificationInput[]) {
|
|
if (!rows.length) return;
|
|
await supabase.from("notifications").insert(rows);
|
|
}
|
|
|
|
const MENTION_RE = /@\[([^\]]+)\]\(user:([0-9a-f-]{36})\)/g;
|
|
|
|
export function extractMentions(body: string): string[] {
|
|
const ids = new Set<string>();
|
|
let m: RegExpExecArray | null;
|
|
while ((m = MENTION_RE.exec(body)) !== null) {
|
|
ids.add(m[2]);
|
|
}
|
|
return Array.from(ids);
|
|
}
|
|
|
|
export function renderMentionsToText(body: string): string {
|
|
return body.replace(MENTION_RE, "@$1");
|
|
}
|