Skip to content

Function: hasGroupUnread()

hasGroupUnread(group, currentUserId?, isCurrentlyViewing?): boolean

Defined in: src/utils/group-utils.ts:106

Determines whether a group has unread messages for a specific user.

Rules:

  1. If no current user or group has no lastMessageAt, no unread.
  2. If the user is currently actively viewing this group's chat, no unread.
  3. If the last message was sent by the user themselves, never mark as unread (prevents self-trigger bug).
  4. If the user has a memberLastReadAt timestamp, compare it with lastMessageAt.
  5. If no memberLastReadAt exists (first time), check if lastMessageAt is after their joinedAt timestamp.

Parameters

group

Group

currentUserId?

string | null

isCurrentlyViewing?

boolean = false

Returns

boolean

Released under the MIT License.