- Remove MessageStateManager wrapper layer in favor of direct zustand store - Move service modules to services/ subdirectory (ConversationOperations, MessageDeduplication, MessageSendService, MessageSyncService, ReadReceiptManager, UserCacheService, WSMessageHandler) - Add new zustand-based store with subscriptionManager for event handling - Introduce React hooks for message state (useConversations, useMessages, useUnreadCount, etc.) - Update exports in index.ts to reflect new module structure - Deprecate messageManager.ts entry point in favor of message/index.ts - Maintain backward compatibility with existing MessageManager API
110 lines
2.5 KiB
TypeScript
110 lines
2.5 KiB
TypeScript
/**
|
|
* 消息模块统一导出
|
|
*
|
|
* 重构说明:
|
|
* - 移除了 MessageStateManager 包装层
|
|
* - 直接使用 zustand store 进行状态管理
|
|
* - 服务层移至 services/ 目录
|
|
* - 新增 hooks.ts 封装常用逻辑
|
|
*/
|
|
|
|
// ==================== 主管理器 ====================
|
|
export { messageManager, MessageManager } from './MessageManager';
|
|
|
|
// ==================== 状态管理 ====================
|
|
export {
|
|
useMessageStore,
|
|
subscriptionManager,
|
|
normalizeConversationId,
|
|
mergeMessagesById,
|
|
notifySubscribers,
|
|
subscribeToMessages,
|
|
} from './store';
|
|
export type { MessageState, MessageActions, MessageStore } from './store';
|
|
|
|
// ==================== 类型导出 ====================
|
|
// 从 types.ts 导出所有类型
|
|
export type {
|
|
MessageEventType,
|
|
MessageEvent,
|
|
MessageSubscriber,
|
|
MessageManagerState,
|
|
ReadStateRecord,
|
|
MessageManagerConversationListDeps,
|
|
HandleNewMessageOptions,
|
|
// 服务接口类型(保留向后兼容,但服务层已不再使用)
|
|
IMessageStateManager,
|
|
IMessageDeduplication,
|
|
IUserCacheService,
|
|
IReadReceiptManager,
|
|
IConversationOperations,
|
|
IMessageSendService,
|
|
IMessageSyncService,
|
|
IWSMessageHandler,
|
|
} from './types';
|
|
|
|
// ==================== 常量导出 ====================
|
|
export {
|
|
READ_STATE_PROTECTION_DELAY,
|
|
PROCESSED_MESSAGE_ID_EXPIRY,
|
|
PROCESSED_MESSAGE_ID_MAX_SIZE,
|
|
MAX_FLUSH_ITERATIONS,
|
|
CONVERSATION_REFRESH_THROTTLE,
|
|
MIN_RECONNECT_SYNC_INTERVAL,
|
|
} from './constants';
|
|
|
|
// ==================== 服务导出 ====================
|
|
export {
|
|
// 消息去重服务
|
|
MessageDeduplication,
|
|
messageDeduplication,
|
|
|
|
// 用户缓存服务
|
|
UserCacheService,
|
|
userCacheService,
|
|
|
|
// 已读回执管理器
|
|
ReadReceiptManager,
|
|
|
|
// 会话操作服务
|
|
ConversationOperations,
|
|
|
|
// 消息发送服务
|
|
MessageSendService,
|
|
|
|
// 消息同步服务
|
|
MessageSyncService,
|
|
|
|
// WebSocket 消息处理器
|
|
WSMessageHandler,
|
|
} from './services';
|
|
|
|
// ==================== Hooks 导出 ====================
|
|
export {
|
|
// 会话相关
|
|
useConversations,
|
|
useConversation,
|
|
useCreateConversation,
|
|
useUpdateConversation,
|
|
useActiveConversation,
|
|
|
|
// 消息相关
|
|
useMessages,
|
|
useSendMessage,
|
|
useMarkAsRead,
|
|
|
|
// 未读数相关
|
|
useUnreadCount,
|
|
useSystemUnreadCount,
|
|
|
|
// 群聊相关
|
|
useGroupTyping,
|
|
useGroupMuted,
|
|
|
|
// 通用
|
|
useMessageManager,
|
|
} from './hooks';
|
|
|
|
// ==================== 默认导出 ====================
|
|
export { default } from './MessageManager';
|