Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
f524dc8fd1
commit
ca5b7ea01a
@@ -0,0 +1,36 @@
|
||||
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");
|
||||
}
|
||||
Reference in New Issue
Block a user