ChatRepository
app/features/chat/ChatRepository.server.ts- Tables
- ChatMessageChatMessageReadIndicatorChatRoomGroupGroupMatchGroupMemberScrimPostScrimPostRequestScrimPostRequestUserScrimPostUserTournamentMatchTournamentTeamTournamentTeamMemberUserUserSubmittedImage
- Calls
- no other repositories
- Imports
- no other modules
- Used by
- 1 action3 routes5 repositories1 routine2 scripts6 other
Functions & values
Ids of the open rooms the user participates in. Membership-first: every branch starts from the user's own membership rows so the cost tracks their participation, not the site's open room count. SendouQ branches narrow further to {@link SQ_MEMBERSHIP_LOOKBACK_HOURS}.
export async function findAllOpenRoomIdsByUserId( userId: number, ): Promise<number[]>
Returns the latest limit messages of a room, oldest first, authors resolved live.
export async function findAllMessagesByRoomId( roomId: number, { limit = MESSAGES_DEFAULT_LIMIT }: { limit?: number } = {}, )
Unit tests (3)
Returns a message with its author resolved live.
export function findMessageById(messageId: number)
Unit tests (2)
Users as rooms list their participants, for mentioning them.
export async function findAllParticipantsByUserIds(userIds: number[])
Per-room message stats for the user: unread count (messages newer than their read indicator) and the latest message. Rooms with no messages are left out.
export async function findMessageStatsByRoomIds( userId: number, roomIds: number[], ): Promise< Array<{ roomId: number; unreadCount: number; latestMessageId: number; latestMessageCreatedAt: number; }> >
Unit tests (4)
Inserts a chat room, returning the row. Called in the owning entity's insert transaction.
export function insertRoom( args: { type: Tables["ChatRoom"]["type"]; expiresAt: Date }, trx?: Transaction<DB>, )
Inserts count chat rooms of one type, returning their ids in insertion order. Called in the owning entity's insert transaction.
export async function insertRooms( args: { type: Tables["ChatRoom"]["type"]; expiresAt: Date; count: number; }, trx?: Transaction<DB>, ): Promise<number[]>
Extends a room's lifetime, e.g. when a successor group carries its chat over.
export async function updateRoomExpiresAt( args: { roomId: number; expiresAt: Date }, trx?: Transaction<DB>, )
Sets rooms' expiry, e.g. to wind down league match rooms once their set is decided.
export async function updateRoomsExpiresAt( roomIds: Array<number | null>, expiresAt: Date, trx?: Transaction<DB>, )
Marks rooms' owner activity as concluded, or active again (a reopened tournament match).
export async function updateRoomsInactive( roomIds: Array<number | null>, inactive: boolean, trx?: Transaction<DB>, )
Inserts a user message. A publicId conflict (retried send) returns the existing row instead.
export async function insertMessage(args: InsertMessageArgs)
Unit tests (2)
Inserts a system message rendered client-side from its type; authorUserId is the actor it describes.
export function insertSystemMessage( args: { roomId: number; type: PersistedSystemMessageType; authorUserId: number; }, trx?: Transaction<DB>, )
Unit tests (1)
Marks the newest message a user has seen in a room. Never regresses: upserts keep the MAX.
export async function upsertReadIndicator( args: TablesInsertable["ChatMessageReadIndicator"], )
Closes rooms whose expiry is before expiredBefore, returning how many. Messages are kept; access narrows.
export async function closeExpiredRooms(expiredBefore: Date)
Deletes rooms no owner row points at any more (backstop for owner deletes that missed their room), returning how many. A room's type names its one owner table.
export async function deleteOrphanedRooms()