feat(reset): 以构造器模式重构
- 加了大文件传输自定义分片协议 BREAKING CHANGES: 0.1.0(latest)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { PaginationRequest, PaginationResponse } from '../common';
|
||||
import type { ChatSession, ChatMessage } from './base';
|
||||
import type { ChatMessageType } from './enum';
|
||||
import type { ChatMessageType } from './types';
|
||||
|
||||
// 创建聊天会话请求接口
|
||||
export interface CreateChatSessionRequest {
|
||||
@@ -7,92 +8,55 @@ export interface CreateChatSessionRequest {
|
||||
participantId: string;
|
||||
}
|
||||
|
||||
// 更新聊天会话请求接口(占位)
|
||||
export interface UpdateChatSessionRequest {
|
||||
// 只能用于处理后台逻辑
|
||||
sessionId: string;
|
||||
// 创建聊天会话响应接口
|
||||
export interface CreateChatSessionResponse {
|
||||
success: boolean;
|
||||
chatSessionId: string; // 成功时返回会话ID,应该是点击私信就跳转到私信
|
||||
}
|
||||
|
||||
|
||||
// 发送消息请求接口
|
||||
export interface SendMessageRequest {
|
||||
sessionId: string;
|
||||
chatSessionId: string; // cookie存不了这个,所以得在请求体里
|
||||
content: string;
|
||||
type: ChatMessageType;
|
||||
metadata?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface SendMessageResponse {
|
||||
success: boolean;
|
||||
}
|
||||
|
||||
// 获取聊天会话列表请求接口
|
||||
export interface GetChatSessionsRequest {
|
||||
page?: number;
|
||||
limit?: number;
|
||||
export interface GetChatSessionsRequest extends PaginationRequest {
|
||||
// 足矣
|
||||
}
|
||||
|
||||
// 获取聊天会话列表响应接口
|
||||
export interface GetChatSessionsResponse {
|
||||
sessions: ChatSession[];
|
||||
total: number;
|
||||
page: number;
|
||||
limit: number;
|
||||
export interface GetChatSessionsResponse extends PaginationResponse<ChatSession> {
|
||||
// 足矣
|
||||
}
|
||||
|
||||
|
||||
// 获取聊天消息请求接口
|
||||
export interface GetChatMessagesRequest {
|
||||
sessionId: string;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
export interface GetChatMessagesRequest extends PaginationRequest {
|
||||
chatSessionId: string;
|
||||
before?: string; // 消息ID,获取该消息之前的消息
|
||||
after?: string; // 消息ID,获取该消息之后的消息
|
||||
}
|
||||
|
||||
// 获取聊天消息响应接口
|
||||
export interface GetChatMessagesResponse {
|
||||
messages: ChatMessage[];
|
||||
total: number;
|
||||
page: number;
|
||||
limit: number;
|
||||
hasMore: boolean;
|
||||
export interface GetChatMessagesResponse extends PaginationResponse<ChatMessage> {
|
||||
// 足矣
|
||||
}
|
||||
|
||||
// 标记消息已读请求接口
|
||||
export interface MarkMessagesAsReadRequest {
|
||||
sessionId: string;
|
||||
messageIds: string[];
|
||||
}
|
||||
|
||||
// 标记消息已读响应接口(已读状态只面向接收方)
|
||||
export interface MarkMessagesAsReadResponse {
|
||||
success: boolean;
|
||||
markedMessageIds: string[]; // 成功标记的消息ID
|
||||
failedMessageIds?: string[]; // 失败的消息ID
|
||||
}
|
||||
|
||||
// 搜索聊天消息请求接口
|
||||
export interface SearchChatMessagesRequest {
|
||||
sessionId?: string;
|
||||
// 搜索聊天消息/会话请求接口
|
||||
export interface SearchChatMessagesRequest extends PaginationRequest {
|
||||
query: string;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
// 搜索聊天消息响应接口
|
||||
export interface SearchChatMessagesResponse {
|
||||
messages: ChatMessage[];
|
||||
total: number;
|
||||
page: number;
|
||||
limit: number;
|
||||
export interface SearchChatMessagesResponse extends PaginationResponse<ChatSession> {
|
||||
// 足矣
|
||||
}
|
||||
|
||||
// 搜索聊天会话请求接口
|
||||
export interface SearchChatSessionsRequest {
|
||||
query: string;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
// 搜索聊天会话响应接口
|
||||
export interface SearchChatSessionsResponse {
|
||||
sessions: ChatSession[];
|
||||
total: number;
|
||||
page: number;
|
||||
limit: number;
|
||||
}
|
||||
|
||||
@@ -1,47 +1,25 @@
|
||||
import type { User } from '../index';
|
||||
import type { ChatMessageType, ChatMessageStatus } from './enum';
|
||||
import type { UserProfile } from '../user';
|
||||
import type { ChatMessageType } from './types';
|
||||
import type { BaseEntity } from '../common';
|
||||
|
||||
// 聊天消息接口
|
||||
export interface ChatMessage {
|
||||
id: string;
|
||||
export interface ChatMessage extends BaseEntity {
|
||||
// 聊天会话id,下面那个接口的id
|
||||
sessionId: string;
|
||||
sender: User;
|
||||
receiver: User;
|
||||
content: string;
|
||||
type: ChatMessageType;
|
||||
status: ChatMessageStatus;
|
||||
chatSessionId: string;
|
||||
sender: UserProfile;
|
||||
receiver: UserProfile;
|
||||
content: string; // 只支持文本信息
|
||||
type: ChatMessageType; // 实际无用
|
||||
createdAt: Date;
|
||||
// 非文本消息类型的元数据
|
||||
metadata?: {
|
||||
fileName?: string;
|
||||
fileSize?: number;
|
||||
duration?: number;
|
||||
// 小图预览
|
||||
thumbnail?: string;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
// 无元数据,因为只有文本消息
|
||||
}
|
||||
|
||||
// 聊天会话接口
|
||||
export interface ChatSession {
|
||||
export interface ChatSession extends BaseEntity {
|
||||
id: string;
|
||||
participant1Id: string;
|
||||
participant2Id: string;
|
||||
participant1: User;
|
||||
participant2: User;
|
||||
lastMessage?: {
|
||||
id: string;
|
||||
content: string;
|
||||
senderId: string;
|
||||
createdAt: Date;
|
||||
};
|
||||
unreadCount1: number; // 参与者1的未读消息数
|
||||
unreadCount2: number; // 参与者2的未读消息数
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
// 会话元数据(特殊标记、背景设置、自定义属性等等)
|
||||
metadata?: {
|
||||
[key: string]: unknown;
|
||||
};
|
||||
participant1: UserProfile;
|
||||
participant2: UserProfile;
|
||||
// 用于在聊天列表显示最后一句话
|
||||
lastMessage?: ChatMessage;
|
||||
// 没有已读和未读
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
// 聊天消息类型枚举(暂时用不到的)
|
||||
export enum ChatMessageType {
|
||||
TEXT = 'text',
|
||||
IMAGE = 'image',
|
||||
FILE = 'file',
|
||||
VOICE = 'voice',
|
||||
VIDEO = 'video',
|
||||
SYSTEM = 'system'
|
||||
}
|
||||
|
||||
// 聊天消息状态枚举(暂时用不到的)
|
||||
export enum ChatMessageStatus {
|
||||
SENDING = 'sending',
|
||||
SENT = 'sent',
|
||||
DELIVERED = 'delivered',
|
||||
READ = 'read',
|
||||
FAILED = 'failed'
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from './enum';
|
||||
export * from './base';
|
||||
export * from './api';
|
||||
export * from './types';
|
||||
|
||||
4
types/chat/types.ts
Normal file
4
types/chat/types.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
// 聊天消息类型枚举(暂时只支持文本)
|
||||
export type ChatMessageType =
|
||||
| 'text';
|
||||
|
||||
Reference in New Issue
Block a user