completionId: cgen-961b0ddb8bdd4793be281dcb500ae8a8

cgen-961b0ddb8bdd4793be281dcb500ae8a8
This commit is contained in:
Builder.io 2025-11-11 00:30:45 +00:00
parent 1de2403ba4
commit 061ba89a38

View file

@ -2907,6 +2907,29 @@ export function createServer() {
.update({ comments_count: count })
.eq("id", postId);
}
// Notify post author of comment (only if different user)
if (post?.user_id && post.user_id !== user_id) {
try {
const { data: commenter } = await adminSupabase
.from("user_profiles")
.select("full_name, username")
.eq("id", user_id)
.single();
const commenterName = (commenter as any)?.full_name || (commenter as any)?.username || "Someone";
const preview = content.substring(0, 50) + (content.length > 50 ? "..." : "");
await adminSupabase.from("notifications").insert({
user_id: post.user_id,
type: "info",
title: "💬 New comment on your post",
message: `${commenterName} commented: "${preview}"`,
});
} catch (notifError) {
console.warn("Failed to create comment notification:", notifError);
}
}
res.json(data);
} catch (e: any) {
res.status(500).json({ error: e?.message || String(e) });