add prod logs
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user