Fix cross-conversation reply auto-resume
This commit is contained in:
@@ -218,7 +218,7 @@
|
||||
})();
|
||||
const pendingNotesByTarget = new Map();
|
||||
const userMessageIndex = new Map();
|
||||
const expandedOldSessionAgents = new Set();
|
||||
const expandedOldSessionGroups = new Set();
|
||||
document.documentElement.dataset.dividerTime = showAgentDividerTime ? 'show' : 'hide';
|
||||
|
||||
// --- DOM ---
|
||||
@@ -2722,11 +2722,15 @@
|
||||
return Number.isFinite(updatedMs) && updatedMs > 0 && nowMs - updatedMs > OLD_SESSION_COLLAPSE_MS;
|
||||
}
|
||||
|
||||
function splitCollapsedOldSessions(regularSessions, pinnedCount) {
|
||||
if (expandedOldSessionAgents.has(currentAgent)) {
|
||||
return { visibleRegularSessions: regularSessions, hiddenOldSessions: [] };
|
||||
}
|
||||
function getProjectOldSessionCollapseKey(group) {
|
||||
return `project:${getProjectCollapseKey(group)}`;
|
||||
}
|
||||
|
||||
function getUngroupedOldSessionCollapseKey() {
|
||||
return `${normalizeAgent(currentAgent)}:ungrouped`;
|
||||
}
|
||||
|
||||
function splitCollapsedOldSessions(regularSessions, pinnedCount, getCollapseKey = () => '') {
|
||||
const totalCount = pinnedCount + regularSessions.length;
|
||||
if (totalCount <= OLD_SESSION_COLLAPSE_VISIBLE_LIMIT) {
|
||||
return { visibleRegularSessions: regularSessions, hiddenOldSessions: [] };
|
||||
@@ -2738,8 +2742,10 @@
|
||||
const hiddenOldSessions = [];
|
||||
|
||||
regularSessions.forEach((session, index) => {
|
||||
const collapseKey = getCollapseKey(session);
|
||||
const isExpanded = collapseKey && expandedOldSessionGroups.has(collapseKey);
|
||||
const shouldKeepVisible = session.id === currentSessionId || session.isRunning || session.hasUnread || session.waitingOnChildren;
|
||||
const canCollapse = index >= visibleRegularLimit && isOlderThanOldSessionWindow(session, nowMs);
|
||||
const canCollapse = !isExpanded && index >= visibleRegularLimit && isOlderThanOldSessionWindow(session, nowMs);
|
||||
if (canCollapse && !shouldKeepVisible) {
|
||||
hiddenOldSessions.push(session);
|
||||
} else {
|
||||
@@ -2750,17 +2756,17 @@
|
||||
return { visibleRegularSessions, hiddenOldSessions };
|
||||
}
|
||||
|
||||
function createOldSessionLoadMoreButton(hiddenCount) {
|
||||
function createOldSessionLoadMoreButton(hiddenCount, collapseKey, projectName = '') {
|
||||
const button = document.createElement('button');
|
||||
button.type = 'button';
|
||||
button.className = 'session-list-load-more';
|
||||
button.setAttribute('aria-label', `加载更多 ${hiddenCount} 条 7 天前会话`);
|
||||
button.setAttribute('aria-label', `加载更多${projectName ? ` ${projectName}` : ''} ${hiddenCount} 条 7 天前会话`);
|
||||
button.innerHTML = `
|
||||
<span class="session-list-load-more-title">加载更多</span>
|
||||
<span class="session-list-load-more-meta">${hiddenCount} 条 7 天前会话</span>
|
||||
`;
|
||||
button.addEventListener('click', () => {
|
||||
expandedOldSessionAgents.add(currentAgent);
|
||||
if (collapseKey) expandedOldSessionGroups.add(collapseKey);
|
||||
renderSessionList();
|
||||
});
|
||||
return button;
|
||||
@@ -5920,9 +5926,34 @@
|
||||
}
|
||||
|
||||
const { pinnedSessions, regularSessions } = splitPinnedSessions(visibleSessions);
|
||||
const { groups: projectGroups, ungroupedSessions } = groupSessionsByProject(regularSessions);
|
||||
const oldSessionCollapseKeysBySessionId = new Map();
|
||||
projectGroups.forEach((group) => {
|
||||
const oldSessionCollapseKey = getProjectOldSessionCollapseKey(group);
|
||||
group.sessions.forEach((session) => {
|
||||
oldSessionCollapseKeysBySessionId.set(session.id, oldSessionCollapseKey);
|
||||
});
|
||||
});
|
||||
ungroupedSessions.forEach((session) => {
|
||||
oldSessionCollapseKeysBySessionId.set(session.id, getUngroupedOldSessionCollapseKey());
|
||||
});
|
||||
const { visibleRegularSessions, hiddenOldSessions } = isSearchingSessions
|
||||
? { visibleRegularSessions: regularSessions, hiddenOldSessions: [] }
|
||||
: splitCollapsedOldSessions(regularSessions, pinnedSessions.length);
|
||||
: splitCollapsedOldSessions(
|
||||
regularSessions,
|
||||
pinnedSessions.length,
|
||||
(session) => oldSessionCollapseKeysBySessionId.get(session.id) || ''
|
||||
);
|
||||
const hiddenOldSessionCountsByKey = new Map();
|
||||
hiddenOldSessions.forEach((session) => {
|
||||
const oldSessionCollapseKey = oldSessionCollapseKeysBySessionId.get(session.id);
|
||||
if (!oldSessionCollapseKey) return;
|
||||
hiddenOldSessionCountsByKey.set(
|
||||
oldSessionCollapseKey,
|
||||
(hiddenOldSessionCountsByKey.get(oldSessionCollapseKey) || 0) + 1
|
||||
);
|
||||
});
|
||||
const visibleRegularSessionIds = new Set(visibleRegularSessions.map((session) => session.id));
|
||||
if (pinnedSessions.length > 0) {
|
||||
const pinnedGroupEl = document.createElement('section');
|
||||
pinnedGroupEl.className = 'session-project-group session-pinned-group';
|
||||
@@ -5941,9 +5972,11 @@
|
||||
sessionList.appendChild(pinnedGroupEl);
|
||||
}
|
||||
|
||||
const { groups: projectGroups, ungroupedSessions } = groupSessionsByProject(visibleRegularSessions);
|
||||
projectGroups.forEach((group, groupIndex) => {
|
||||
const groupKey = getProjectCollapseKey(group);
|
||||
const oldSessionCollapseKey = getProjectOldSessionCollapseKey(group);
|
||||
const visibleGroupSessions = group.sessions.filter((session) => visibleRegularSessionIds.has(session.id));
|
||||
const hiddenGroupOldSessionCount = hiddenOldSessionCountsByKey.get(oldSessionCollapseKey) || 0;
|
||||
const isCollapsed = !isSearchingSessions && collapsedProjectKeys.has(groupKey);
|
||||
const hasActiveSession = group.sessions.some((session) => session.id === currentSessionId);
|
||||
const hasUnreadSession = group.sessions.some((session) => session.hasUnread);
|
||||
@@ -5972,9 +6005,12 @@
|
||||
groupBody.id = groupBodyId;
|
||||
groupBody.className = 'session-project-sessions';
|
||||
groupBody.hidden = isCollapsed;
|
||||
for (const s of group.sessions) {
|
||||
for (const s of visibleGroupSessions) {
|
||||
groupBody.appendChild(createSessionListItem(s));
|
||||
}
|
||||
if (hiddenGroupOldSessionCount > 0) {
|
||||
groupBody.appendChild(createOldSessionLoadMoreButton(hiddenGroupOldSessionCount, oldSessionCollapseKey, group.name));
|
||||
}
|
||||
groupEl.appendChild(groupBody);
|
||||
|
||||
header.querySelector('.session-project-toggle').addEventListener('click', () => {
|
||||
@@ -5989,12 +6025,16 @@
|
||||
sessionList.appendChild(groupEl);
|
||||
});
|
||||
|
||||
for (const s of ungroupedSessions) {
|
||||
const ungroupedCollapseKey = getUngroupedOldSessionCollapseKey();
|
||||
const visibleUngroupedSessions = ungroupedSessions.filter((session) => visibleRegularSessionIds.has(session.id));
|
||||
const hiddenUngroupedOldSessionCount = hiddenOldSessionCountsByKey.get(ungroupedCollapseKey) || 0;
|
||||
|
||||
for (const s of visibleUngroupedSessions) {
|
||||
sessionList.appendChild(createSessionListItem(s));
|
||||
}
|
||||
|
||||
if (hiddenOldSessions.length > 0) {
|
||||
sessionList.appendChild(createOldSessionLoadMoreButton(hiddenOldSessions.length));
|
||||
if (hiddenUngroupedOldSessionCount > 0) {
|
||||
sessionList.appendChild(createOldSessionLoadMoreButton(hiddenUngroupedOldSessionCount, ungroupedCollapseKey));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user