1
0
Fork 0
forked from Mirrors/gomuks

web/types: split standard matrix types to separate file

This commit is contained in:
Tulir Asokan 2024-10-10 01:25:01 +03:00
parent dd6c7b4822
commit 3065f7363c
14 changed files with 106 additions and 60 deletions

View file

@ -18,8 +18,9 @@ import type {
EventRowID, EventRowID,
EventType, EventType,
RoomID, RoomID,
} from "./types/hitypes.ts" ClientState,
import type { ClientState, RPCEvent } from "./types/hievents.ts" RPCEvent,
} from "./types"
import type RPCClient from "./rpc.ts" import type RPCClient from "./rpc.ts"
import { StateStore } from "./statestore.ts" import { StateStore } from "./statestore.ts"

View file

@ -23,9 +23,11 @@ import type {
EventType, EventType,
PaginationResponse, PaginationResponse,
RoomID, RoomID,
TimelineRowID, UserID, TimelineRowID,
} from "./types/hitypes.ts" UserID,
import { RPCCommand, RPCEvent } from "./types/hievents.ts" RPCCommand,
RPCEvent,
} from "./types"
export interface ConnectionEvent { export interface ConnectionEvent {
connected: boolean connected: boolean

View file

@ -25,8 +25,10 @@ import type {
LazyLoadSummary, LazyLoadSummary,
RoomID, RoomID,
TimelineRowTuple, TimelineRowTuple,
} from "./types/hitypes.ts" EventsDecryptedData,
import type { EventsDecryptedData, SyncCompleteData, SyncRoom } from "./types/hievents.ts" SyncCompleteData,
SyncRoom,
} from "./types"
function arraysAreEqual<T>(arr1?: T[], arr2?: T[]): boolean { function arraysAreEqual<T>(arr1?: T[], arr2?: T[]): boolean {
if (!arr1 || !arr2) { if (!arr1 || !arr2) {

View file

@ -14,14 +14,16 @@
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import { import {
DBEvent,
DBRoom,
DeviceID, DeviceID,
EventRowID,
EventType, EventType,
RoomID, RoomID,
TimelineRowTuple,
UserID, UserID,
} from "./mxtypes.ts"
import {
DBEvent,
DBRoom,
EventRowID,
TimelineRowTuple,
} from "./hitypes.ts" } from "./hitypes.ts"
export interface RPCCommand<T> { export interface RPCCommand<T> {

View file

@ -13,18 +13,22 @@
// //
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import {
ContentURI,
CreateEventContent,
EncryptedEventContent,
EncryptionEventContent,
EventID,
EventType,
LazyLoadSummary,
RelationType,
RoomAlias,
RoomID,
UserID,
} from "./mxtypes.ts"
export type EventRowID = number export type EventRowID = number
export type TimelineRowID = 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 { export interface TimelineRowTuple {
timeline_rowid: TimelineRowID timeline_rowid: TimelineRowID
@ -38,30 +42,6 @@ export enum RoomNameQuality {
Explicit, 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 { export interface DBRoom {
room_id: RoomID room_id: RoomID
creation_content: CreateEventContent creation_content: CreateEventContent
@ -82,14 +62,6 @@ export interface DBRoom {
prev_batch: string 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 { export interface DBEvent {
rowid: EventRowID rowid: EventRowID
timeline_rowid: TimelineRowID timeline_rowid: TimelineRowID

View file

@ -0,0 +1,3 @@
export * from "./mxtypes.ts"
export * from "./hitypes.ts"
export * from "./hievents.ts"

View file

@ -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 <https://www.gnu.org/licenses/>.
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
}

View file

@ -13,7 +13,7 @@
// //
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import type { RPCCommand } from "./types/hievents.ts" import type { RPCCommand } from "./types"
import RPCClient from "./rpc.ts" import RPCClient from "./rpc.ts"
export default class WSClient extends RPCClient { export default class WSClient extends RPCClient {

View file

@ -14,7 +14,7 @@
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import { useState, use } from "react" 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 RoomList from "./roomlist/RoomList.tsx"
import RoomView from "./RoomView.tsx" import RoomView from "./RoomView.tsx"
import { ClientContext } from "./ClientContext.ts" import { ClientContext } from "./ClientContext.ts"

View file

@ -15,8 +15,8 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import React, { useCallback, useEffect, useState } from "react" import React, { useCallback, useEffect, useState } from "react"
import type Client from "../../api/client.ts" import type Client from "../../api/client.ts"
import { ClientState } from "../../api/types"
import "./LoginScreen.css" import "./LoginScreen.css"
import { ClientState } from "../../api/types/hievents.ts"
export interface LoginScreenProps { export interface LoginScreenProps {
client: Client client: Client

View file

@ -14,8 +14,8 @@
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import React, { useCallback, useState } from "react" import React, { useCallback, useState } from "react"
import "./LoginScreen.css"
import { LoginScreenProps } from "./LoginScreen.tsx" import { LoginScreenProps } from "./LoginScreen.tsx"
import "./LoginScreen.css"
export const VerificationScreen = ({ client, clientState }: LoginScreenProps) => { export const VerificationScreen = ({ client, clientState }: LoginScreenProps) => {
if (!clientState.is_logged_in) { if (!clientState.is_logged_in) {

View file

@ -14,7 +14,7 @@
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import React, { use, useMemo } from "react" 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 { useNonNullEventAsState } from "../../util/eventdispatcher.ts"
import { ClientContext } from "../ClientContext.ts" import { ClientContext } from "../ClientContext.ts"
import Entry from "./Entry.tsx" import Entry from "./Entry.tsx"

View file

@ -15,7 +15,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import React from "react" import React from "react"
import { RoomStateStore } from "../../api/statestore.ts" 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 { EventContentProps } from "./content/props.ts"
import HiddenEvent from "./content/HiddenEvent.tsx" import HiddenEvent from "./content/HiddenEvent.tsx"
import "./TimelineEvent.css" import "./TimelineEvent.css"

View file

@ -15,7 +15,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import sanitizeHtml from "sanitize-html" import sanitizeHtml from "sanitize-html"
import { ContentURI } from "../../../api/types/hitypes.ts" import { ContentURI } from "../../../api/types"
import { getMediaURL } from "../../../api/media.ts" import { getMediaURL } from "../../../api/media.ts"
import { sanitizeHtmlParams } from "../../../util/html.ts" import { sanitizeHtmlParams } from "../../../util/html.ts"
import { EventContentProps } from "./props.ts" import { EventContentProps } from "./props.ts"