Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/piratta/gymApp/llms.txt

Use this file to discover all available pages before exploring further.

The Messaging tab is the direct communication channel between a coach and every athlete on their roster. From a single consolidated hub, coaches can see all active conversations in a sidebar, pick up any thread instantly, and exchange messages that are persisted in Firestore under the fit_messages collection. Whether a quick check-in before a session or a detailed form-check debrief after a review, every interaction stays in one organised place — no external apps required.

Message Data Model

Each message exchanged in FocusFlow is represented by the Message interface:
export interface Message {
  id: string;
  senderId: string;
  receiverId: string;
  content: string;
  timestamp: string; // ISO string
  isRead: boolean;
}
FieldDescription
senderIdUser.id of the author — either the coach or the athlete.
receiverIdUser.id of the recipient.
contentPlain-text message body.
timestampISO 8601 string written at send time.
isReadfalse until the recipient opens the conversation thread.

Conversation List

The chat sidebar renders one entry per athlete registered under the coach’s account. Each entry shows:

Unread Badge

A red badge showing the unread message count appears on any conversation with messages where isRead: false and receiverId === coach.id. The dashboard KPI card also surfaces the total “Chats sin responder” count.

Mark as Read

Clicking a conversation sets it as the active thread. A “Quitar notificaciones” button appears in the chat header whenever unread incoming messages are present, and calling onMarkMessagesRead(clientId) marks all of them as read.

Message Delivery

FocusFlow syncs messages via a background polling loop that runs every 10 seconds while a user is logged in. When new messages arrive for the current user, the app:
  1. Updates the local message state and localStorage (fit_messages).
  2. Plays an audio chime via the Web Audio API (playNotificationSound).
  3. Fires a browser push notification (sendBrowserNotification) if the user has previously granted the Notification permission.
There is no dedicated per-field Firestore listener for individual conversations — all message syncing is handled by this unified poller.

Message History

All conversations are stored persistently in Firestore under the fit_messages collection key. When a coach opens any conversation, the full message history is loaded — there is no pagination limit on the visible thread. This ensures coaches can always scroll back to reference previous guidance, agreed-upon plans, or athlete feedback without losing context.
1

Open the Messages tab

Navigate to the Messages tab in the Coach Dashboard top navigation bar. The unread count badge is shown directly on the tab icon.
2

Select an athlete conversation

Click any athlete entry in the conversation sidebar. The full thread loads immediately.
3

Send a message

Type in the message input field at the bottom of the thread and press Send (or hit Enter). The message is written to Firestore and the recipient’s poller picks it up within 10 seconds.
4

Mark messages as read

Click “Quitar notificaciones” in the chat header to mark all unread messages in the active thread as isRead: true and clear the unread badge.

Notifications

New incoming messages trigger both in-app and browser push notifications, using the triggerNotification function from src/lib/notifications.ts.
triggerNotification(
  userId,
  title,
  message,
  "message",
  "messages" // linkTab — navigates straight to the Messages tab
);
The AppNotification produced carries linkTab: "messages", so tapping the notification banner navigates directly to the coach’s Messages tab. Notifications also:
  • Play an audio chime via the Web Audio API (playNotificationSound).
  • Fire a browser push notification (sendBrowserNotification) if the user has previously granted the Notification permission.
Respond quickly to athletes’ questions during active workout sessions — the athlete chat is accessible directly from their workout screen, so they may be messaging mid-set with a form question or a weight check. A prompt reply keeps their session momentum going.

Build docs developers (and LLMs) love