fix: 优化云同步功能,自动去除掉非首个空会话,避免多个空会话在中间,更方便管理

This commit is contained in:
织梦人 2024-09-06 20:59:53 +08:00
parent 6dc868154d
commit 5ae4921ee0
1 changed files with 11 additions and 0 deletions

View File

@ -131,10 +131,21 @@ const MergeStates: StateMerger = {
const finalIds: Record<string, any> = {}; const finalIds: Record<string, any> = {};
localState.sessions = localState.sessions.filter((localSession) => { localState.sessions = localState.sessions.filter((localSession) => {
// 去除掉重复的会话
if (finalIds[localSession.id]) { if (finalIds[localSession.id]) {
return false; return false;
} }
finalIds[localSession.id] = true; finalIds[localSession.id] = true;
// 去除掉非首个空会话,避免多个空会话在中间,不方便管理
if (
localSession.messages.length === 0 &&
localSession != localState.sessions[0]
) {
return false;
}
// 去除云端删除并且删除时间小于本地修改时间的会话
return ( return (
(remoteDeletedSessionIds[localSession.id] || -1) <= (remoteDeletedSessionIds[localSession.id] || -1) <=
localSession.lastUpdate localSession.lastUpdate