fix(app): 대화 screen pages back without limit, shows edits and drops stale answers
- history_query takes item cursors (before / from) ordered by time, source and id, so paging never skips or repeats an item and has no 2,000 item ceiling - live refresh re-reads the window from the oldest item shown and compares whole items, so an edited message is redrawn - answers to requests made before a filter change, and live answers older than the newest one asked, are dropped Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
107
app/ui/app.js
107
app/ui/app.js
@@ -446,10 +446,16 @@ function conversationScreen() {
|
||||
const find = h("input", { type: "text", placeholder: "찾기 (말, 답, 생각)", style: "max-width:220px" });
|
||||
const live = h("input", { type: "checkbox", class: "switch", checked: true });
|
||||
const open = new Set(); // traces the user opened stay open across refreshes
|
||||
let expandAll = false, limit = 200, sig = null;
|
||||
// The window shown: every item from the cursor `from` on, re-read live (at most PAGE_MAX), plus
|
||||
// `older` pages that no longer fit it. Each filter change starts a new epoch; answers from an
|
||||
// earlier epoch, and live answers older than the newest one asked, are dropped.
|
||||
const PAGE = 200, PAGE_MAX = 2000;
|
||||
const cursorOf = (i) => ({ at: i.at, key: i.key });
|
||||
let expandAll = false, sig = null, shown = [], older = [], from = null, hasOlder = false, missing = false;
|
||||
let epoch = 0, liveSeq = 0, first = true;
|
||||
const box = h("div", { class: "talk" });
|
||||
const summary = h("div", { class: "small muted" });
|
||||
const more = h("button", { class: "btn", hidden: true, onclick: () => { limit += 200; load(true); } }, "이전 기록 더 보기");
|
||||
const more = h("button", { class: "btn", hidden: true, onclick: () => loadOlder() }, "이전 기록 더 보기");
|
||||
|
||||
const fill = (sel, list, label) => {
|
||||
const key = JSON.stringify(list);
|
||||
@@ -486,37 +492,78 @@ function conversationScreen() {
|
||||
h("div", { class: "text" }, i.text));
|
||||
}
|
||||
|
||||
async function load(keepTop = false) {
|
||||
function filters() {
|
||||
const since = day.value ? new Date(day.value + "T00:00:00").getTime() / 1000 : null;
|
||||
return { said: said.checked, answered: answered.checked, thought: thought.checked,
|
||||
via: via.value || null, person: person.value || null, channel: channel.value || null, find: find.value || null,
|
||||
since, until: since == null ? null : since + 86400 };
|
||||
}
|
||||
|
||||
function render(keepTop = false) {
|
||||
const items = older.concat(shown);
|
||||
// The whole items, so an edited message or a changed answer is redrawn too.
|
||||
const s = JSON.stringify([items, expandAll, hasOlder, missing]);
|
||||
if (s === sig) return;
|
||||
sig = s;
|
||||
const stick = box.scrollTop + box.clientHeight >= box.scrollHeight - 30, fromBottom = box.scrollHeight - box.scrollTop;
|
||||
const kids = [];
|
||||
let lastDay = null;
|
||||
for (const i of items) {
|
||||
const d = dayOf(i.at);
|
||||
if (d !== lastDay) { kids.push(h("div", { class: "day" }, d)); lastDay = d; }
|
||||
kids.push(item(i));
|
||||
}
|
||||
box.replaceChildren(...(kids.length ? kids : [h("div", { class: "muted" },
|
||||
missing ? "아직 대화 기록이 없습니다. 서비스를 켜고 자비스와 이야기하면 여기에 나옵니다." : "조건에 맞는 기록이 없습니다.")]));
|
||||
more.hidden = !hasOlder;
|
||||
const n = (t) => items.filter((i) => i.type === t).length;
|
||||
summary.textContent = `사람 말 ${n("said")} · 자비스 말 ${n("answered")} · 생각 ${n("thought")}` + (hasOlder ? " (이전 기록 더 있음)" : "");
|
||||
if (keepTop) box.scrollTop = box.scrollHeight - fromBottom;
|
||||
else if (stick || first) box.scrollTop = box.scrollHeight;
|
||||
first = false;
|
||||
}
|
||||
|
||||
function lists(r) {
|
||||
load.channels = r.channels;
|
||||
fill(person, r.people, (p) => `${p.name || p.id}`);
|
||||
fill(channel, r.channels, channelLabel);
|
||||
}
|
||||
|
||||
/** The window from `from` on (the newest page at first), re-read on every live tick. */
|
||||
async function load() {
|
||||
const ep = epoch, my = ++liveSeq;
|
||||
try {
|
||||
const since = day.value ? new Date(day.value + "T00:00:00").getTime() / 1000 : null;
|
||||
const r = await api("history_query", { said: said.checked, answered: answered.checked, thought: thought.checked,
|
||||
via: via.value || null, person: person.value || null, channel: channel.value || null, find: find.value || null,
|
||||
since, until: since == null ? null : since + 86400, limit });
|
||||
load.channels = r.channels;
|
||||
fill(person, r.people, (p) => `${p.name || p.id}`);
|
||||
fill(channel, r.channels, channelLabel);
|
||||
const s = JSON.stringify([r.items.map((i) => i.key + ":" + (i.text || i.answer || "").length), expandAll, r.more]);
|
||||
if (s === sig) return;
|
||||
sig = s;
|
||||
const stick = box.scrollTop + box.clientHeight >= box.scrollHeight - 30, fromBottom = box.scrollHeight - box.scrollTop;
|
||||
const kids = [];
|
||||
let lastDay = null;
|
||||
for (const i of r.items) {
|
||||
const d = dayOf(i.at);
|
||||
if (d !== lastDay) { kids.push(h("div", { class: "day" }, d)); lastDay = d; }
|
||||
kids.push(item(i));
|
||||
}
|
||||
box.replaceChildren(...(kids.length ? kids : [h("div", { class: "muted" },
|
||||
r.missing ? "아직 대화 기록이 없습니다. 서비스를 켜고 자비스와 이야기하면 여기에 나옵니다." : "조건에 맞는 기록이 없습니다.")]));
|
||||
more.hidden = !r.more;
|
||||
const n = (t) => r.items.filter((i) => i.type === t).length;
|
||||
summary.textContent = `사람 말 ${n("said")} · 자비스 말 ${n("answered")} · 생각 ${n("thought")}` + (r.more ? ` (최근 ${limit}개까지)` : "");
|
||||
if (keepTop) box.scrollTop = box.scrollHeight - fromBottom;
|
||||
else if (stick || !load.done) box.scrollTop = box.scrollHeight;
|
||||
load.done = true;
|
||||
const r = await api("history_query", { ...filters(), ...(from ? { from, limit: PAGE_MAX } : { limit: PAGE }) });
|
||||
if (ep !== epoch || my !== liveSeq) return;
|
||||
lists(r);
|
||||
missing = !!r.missing;
|
||||
if (!from) hasOlder = r.more;
|
||||
else if (r.more) { older = []; hasOlder = true; } // more new ones than a window holds: page back from them
|
||||
shown = r.items;
|
||||
if (shown.length) from = cursorOf(shown[0]);
|
||||
render();
|
||||
} catch (e) { fail(e); }
|
||||
}
|
||||
const reload = () => { limit = 200; sig = null; load.done = false; load(); };
|
||||
|
||||
/** The page before the oldest item shown; it joins the live window while that stays under PAGE_MAX. */
|
||||
async function loadOlder() {
|
||||
const oldest = older[0] || shown[0];
|
||||
if (!oldest) return;
|
||||
const ep = epoch;
|
||||
try {
|
||||
const r = await api("history_query", { ...filters(), before: cursorOf(oldest), limit: PAGE });
|
||||
if (ep !== epoch) return;
|
||||
++liveSeq; // a live answer asked with the old window would drop this page
|
||||
hasOlder = r.more;
|
||||
if (!older.length && shown.length + r.items.length <= PAGE_MAX) {
|
||||
shown = r.items.concat(shown);
|
||||
if (shown.length) from = cursorOf(shown[0]);
|
||||
} else older = r.items.concat(older);
|
||||
render(true);
|
||||
} catch (e) { fail(e); }
|
||||
}
|
||||
|
||||
const reload = () => { epoch++; sig = null; shown = []; older = []; from = null; hasOlder = false; first = true; load(); };
|
||||
for (const el of [said, answered, thought, via, person, channel, day]) el.addEventListener("change", reload);
|
||||
find.addEventListener("input", () => { clearTimeout(find.t); find.t = setTimeout(reload, 300); });
|
||||
const view = h("div", {}, h("h1", {}, "대화"),
|
||||
|
||||
Reference in New Issue
Block a user