diff --git a/web/src/api/client.ts b/web/src/api/client.ts index a85f973..eca19ff 100644 --- a/web/src/api/client.ts +++ b/web/src/api/client.ts @@ -18,8 +18,9 @@ import type { EventRowID, EventType, RoomID, -} from "./types/hitypes.ts" -import type { ClientState, RPCEvent } from "./types/hievents.ts" + ClientState, + RPCEvent, +} from "./types" import type RPCClient from "./rpc.ts" import { StateStore } from "./statestore.ts" diff --git a/web/src/api/rpc.ts b/web/src/api/rpc.ts index f2678bd..d5f5d3f 100644 --- a/web/src/api/rpc.ts +++ b/web/src/api/rpc.ts @@ -23,9 +23,11 @@ import type { EventType, PaginationResponse, RoomID, - TimelineRowID, UserID, -} from "./types/hitypes.ts" -import { RPCCommand, RPCEvent } from "./types/hievents.ts" + TimelineRowID, + UserID, + RPCCommand, + RPCEvent, +} from "./types" export interface ConnectionEvent { connected: boolean diff --git a/web/src/api/statestore.ts b/web/src/api/statestore.ts index cca812c..c819c9b 100644 --- a/web/src/api/statestore.ts +++ b/web/src/api/statestore.ts @@ -25,8 +25,10 @@ import type { LazyLoadSummary, RoomID, TimelineRowTuple, -} from "./types/hitypes.ts" -import type { EventsDecryptedData, SyncCompleteData, SyncRoom } from "./types/hievents.ts" + EventsDecryptedData, + SyncCompleteData, + SyncRoom, +} from "./types" function arraysAreEqual(arr1?: T[], arr2?: T[]): boolean { if (!arr1 || !arr2) { diff --git a/web/src/api/types/hievents.ts b/web/src/api/types/hievents.ts index 9d9964e..bbcdc32 100644 --- a/web/src/api/types/hievents.ts +++ b/web/src/api/types/hievents.ts @@ -14,14 +14,16 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . import { - DBEvent, - DBRoom, DeviceID, - EventRowID, EventType, RoomID, - TimelineRowTuple, UserID, +} from "./mxtypes.ts" +import { + DBEvent, + DBRoom, + EventRowID, + TimelineRowTuple, } from "./hitypes.ts" export interface RPCCommand { diff --git a/web/src/api/types/hitypes.ts b/web/src/api/types/hitypes.ts index f490508..ad41227 100644 --- a/web/src/api/types/hitypes.ts +++ b/web/src/api/types/hitypes.ts @@ -13,18 +13,22 @@ // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +import { + ContentURI, + CreateEventContent, + EncryptedEventContent, + EncryptionEventContent, + EventID, + EventType, + LazyLoadSummary, + RelationType, + RoomAlias, + RoomID, + UserID, +} from "./mxtypes.ts" + export type EventRowID = number export type TimelineRowID = number -export type RoomID = string -export type EventID = string -export type UserID = string -export type DeviceID = string -export type EventType = string -export type ContentURI = string -export type RoomAlias = string -export type RoomVersion = "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | "11" -export type RoomType = "" | "m.space" -export type RelationType = "m.annotation" | "m.reference" | "m.replace" | "m.thread" export interface TimelineRowTuple { timeline_rowid: TimelineRowID @@ -38,30 +42,6 @@ export enum RoomNameQuality { Explicit, } -export interface RoomPredecessor { - room_id: RoomID - event_id: EventID -} - -export interface CreateEventContent { - type: RoomType - "m.federate": boolean - room_version: RoomVersion - predecessor: RoomPredecessor -} - -export interface LazyLoadSummary { - heroes?: UserID[] - "m.joined_member_count"?: number - "m.invited_member_count"?: number -} - -export interface EncryptionEventContent { - algorithm: string - rotation_period_ms?: number - rotation_period_msgs?: number -} - export interface DBRoom { room_id: RoomID creation_content: CreateEventContent @@ -82,14 +62,6 @@ export interface DBRoom { prev_batch: string } -export interface EncryptedEventContent { - algorithm: "m.megolm.v1.aes-sha2" - ciphertext: string - session_id: string - sender_key?: string - device_id?: DeviceID -} - export interface DBEvent { rowid: EventRowID timeline_rowid: TimelineRowID diff --git a/web/src/api/types/index.ts b/web/src/api/types/index.ts new file mode 100644 index 0000000..88930fa --- /dev/null +++ b/web/src/api/types/index.ts @@ -0,0 +1,3 @@ +export * from "./mxtypes.ts" +export * from "./hitypes.ts" +export * from "./hievents.ts" diff --git a/web/src/api/types/mxtypes.ts b/web/src/api/types/mxtypes.ts new file mode 100644 index 0000000..9e8fc8d --- /dev/null +++ b/web/src/api/types/mxtypes.ts @@ -0,0 +1,64 @@ +// gomuks - A Matrix client written in Go. +// Copyright (C) 2024 Tulir Asokan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +export type RoomID = string +export type EventID = string +export type UserID = string +export type DeviceID = string +export type EventType = string +export type ContentURI = string +export type RoomAlias = string +export type RoomVersion = "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | "11" +export type RoomType = "" | "m.space" +export type RelationType = "m.annotation" | "m.reference" | "m.replace" | "m.thread" + +export interface RoomPredecessor { + room_id: RoomID + event_id: EventID +} + +export interface CreateEventContent { + type: RoomType + "m.federate": boolean + room_version: RoomVersion + predecessor: RoomPredecessor +} + +export interface LazyLoadSummary { + heroes?: UserID[] + "m.joined_member_count"?: number + "m.invited_member_count"?: number +} + +export interface EncryptionEventContent { + algorithm: string + rotation_period_ms?: number + rotation_period_msgs?: number +} + +export interface EncryptedEventContent { + algorithm: "m.megolm.v1.aes-sha2" + ciphertext: string + session_id: string + sender_key?: string + device_id?: DeviceID +} + +export interface MemberEventContent { + membership: "join" | "leave" | "ban" | "invite" | "knock" + displayname?: string + avatar_url?: ContentURI + reason?: string +} diff --git a/web/src/api/wsclient.ts b/web/src/api/wsclient.ts index 865bf43..4f10c65 100644 --- a/web/src/api/wsclient.ts +++ b/web/src/api/wsclient.ts @@ -13,7 +13,7 @@ // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -import type { RPCCommand } from "./types/hievents.ts" +import type { RPCCommand } from "./types" import RPCClient from "./rpc.ts" export default class WSClient extends RPCClient { diff --git a/web/src/ui/MainScreen.tsx b/web/src/ui/MainScreen.tsx index f8b84cb..d031a30 100644 --- a/web/src/ui/MainScreen.tsx +++ b/web/src/ui/MainScreen.tsx @@ -14,7 +14,7 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . import { useState, use } from "react" -import type { RoomID } from "../api/types/hitypes.ts" +import type { RoomID } from "../api/types" import RoomList from "./roomlist/RoomList.tsx" import RoomView from "./RoomView.tsx" import { ClientContext } from "./ClientContext.ts" diff --git a/web/src/ui/login/LoginScreen.tsx b/web/src/ui/login/LoginScreen.tsx index 186fbc0..0428c58 100644 --- a/web/src/ui/login/LoginScreen.tsx +++ b/web/src/ui/login/LoginScreen.tsx @@ -15,8 +15,8 @@ // along with this program. If not, see . import React, { useCallback, useEffect, useState } from "react" import type Client from "../../api/client.ts" +import { ClientState } from "../../api/types" import "./LoginScreen.css" -import { ClientState } from "../../api/types/hievents.ts" export interface LoginScreenProps { client: Client diff --git a/web/src/ui/login/VerificationScreen.tsx b/web/src/ui/login/VerificationScreen.tsx index d094b60..350ddc9 100644 --- a/web/src/ui/login/VerificationScreen.tsx +++ b/web/src/ui/login/VerificationScreen.tsx @@ -14,8 +14,8 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . import React, { useCallback, useState } from "react" -import "./LoginScreen.css" import { LoginScreenProps } from "./LoginScreen.tsx" +import "./LoginScreen.css" export const VerificationScreen = ({ client, clientState }: LoginScreenProps) => { if (!clientState.is_logged_in) { diff --git a/web/src/ui/roomlist/RoomList.tsx b/web/src/ui/roomlist/RoomList.tsx index 1a92548..38579fd 100644 --- a/web/src/ui/roomlist/RoomList.tsx +++ b/web/src/ui/roomlist/RoomList.tsx @@ -14,7 +14,7 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . import React, { use, useMemo } from "react" -import type { RoomID } from "../../api/types/hitypes.ts" +import type { RoomID } from "../../api/types" import { useNonNullEventAsState } from "../../util/eventdispatcher.ts" import { ClientContext } from "../ClientContext.ts" import Entry from "./Entry.tsx" diff --git a/web/src/ui/timeline/TimelineEvent.tsx b/web/src/ui/timeline/TimelineEvent.tsx index dac3bde..d993a20 100644 --- a/web/src/ui/timeline/TimelineEvent.tsx +++ b/web/src/ui/timeline/TimelineEvent.tsx @@ -15,7 +15,7 @@ // along with this program. If not, see . import React from "react" import { RoomStateStore } from "../../api/statestore.ts" -import { DBEvent } from "../../api/types/hitypes.ts" +import { DBEvent, MemberEventContent } from "../../api/types" import { EventContentProps } from "./content/props.ts" import HiddenEvent from "./content/HiddenEvent.tsx" import "./TimelineEvent.css" diff --git a/web/src/ui/timeline/content/MessageBody.tsx b/web/src/ui/timeline/content/MessageBody.tsx index d8fd903..67b747e 100644 --- a/web/src/ui/timeline/content/MessageBody.tsx +++ b/web/src/ui/timeline/content/MessageBody.tsx @@ -15,7 +15,7 @@ // along with this program. If not, see . import sanitizeHtml from "sanitize-html" -import { ContentURI } from "../../../api/types/hitypes.ts" +import { ContentURI } from "../../../api/types" import { getMediaURL } from "../../../api/media.ts" import { sanitizeHtmlParams } from "../../../util/html.ts" import { EventContentProps } from "./props.ts"