/**
 * Persist + broadcast a mention. The persisted row is what the notifications
 * dropdown reads on next load; the WS event is the live nudge that surfaces
 * the toast and bumps the unread badge without waiting for a poll.
 *
 * One-stop call site so messaging-era split between "write row" and "fire
 * event" can never drift — every mention goes through this.
 */
export function broadcastMention(notifications, wsHub, input) {
    const id = notifications.insert({
        userId: input.recipient.id,
        sourceType: input.sourceType,
        sourceId: input.sourceId,
        mentionerUserId: input.mentioner.id,
        mentionerDisplayName: input.mentioner.displayName,
        preview: input.preview,
    });
    // Target the recipient explicitly. `wsHub.broadcast` only filters by
    // `event.repo`, and user_mention has no repo, so a plain broadcast would
    // fan the toast + preview out to every connected client — leaking the
    // comment body and bumping unread badges for users who weren't mentioned.
    wsHub.broadcastToUser(String(input.recipient.id), {
        type: 'user_mention',
        userId: input.recipient.id,
        notificationId: id,
        sourceType: input.sourceType,
        sourceId: input.sourceId,
        mentionerName: input.mentioner.displayName,
        preview: input.preview.length > 200 ? input.preview.slice(0, 200) : input.preview,
        timestamp: new Date().toISOString(),
        entryRepo: input.entry?.repo ?? null,
        entryType: input.entry?.entryType ?? null,
        entryId: input.entry?.entryId ?? null,
        threadId: input.entry?.threadId ?? null,
    });
    return id;
}
//# sourceMappingURL=notification-broadcast.js.map