fix(coach): deep-link the proactive nudge to its conversation

The bottom-right launcher opened a blank new chat on an unread proactive
message instead of the thread the Coach wrote. Return the owning
conversation id from the nudge-status endpoint, have the launcher open
/coach?c=<id> on the unread path, and stamp the same deep link on the push
metadata so the notification lands in the exact conversation rather than
relying on a most-recent heuristic.
This commit is contained in:
Marc-André Bombeck committed 2026-06-27 13:31:17 +02:00
1 parent 914fa8d36e
commit 9ef79b2357
6 files changed
+80 -10

No files matched your search

@@ -39,7 +39,11 @@ export const GET = apiHandler(async () => {
prisma.coachMessage.findFirst({
where: { role: "assistant", conversation: { userId: user.id } },
orderBy: { createdAt: "desc" },
select: { createdAt: true },
// v1.22 (W5) — also return the owning conversation id so the FAB can
// deep-link straight into the proactive thread (`/coach?c=<id>`)
// instead of opening a blank new chat and relying on a most-recent
// heuristic to find it.
select: { createdAt: true, conversationId: true },
}),
prisma.user.findUnique({
where: { id: user.id },
@@ -55,6 +59,10 @@ export const GET = apiHandler(async () => {
return apiSuccess({
nudgedAt: nudgedAt ? nudgedAt.toISOString() : null,
unread,
// The conversation holding the newest assistant message. Present
// whenever a Coach reply exists; the FAB only consumes it on the
// unread path.
conversationId: lastAssistant?.conversationId ?? null,
});
});