This commit implements a major architectural refactor to improve modularity, type safety, and maintainability across the codebase.
Key changes include:
- **Responsive System Refactor**: Migrated from a monolithic `useResponsive` hook to a set of specialized, granular hooks (`useBreakpoint`, `useOrientation`, `usePlatform`, etc.) located in `src/presentation/hooks/responsive`. This reduces unnecessary re-renders and improves developer experience.
- **Core Service Restructuring**: Introduced a new directory structure for services, including dedicated folders for `datasources`, `mappers`, and domain-specific types (`message`, `post`).
- **Data Layer Improvements**:
- Centralized JSON parsing logic in `src/database/core/jsonUtils.ts`.
- Cleaned up repository implementations by removing redundant local utility functions.
- Refactored `MessageMapper` to use the new centralized JSON utility.
- **Type System Cleanup**:
- Decomposed the large `src/types/dto.ts` into a modular `src/types/dto/` directory.
- Simplified `src/types/index.ts` and introduced backward-compatible aliases for core entities.
- **Utility Consolidation**:
- Created a centralized `src/utils/formatTime.ts` to replace fragmented date formatting logic across various screens and components.
- Removed deprecated responsive utility files in favor of the new hook-based system.
- **Service Logic Refinement**: Refactored `ApiClient` and `WebSocketService` to use a centralized `showVerificationModal` service, removing duplicated state management for verification prompts.
127 lines
2.7 KiB
TypeScript
127 lines
2.7 KiB
TypeScript
/**
|
|
* Repository 层模型定义
|
|
* 定义应用内部使用的数据模型,与 API 响应和数据库结构解耦
|
|
*/
|
|
|
|
// ==================== 消息模型 ====================
|
|
|
|
export interface MessageSegment {
|
|
type: string;
|
|
data: Record<string, any>;
|
|
}
|
|
|
|
export interface MessageModel {
|
|
id: string;
|
|
conversationId: string;
|
|
senderId: string;
|
|
content?: string;
|
|
type: 'text' | 'image' | 'file' | 'system' | string;
|
|
isRead: boolean;
|
|
createdAt: Date;
|
|
seq: number;
|
|
status: 'normal' | 'recalled' | 'deleted' | string;
|
|
segments?: MessageSegment[];
|
|
replyToId?: string;
|
|
sender?: UserModel;
|
|
}
|
|
|
|
// ==================== 会话模型 ====================
|
|
|
|
export type ConversationType = 'private' | 'group';
|
|
|
|
export interface ConversationModel {
|
|
id: string;
|
|
type: ConversationType;
|
|
participantId: string;
|
|
lastMessageId?: string;
|
|
lastMessage?: MessageModel;
|
|
lastSeq: number;
|
|
myLastReadSeq: number;
|
|
otherLastReadSeq: number;
|
|
unreadCount: number;
|
|
isPinned: boolean;
|
|
participants?: UserModel[];
|
|
group?: GroupModel;
|
|
createdAt: Date;
|
|
updatedAt: Date;
|
|
}
|
|
|
|
// ==================== 用户模型 ====================
|
|
|
|
export interface UserModel {
|
|
id: string;
|
|
username: string;
|
|
nickname?: string;
|
|
avatar?: string;
|
|
bio?: string;
|
|
website?: string;
|
|
location?: string;
|
|
email?: string;
|
|
phone?: string;
|
|
followersCount?: number;
|
|
followingCount?: number;
|
|
postsCount?: number;
|
|
isFollowing?: boolean;
|
|
isBlocked?: boolean;
|
|
createdAt?: Date;
|
|
updatedAt?: Date;
|
|
}
|
|
|
|
// ==================== 帖子模型 ====================
|
|
|
|
export interface PostModel {
|
|
id: string;
|
|
authorId: string;
|
|
author?: UserModel;
|
|
title: string;
|
|
content: string;
|
|
images?: string[];
|
|
likeCount: number;
|
|
commentCount: number;
|
|
shareCount: number;
|
|
viewCount: number;
|
|
favoriteCount: number;
|
|
isLiked: boolean;
|
|
isFavorited: boolean;
|
|
isTop: boolean;
|
|
status: 'published' | 'draft' | 'deleted';
|
|
channelId?: string;
|
|
/** 频道展示用(与 PostDTO.channel 一致) */
|
|
channel?: { id: string; name: string } | null;
|
|
tags?: string[];
|
|
createdAt: Date;
|
|
updatedAt: Date;
|
|
}
|
|
|
|
// ==================== 群组模型 ====================
|
|
|
|
export type GroupMemberRole = 'owner' | 'admin' | 'member';
|
|
export type GroupJoinType = 'anyone' | 'approval' | 'invite';
|
|
|
|
export interface GroupMemberModel {
|
|
userId: string;
|
|
user?: UserModel;
|
|
role: GroupMemberRole;
|
|
nickname?: string;
|
|
joinTime: Date;
|
|
muteUntil?: Date;
|
|
isMuted?: boolean;
|
|
}
|
|
|
|
export interface GroupModel {
|
|
id: string;
|
|
name: string;
|
|
avatar?: string;
|
|
description?: string;
|
|
announcement?: string;
|
|
ownerId: string;
|
|
owner?: UserModel;
|
|
memberCount: number;
|
|
maxMemberCount: number;
|
|
joinType: GroupJoinType;
|
|
isMuted: boolean;
|
|
createdAt: Date;
|
|
updatedAt: Date;
|
|
}
|
|
|