Skip to content

Chat · Repositories

9 modules · 32 exports · 1 repository · 16 e2e tests · 5 routes

Every table a function queries, its own helpers included, read or written. Calls to other repositories are listed apart, their tables are on their own page.

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

function

findAllRoomsByIds

:27

Chat rooms by id.

export async function findAllRoomsByIds(roomIds: number[])
TablesChatRoom
function

findAllOpenRoomIdsByUserId

:42

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[]>
function

findAllMessagesByRoomId

:142

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)
function

findMessageById

:158

Returns a message with its author resolved live.

export function findMessageById(messageId: number)
Unit tests (2)
function

findAllParticipantsByUserIds

:167

Users as rooms list their participants, for mentioning them.

export async function findAllParticipantsByUserIds(userIds: number[])
function

findMessageStatsByRoomIds

:178

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)
function

insertRoom

:223

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>,
)
TablesChatRoom
function

insertRooms

:240

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[]>
TablesChatRoom
function

updateRoomExpiresAt

:269

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>,
)
TablesChatRoom
function

updateRoomsExpiresAt

:283

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>,
)
TablesChatRoom
function

updateRoomsInactive

:301

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>,
)
TablesChatRoom
Unit tests (2)
function

insertMessage

:327

Inserts a user message. A publicId conflict (retried send) returns the existing row instead.

export async function insertMessage(args: InsertMessageArgs)
Unit tests (2)
function

insertSystemMessage

:345

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)
function

upsertReadIndicator

:363

Marks the newest message a user has seen in a room. Never regresses: upserts keep the MAX.

export async function upsertReadIndicator(
	args: TablesInsertable["ChatMessageReadIndicator"],
)
Unit tests (2)
function

closeExpiredRooms

:378

Closes rooms whose expiry is before expiredBefore, returning how many. Messages are kept; access narrows.

export async function closeExpiredRooms(expiredBefore: Date)
TablesChatRoom
Unit tests (2)
function

deleteOrphanedRooms

:390

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()
TablesChatRoom
Unit tests (2)