fix(frontend): 修复 TypeScript 类型错误,与后端 API 响应结构对齐
- 修复 UserDTO 类型定义,字段改为非 nullable 类型 - 修复 PostMapper 使用正确的 snake_case 字段名 - 修复 UserMapper 移除不存在的 is_blocked 和 updated_at 字段 - 修复 MessageMapper 使用 segments 替代已移除的字段 - 修复 MessageSyncService 正确处理 API 响应类型 - 修复 LocalDataSource SQLite 参数类型问题 - 修复导航相关类型错误 - 修复 PostDetailScreen 和 EditProfileScreen 的 null/undefined 类型不匹配
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
import { messageService } from '../../services/messageService';
|
||||
import { messageRepository } from '../../data/repositories/MessageRepository';
|
||||
import type { Message, Conversation } from '../../core/entities/Message';
|
||||
import type { ConversationResponse, MessageResponse } from '../../types/dto';
|
||||
import type { ConversationListResponse, MessageListResponse } from '../../types/dto';
|
||||
|
||||
export interface SyncOptions {
|
||||
force?: boolean;
|
||||
@@ -32,8 +32,8 @@ export class MessageSyncService {
|
||||
this.syncingConversations = true;
|
||||
|
||||
try {
|
||||
const response = await messageService.getConversations();
|
||||
const conversations = this.mapConversations(response);
|
||||
const response: ConversationListResponse = await messageService.getConversations();
|
||||
const conversations = this.mapConversations(response.list || []);
|
||||
return conversations;
|
||||
} catch (error) {
|
||||
console.error('[MessageSyncService] Failed to sync conversations:', error);
|
||||
@@ -59,10 +59,12 @@ export class MessageSyncService {
|
||||
try {
|
||||
const lastSeq = options.lastSeq ?? await messageRepository.getMaxSeq(conversationId);
|
||||
|
||||
const response = await messageService.getMessages(conversationId, {
|
||||
after_seq: lastSeq,
|
||||
limit: 50,
|
||||
});
|
||||
const response: MessageListResponse = await messageService.getMessages(
|
||||
conversationId,
|
||||
lastSeq,
|
||||
undefined,
|
||||
50
|
||||
);
|
||||
|
||||
const messages = this.mapMessages(response.messages || []);
|
||||
|
||||
@@ -73,7 +75,7 @@ export class MessageSyncService {
|
||||
return {
|
||||
conversations: [],
|
||||
messages,
|
||||
hasMore: response.has_more || false,
|
||||
hasMore: messages.length >= 50,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('[MessageSyncService] Failed to sync messages:', error);
|
||||
@@ -89,10 +91,12 @@ export class MessageSyncService {
|
||||
limit: number = 20
|
||||
): Promise<Message[]> {
|
||||
try {
|
||||
const response = await messageService.getMessages(conversationId, {
|
||||
before_seq: beforeSeq,
|
||||
limit,
|
||||
});
|
||||
const response: MessageListResponse = await messageService.getMessages(
|
||||
conversationId,
|
||||
undefined,
|
||||
beforeSeq,
|
||||
limit
|
||||
);
|
||||
|
||||
const messages = this.mapMessages(response.messages || []);
|
||||
|
||||
@@ -122,31 +126,45 @@ export class MessageSyncService {
|
||||
return messageRepository.getMessagesBeforeSeq(conversationId, beforeSeq, limit);
|
||||
}
|
||||
|
||||
private mapConversations(response: ConversationResponse[]): Conversation[] {
|
||||
return response.map(conv => ({
|
||||
private mapConversations(list: ConversationListResponse['list']): Conversation[] {
|
||||
return list.map(conv => ({
|
||||
id: conv.id,
|
||||
type: conv.type || 'private',
|
||||
isPinned: conv.isPinned || false,
|
||||
lastSeq: conv.lastSeq || conv.last_seq || 0,
|
||||
lastMessageAt: conv.lastMessageAt || conv.last_message_at || new Date().toISOString(),
|
||||
unreadCount: conv.unreadCount || conv.unread_count || 0,
|
||||
participants: conv.participants || [],
|
||||
group: conv.group,
|
||||
createdAt: conv.createdAt || conv.created_at || new Date().toISOString(),
|
||||
updatedAt: conv.updatedAt || conv.updated_at || new Date().toISOString(),
|
||||
isPinned: conv.is_pinned || false,
|
||||
lastSeq: conv.last_seq || 0,
|
||||
lastMessageAt: conv.last_message_at || new Date().toISOString(),
|
||||
unreadCount: conv.unread_count || 0,
|
||||
participants: (conv.participants || []).map(p => ({
|
||||
id: p.id,
|
||||
username: p.username,
|
||||
avatar: p.avatar || undefined,
|
||||
nickname: p.nickname,
|
||||
})),
|
||||
group: conv.group ? {
|
||||
id: String(conv.group.id),
|
||||
name: conv.group.name,
|
||||
avatar: conv.group.avatar,
|
||||
} : undefined,
|
||||
createdAt: conv.created_at || new Date().toISOString(),
|
||||
updatedAt: conv.updated_at || new Date().toISOString(),
|
||||
}));
|
||||
}
|
||||
|
||||
private mapMessages(response: MessageResponse[]): Message[] {
|
||||
return response.map(msg => ({
|
||||
private mapMessages(messages: MessageListResponse['messages']): Message[] {
|
||||
return messages.map(msg => ({
|
||||
id: msg.id,
|
||||
conversationId: msg.conversationId || msg.conversation_id || '',
|
||||
senderId: msg.senderId || msg.sender_id || '',
|
||||
seq: msg.seq || 0,
|
||||
conversationId: msg.conversation_id,
|
||||
senderId: msg.sender_id,
|
||||
seq: msg.seq,
|
||||
segments: msg.segments || [],
|
||||
createdAt: msg.createdAt || msg.created_at || new Date().toISOString(),
|
||||
createdAt: msg.created_at,
|
||||
status: msg.status || 'normal',
|
||||
sender: msg.sender,
|
||||
sender: msg.sender ? {
|
||||
id: msg.sender.id,
|
||||
username: msg.sender.username,
|
||||
avatar: msg.sender.avatar || undefined,
|
||||
nickname: msg.sender.nickname,
|
||||
} : undefined,
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user