From d0856648faaca152f8b3dd787c07dd6550376d19 Mon Sep 17 00:00:00 2001 From: JCEEE <0xjceee@proton.me> Date: Fri, 11 Sep 2026 12:31:31 +0100 Subject: [PATCH] add prod logs --- frontend/src/lib/server/email.ts | 1 + frontend/src/lib/server/services/chat.ts | 39 +++++++++++++++++++----- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/frontend/src/lib/server/email.ts b/frontend/src/lib/server/email.ts index f91486b..03bc8a5 100644 --- a/frontend/src/lib/server/email.ts +++ b/frontend/src/lib/server/email.ts @@ -132,6 +132,7 @@ export async function sendMentionEmail(opts: { message: string; dashboardUrl: string; }) { + console.log('[email] sendMentionEmail called to:', opts.to); const { to, parentName, authorName, message, dashboardUrl } = opts; await resend.emails.send({ diff --git a/frontend/src/lib/server/services/chat.ts b/frontend/src/lib/server/services/chat.ts index e918587..5551fe3 100644 --- a/frontend/src/lib/server/services/chat.ts +++ b/frontend/src/lib/server/services/chat.ts @@ -43,10 +43,13 @@ export async function send( createdAt: new Date().toISOString(), clientId: body.clientId ? String(body.clientId).slice(0, 64) : '' }); - // Email any @mentioned parents (their in-app toast is client-side, via the - // same mention tokens). Fire-and-forget — never fail the message itself. - notifyMentionedParents(pb, famId, actor, record, body.siteUrl || '').catch(() => {}); - return record; +// Email any @mentioned parents (their in-app toast is client-side, via the +// same mention tokens). Fire-and-forget — never fail the message itself. +console.log('[chat] calling notifyMentionedParents for famId:', famId, 'content:', content.slice(0, 50)); +notifyMentionedParents(pb, famId, actor, record, body.siteUrl || '').catch((err: any) => { + console.error('[chat] notifyMentionedParents top-level catch:', err); +}); +return record; } // Scan the message for `@Parent Name` tokens (case-insensitive) and email every @@ -58,25 +61,44 @@ async function notifyMentionedParents( message: any, siteUrl: string ) { + console.log('[chat] notifyMentionedParents called', { famId, actorName: actor.name, contentLen: String(message.content || '').length }); const content = String(message.content || ''); const parents = await pb .collection('users') .getFullList({ filter: `famId = '${famId}' && role = 'parent'` }) - .catch(() => []); + .catch((err: any) => { + console.error('[chat] Failed to fetch parents:', err); + return []; + }); + console.log('[chat] parents found:', parents.length, 'mentioned parents:', parents.filter((u: any) => { + if (u.id === actor.id || !u.email) return false; + const name = (u.name || '').trim().toLowerCase(); + return !!name && content.toLowerCase().includes('@' + name); + }).length); const mentioned = parents.filter((u: any) => { if (u.id === actor.id || !u.email) return false; const name = (u.name || '').trim().toLowerCase(); return !!name && content.toLowerCase().includes('@' + name); }); - if (!mentioned.length) return; + if (!mentioned.length) { + console.log('[chat] no mentioned parents found'); + return; + } const fam = await pb .collection('fams') .getOne(famId) - .catch(() => null); + .catch((err: any) => { + console.error('[chat] Failed to fetch fam:', err); + return null; + }); // Don't send emails for the demo family. - if (fam?.slug === 'showboaters') return; + if (fam?.slug === 'showboaters') { + console.log('[chat] skipping demo family'); + return; + } const dashboardUrl = `${siteUrl}/${fam?.slug || famId}`; + console.log('[chat] sending mention emails to', mentioned.length, 'parents'); for (const parent of mentioned) { try { await sendMentionEmail({ @@ -86,6 +108,7 @@ async function notifyMentionedParents( message: content, dashboardUrl }); + console.log('[chat] email sent to', parent.email); } catch (err) { console.error(`[chat] Failed to send mention email to ${parent.email}:`, err); }