feat(navigation): add schedule tab and stack navigator
Add new ScheduleTab to main navigation with ScheduleStackNavigator for managing course schedule screens. Includes CourseDetailScreen with modal presentation. Also exports scheduleService and related types for the new schedule feature. fix(message): add group_id parameter to invite and request handlers Pass group_id from extra_data when calling respondInvite and reviewJoinRequest APIs, as the backend now requires this parameter. refactor(message): extract mergeMessagesById helper method Centralize message merging logic into a reusable private method to avoid duplication and ensure consistent message deduplication behavior.
This commit is contained in:
@@ -231,6 +231,19 @@ class MessageManager {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 按 message_id 合并消息并按 seq 排序。
|
||||
* 后者覆盖前者,可用来吸收更完整的同 ID 消息体(例如服务端回包/SSE)。
|
||||
*/
|
||||
private mergeMessagesById(base: MessageResponse[], incoming: MessageResponse[]): MessageResponse[] {
|
||||
if (incoming.length === 0) return base;
|
||||
const merged = new Map<string, MessageResponse>();
|
||||
[...base, ...incoming].forEach(msg => {
|
||||
merged.set(String(msg.id), msg);
|
||||
});
|
||||
return Array.from(merged.values()).sort((a, b) => a.seq - b.seq);
|
||||
}
|
||||
|
||||
private updateConversationList() {
|
||||
// 会话排序:置顶优先,再按最后消息时间排序
|
||||
const list = Array.from(this.state.conversations.values()).sort((a, b) => {
|
||||
@@ -637,10 +650,10 @@ class MessageManager {
|
||||
|
||||
// 2. 立即更新内存中的消息列表(关键:确保ChatScreen能立即看到)
|
||||
const existingMessages = this.state.messagesMap.get(normalizedConversationId) || [];
|
||||
const messageExists = existingMessages.some(m => m.id === id);
|
||||
const messageExists = existingMessages.some(m => String(m.id) === String(id));
|
||||
|
||||
if (!messageExists) {
|
||||
const updatedMessages = [...existingMessages, newMessage].sort((a, b) => a.seq - b.seq);
|
||||
const updatedMessages = this.mergeMessagesById(existingMessages, [newMessage]);
|
||||
this.state.messagesMap.set(normalizedConversationId, updatedMessages);
|
||||
|
||||
// 3. 立即通知订阅者(关键:解决竞态条件)
|
||||
@@ -1115,12 +1128,7 @@ class MessageManager {
|
||||
|
||||
try {
|
||||
const mergeMessages = (base: MessageResponse[], incoming: MessageResponse[]): MessageResponse[] => {
|
||||
if (incoming.length === 0) return base;
|
||||
const merged = new Map<string, MessageResponse>();
|
||||
[...base, ...incoming].forEach(msg => {
|
||||
merged.set(String(msg.id), msg);
|
||||
});
|
||||
return Array.from(merged.values()).sort((a, b) => a.seq - b.seq);
|
||||
return this.mergeMessagesById(base, incoming);
|
||||
};
|
||||
|
||||
// 1. 先从本地数据库加载(确保立即有数据展示)
|
||||
@@ -1366,7 +1374,7 @@ class MessageManager {
|
||||
|
||||
// 合并到现有消息
|
||||
const existingMessages = this.state.messagesMap.get(conversationId) || [];
|
||||
const mergedMessages = [...formattedMessages, ...existingMessages].sort((a, b) => a.seq - b.seq);
|
||||
const mergedMessages = this.mergeMessagesById(existingMessages, formattedMessages);
|
||||
this.state.messagesMap.set(conversationId, mergedMessages);
|
||||
|
||||
this.notifySubscribers({
|
||||
@@ -1402,7 +1410,7 @@ class MessageManager {
|
||||
|
||||
// 合并消息
|
||||
const existingMessages = this.state.messagesMap.get(conversationId) || [];
|
||||
const mergedMessages = [...serverMessages, ...existingMessages].sort((a, b) => a.seq - b.seq);
|
||||
const mergedMessages = this.mergeMessagesById(existingMessages, serverMessages);
|
||||
this.state.messagesMap.set(conversationId, mergedMessages);
|
||||
|
||||
this.notifySubscribers({
|
||||
@@ -1481,7 +1489,7 @@ class MessageManager {
|
||||
status: 'normal',
|
||||
};
|
||||
|
||||
const updatedMessages = [...existingMessages, newMessage].sort((a, b) => a.seq - b.seq);
|
||||
const updatedMessages = this.mergeMessagesById(existingMessages, [newMessage]);
|
||||
this.state.messagesMap.set(conversationId, updatedMessages);
|
||||
|
||||
// 关键:立即广播消息列表更新,确保 ChatScreen 立刻显示新消息
|
||||
|
||||
Reference in New Issue
Block a user