61 lines
1.1 KiB
TypeScript
61 lines
1.1 KiB
TypeScript
import { APIClient } from "./ApiClient";
|
|
import type { MessageType } from "./matrix/MatrixApiEvent";
|
|
|
|
interface BaseRoomEvent {
|
|
time: number;
|
|
room_id: string;
|
|
event_id: string;
|
|
sender: string;
|
|
origin_server_ts: number;
|
|
}
|
|
|
|
export interface RoomMessageEvent extends BaseRoomEvent {
|
|
type: "RoomMessageEvent";
|
|
data: {
|
|
msgtype: MessageType;
|
|
body: string;
|
|
"m.relates_to"?: {
|
|
rel_type?: "m.replace" | string;
|
|
event_id?: string;
|
|
};
|
|
"m.new_content"?: {
|
|
msgtype?: MessageType;
|
|
body?: string;
|
|
};
|
|
url?: string;
|
|
file?: { url: string };
|
|
};
|
|
}
|
|
|
|
export interface RoomReactionEvent extends BaseRoomEvent {
|
|
type: "RoomReactionEvent";
|
|
data: {
|
|
"m.relates_to": {
|
|
rel_type: string;
|
|
event_id: string;
|
|
key: string;
|
|
};
|
|
};
|
|
}
|
|
|
|
export interface RoomRedactionEvent extends BaseRoomEvent {
|
|
type: "RoomRedactionEvent";
|
|
data: {
|
|
redacts: string;
|
|
};
|
|
}
|
|
|
|
export type WsMessage =
|
|
| RoomMessageEvent
|
|
| RoomReactionEvent
|
|
| RoomRedactionEvent;
|
|
|
|
export class WsApi {
|
|
/**
|
|
* Get WebSocket URL
|
|
*/
|
|
static get WsURL(): string {
|
|
return APIClient.backendURL() + "/ws";
|
|
}
|
|
}
|