import type * as renraku from "renraku" import {Id} from "dbmage" import * as dbmage from "dbmage" import type {Await} from "../../../../types/await.js" import type {AccessPayload} from "../../../auth/types/auth-tokens.js" import type {makeChatServerside} from "../../api/services/chat-serverside.js" import type {makeChatClientside} from "../../api/services/chat-clientside.js" import type {mockChatPersistence} from "../../api/cores/persistence/mock-chat-persistence.js" export interface ChatMeta { accessToken: string } export interface ChatAuth { access: AccessPayload } export type ChatPolicy = (meta: ChatMeta, headers: renraku.HttpHeaders) => Promise export type ChatDraft = { content: string } export type ChatPost = { room: string nickname: string postId: string userId: string time: number } & ChatDraft export type ChatPostRow = { room: string postId: Id userId: Id time: number nickname: string } & ChatDraft export type ChatMute = { userId: string } export type ChatMuteRow = { userId: Id } export type ChatRoomStatusRow = { room: string status: ChatStatus } export type ChatSchema = dbmage.AsSchema<{ posts: ChatPostRow mutes: ChatMuteRow roomStatuses: ChatRoomStatusRow roomUsers: {room: string, user?: Id, participant: boolean} }> export type ChatShape = dbmage.SchemaToShape export const chatShape: ChatShape = { posts: true, mutes: true, roomStatuses: true, roomUsers: true, } export type ChatPersistence = Await> export type ChatPersistenceActions = ReturnType export type ChatServersideApi = ReturnType export type ChatClientsideApi = ReturnType export type ChatServerside = renraku.Remote export type ChatClientside = renraku.Remote export interface ClientRecord { rooms: Set auth: undefined | ChatAuth clientside: ChatClientside controls: renraku.ConnectionControls } export interface ChatConnection { serverside: ChatServerside disconnect(): void } export type ChatConnect = ({clientsideApi}: { clientsideApi: ChatClientsideApi handleDisconnect(): void }) => Promise export enum ChatStatus { Offline, Online, } export interface ChatRoomStats { totalUsers: number viewers: number participants: number moderators: number } export interface StatsForChatRoom { [roomName: string]: ChatRoomStats } export interface ChatStats { numberOfConnections: number statsForRooms: StatsForChatRoom }