refactor(core): introduce EventBus and refactor store infrastructure
- Add EventBus for decoupled event-driven communication between services - Add EventSubscriber component for centralized event handling - Add requestDedupe utility for shared request deduplication - Refactor api/wsService to use eventBus instead of direct router navigation - Extract MessageMapper.toCachedMessages for consistent message mapping - Remove deprecated BaseManager and CacheBus classes - Improve @mention rendering with memberMap support in segment rendering - Update hooks to use useRef instead of useState for fetch tracking
This commit is contained in:
@@ -12,6 +12,7 @@ import type {
|
||||
MessageResponse,
|
||||
UserDTO,
|
||||
} from '../../types/dto';
|
||||
import type { CachedMessage } from '../../database/types/CachedMessage';
|
||||
|
||||
// 数据库消息记录类型
|
||||
export interface MessageDbRecord {
|
||||
@@ -180,4 +181,23 @@ export class MessageMapper {
|
||||
avatar: sender.avatar || undefined,
|
||||
};
|
||||
}
|
||||
|
||||
static toCachedMessage(apiMessage: any, conversationId?: string): CachedMessage {
|
||||
return {
|
||||
id: apiMessage.id,
|
||||
conversationId: apiMessage.conversation_id || conversationId || '',
|
||||
senderId: apiMessage.sender_id,
|
||||
content: apiMessage.content,
|
||||
type: apiMessage.type || 'text',
|
||||
isRead: apiMessage.is_read || false,
|
||||
createdAt: apiMessage.created_at,
|
||||
seq: apiMessage.seq,
|
||||
status: apiMessage.status || 'normal',
|
||||
segments: apiMessage.segments,
|
||||
};
|
||||
}
|
||||
|
||||
static toCachedMessages(apiMessages: any[], conversationId?: string): CachedMessage[] {
|
||||
return apiMessages.map(m => this.toCachedMessage(m, conversationId));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user