completionId: cgen-961b0ddb8bdd4793be281dcb500ae8a8
cgen-961b0ddb8bdd4793be281dcb500ae8a8
This commit is contained in:
parent
1de2403ba4
commit
061ba89a38
1 changed files with 23 additions and 0 deletions
|
|
@ -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) });
|
||||
|
|
|
|||
Loading…
Reference in a new issue