refactor(post): consolidate post sync to PostSyncService and remove ProcessPostUseCase
All checks were successful
Frontend CI / build-and-push-web (push) Successful in 3m28s
Frontend CI / ota-android (push) Successful in 10m25s
Frontend CI / build-android-apk (push) Successful in 55m22s

- Replace ProcessPostUseCase with new PostSyncService in src/services/post/
- Add postListStore for state management in src/stores/post/
- Remove deprecated ProcessPostUseCase and ProcessMessageUseCase files
- Delete architecture documentation files (ARCHITECTURE_REFACTOR_PLAN.md, architecture-comparison-report.md)
- Update all consumers (HomeScreen, PostDetailScreen, SearchScreen, useUserProfile, useDifferentialPosts)
- Simplify postService to only contain API layer methods
- Remove unused type exports from message stores

BREAKING CHANGE: ProcessPostUseCase and ProcessMessageUseCase have been removed.
Use postSyncService for post operations instead.
This commit is contained in:
lafay
2026-04-13 00:26:05 +08:00
parent 6610d2f173
commit 2adc9360a5
21 changed files with 679 additions and 2896 deletions

View File

@@ -29,9 +29,6 @@ import { useMessageStore, normalizeConversationId } from './store';
// 重新导出类型,保持兼容性
export type {
MessageEventType,
MessageEvent,
MessageSubscriber,
MessageManagerState,
ReadStateRecord,
MessageManagerConversationListDeps,

View File

@@ -23,15 +23,10 @@ export type { MessageState, MessageActions, MessageStore } from './store';
// ==================== 类型导出 ====================
// 从 types.ts 导出所有类型
export type {
MessageEventType,
MessageEvent,
MessageSubscriber,
MessageManagerState,
ReadStateRecord,
MessageManagerConversationListDeps,
HandleNewMessageOptions,
// 服务接口类型(保留向后兼容,但服务层已不再使用)
IMessageStateManager,
IMessageDeduplication,
IUserCacheService,
IReadReceiptManager,

View File

@@ -1,193 +1,48 @@
/**
* 消息管理类型定义模块
* 包含所有与消息管理相关的类型、接口和类型别名
*/
import type { ConversationResponse, MessageResponse, UserDTO } from '../../types/dto';
import type { IConversationListPagedSource } from '../conversationListSources';
// ==================== 事件类型 ====================
/**
* 消息事件类型枚举
* 定义了所有可能的消息事件类型
*/
export type MessageEventType =
| 'conversations_updated'
| 'conversations_loading'
| 'messages_updated'
| 'unread_count_updated'
| 'connection_changed'
| 'message_sent'
| 'message_read'
| 'message_received'
| 'message_recalled'
| 'typing_status'
| 'group_notice'
| 'error';
/**
* 消息事件接口
* 所有订阅者接收的事件对象结构
*/
export interface MessageEvent {
type: MessageEventType;
payload: any;
timestamp: number;
}
/**
* 消息订阅者类型
*/
export type MessageSubscriber = (event: MessageEvent) => void;
// ==================== 状态接口 ====================
/**
* 消息管理器内部状态接口
* 定义了所有需要管理的状态字段
*/
export interface MessageManagerState {
// 会话相关
conversations: Map<string, ConversationResponse>;
conversationList: ConversationResponse[];
// 消息相关 - 按会话ID存储
messagesMap: Map<string, MessageResponse[]>;
// 未读数
totalUnreadCount: number;
systemUnreadCount: number;
// 连接状态
isWSConnected: boolean;
// 当前活动会话ID用户正在查看的会话
currentConversationId: string | null;
// 加载状态
isLoadingConversations: boolean;
loadingMessagesSet: Set<string>; // 正在加载消息的会话ID集合
// 初始化状态
loadingMessagesSet: Set<string>;
isInitialized: boolean;
// 订阅者
subscribers: Set<MessageSubscriber>;
// 输入状态 - 按群组ID存储正在输入的用户ID列表
typingUsersMap: Map<string, string[]>;
// 当前用户的禁言状态 - 按群组ID存储
mutedStatusMap: Map<string, boolean>;
}
// ==================== 已读状态相关 ====================
/**
* 已读状态记录接口
* 用于跟踪已读操作的状态和保护机制
*/
export interface ReadStateRecord {
/** 标记已读的时间戳 */
timestamp: number;
/** 状态版本号,用于防止旧数据覆盖新数据 */
version: number;
/** 已上报的已读序号(用于去重) */
lastReadSeq: number;
/** 清除保护的定时器ID */
clearTimer?: ReturnType<typeof setTimeout>;
}
// ==================== 依赖注入接口 ====================
/**
* 可注入会话列表源,便于测试或替换实现
*/
export interface MessageManagerConversationListDeps {
remoteConversationListSource?: IConversationListPagedSource;
localConversationListSource?: IConversationListPagedSource;
/**
* 未传 remoteConversationListSource 时:默认 `cursor`/conversations/cursor
* `offset` 为常规页码(/conversations?page=&page_size=)。
*/
remoteListKind?: 'cursor' | 'offset';
/** 与 remoteListKind 搭配,默认与 CONVERSATION_LIST_PAGE_SIZE 一致 */
remoteListPageSize?: number;
}
// ==================== 消息处理选项 ====================
/**
* 处理新消息的选项
*/
export interface HandleNewMessageOptions {
/** 是否抑制未读数增加 */
suppressUnreadIncrement?: boolean;
/** 是否抑制震动 */
suppressVibration?: boolean;
/** 是否抑制会话更新 */
suppressConversationUpdates?: boolean;
/** 是否抑制自动标记已读 */
suppressAutoMarkAsRead?: boolean;
}
// ==================== 服务接口 ====================
/**
* 状态管理器接口
* 定义状态管理器需要实现的方法
*/
export interface IMessageStateManager {
// 获取状态
getState(): MessageManagerState;
getConversations(): ConversationResponse[];
getConversation(conversationId: string): ConversationResponse | null;
getMessages(conversationId: string): MessageResponse[];
getUnreadCount(): { total: number; system: number };
isConnected(): boolean;
isLoading(): boolean;
isLoadingMessages(conversationId: string): boolean;
getTypingUsers(groupId: string): string[];
isMuted(groupId: string): boolean;
getActiveConversation(): string | null;
// 设置状态
setConversations(conversations: Map<string, ConversationResponse>): void;
updateConversation(conversation: ConversationResponse): void;
removeConversation(conversationId: string): void;
setMessages(conversationId: string, messages: MessageResponse[]): void;
addMessage(conversationId: string, message: MessageResponse): void;
updateMessage(conversationId: string, messageId: string, updates: Partial<MessageResponse>): void;
setUnreadCount(total: number, system: number): void;
setSSEConnected(connected: boolean): void;
setCurrentConversation(conversationId: string | null): void;
setLoading(loading: boolean): void;
setLoadingMessages(conversationId: string, loading: boolean): void;
setTypingUsers(groupId: string, users: string[]): void;
setMutedStatus(groupId: string, isMuted: boolean): void;
setInitialized(initialized: boolean): void;
// 订阅机制
subscribe(subscriber: MessageSubscriber): () => void;
notifySubscribers(event: MessageEvent): void;
// 重置
reset(): void;
}
/**
* 消息去重服务接口
*/
export interface IMessageDeduplication {
isMessageProcessed(messageId: string): boolean;
markMessageAsProcessed(messageId: string): void;
cleanupProcessedMessageIds(): void;
}
/**
* 用户缓存服务接口
*/
export interface IUserCacheService {
getSenderInfo(userId: string): Promise<UserDTO | null>;
enrichMessagesWithSenderInfo(
@@ -197,9 +52,6 @@ export interface IUserCacheService {
): void;
}
/**
* 已读回执管理器接口
*/
export interface IReadReceiptManager {
markAsRead(conversationId: string, seq: number): Promise<void>;
markAllAsRead(): Promise<void>;
@@ -210,9 +62,6 @@ export interface IReadReceiptManager {
getPendingReadMap(): Map<string, ReadStateRecord>;
}
/**
* 会话操作接口
*/
export interface IConversationOperations {
createConversation(userId: string): Promise<ConversationResponse | null>;
updateConversation(conversationId: string, updates: Partial<ConversationResponse>): void;
@@ -225,9 +74,6 @@ export interface IConversationOperations {
decrementSystemUnreadCount(count?: number): void;
}
/**
* 消息发送服务接口
*/
export interface IMessageSendService {
sendMessage(
conversationId: string,
@@ -236,9 +82,6 @@ export interface IMessageSendService {
): Promise<MessageResponse | null>;
}
/**
* 消息同步服务接口
*/
export interface IMessageSyncService {
fetchConversations(forceRefresh?: boolean, source?: string): Promise<void>;
loadMoreConversations(): Promise<void>;
@@ -249,9 +92,6 @@ export interface IMessageSyncService {
canLoadMoreConversations(): boolean;
}
/**
* WebSocket 消息处理器接口
*/
export interface IWSMessageHandler {
connect(): void;
disconnect(): void;