refactor: add more Typescript code

This commit is contained in:
Tristan Yang
2022-07-05 22:19:45 +08:00
parent 1aafc03ef5
commit d8643fc8fe
6 changed files with 47 additions and 2 deletions
+13 -2
View File
@@ -11,6 +11,7 @@ import { onMessageSendStarted } from "./handlers";
import handleChatMessage from "../../common/hook/useStreaming/chat.handler";
import { Channel, CreateChannelDTO } from "../../types/channel";
import { RootState } from "../store";
import { ContentTypeKey } from "../../types/message";
export const channelApi = createApi({
reducerPath: "channelApi",
baseQuery,
@@ -118,8 +119,18 @@ export const channelApi = createApi({
}
}
}),
sendChannelMsg: builder.mutation({
query: ({ id, content, type = "text", properties = "" }) => ({
sendChannelMsg: builder.mutation<
number,
{
id: number;
content: string | object;
type: ContentTypeKey;
properties?: object;
from_uid: number;
ignoreLocal: boolean;
}
>({
query: ({ id, content, type = "text", properties = {} }) => ({
headers: {
"content-type": ContentTypes[type],
"X-Properties": properties
+1
View File
@@ -4,6 +4,7 @@ import { ContentTypes } from "../config";
import { addChannelMsg, removeChannelMsg } from "../slices/message.channel";
import { addUserMsg, removeUserMsg } from "../slices/message.user";
import { addMessage, removeMessage } from "../slices/message";
// import { ContentType } from "../../types/message";
export const onMessageSendStarted = async (
{
+1
View File
@@ -1,3 +1,4 @@
//call `group` in backend
import { ContentType } from "./message";
export interface ChannelMember {}
+1
View File
@@ -1 +1,2 @@
export type ContentType = "text/plain" | "text/markdown" | "vocechat/file" | "vocechat/archive";
export type ContentTypeKey = "text" | "markdown" | "file" | "archive";
+30
View File
@@ -0,0 +1,30 @@
export interface ArchiveUser {
name: string;
avatar?: number;
}
export interface ArchiveMessage {
from_user: number;
created_at: number;
mid: number;
source: { uid: number } | { gid: number };
properties?: object;
content_type: string;
content?: string;
file_id?: number;
thumbnail_id?: number;
}
export interface Archive {
users: ArchiveUser[];
messages: ArchiveMessage[];
num_attachments: number;
}
// 上传文件API响应
export interface UploadResponse {
path: string;
size: number;
hash: string;
image_properties?: {
width: number;
height: number;
};
}
+1
View File
@@ -1,3 +1,4 @@
// call `organization` in backend
import { User } from "./auth";
export interface Server {