const pullResp = await api.syncPull();
const serverEvents = pullResp.data.events || [];
const localAll = await getAllProgress();
- const localKeys = new Set(localAll.map(p => p.key));
for (const ev of serverEvents) {
const key = `${ev.group_id}:${ev.op_type}`;
- if (!localKeys.has(key)) {
+ const local = localAll.find(p => p.key === key);
+ if (!local) {
+ // 本地缺失: 直接补入(布尔并集)
await putProgress(ev.group_id, ev.op_type, ev.completed_at, false);
result.pulled++;
result.pulledEvents.push(ev);
+ } else {
+ // 本地已存在: 若云端日期更新(如服务端修正了时区误记),
+ // 用云端日期覆盖本地显示时间, 让首页进度与云端一致(LWW, 只升不降, 按日期比较)
+ const localDate = (local.completed_at || '').slice(0, 10);
+ const serverDate = (ev.completed_at || '').slice(0, 10);
+ if (serverDate > localDate) {
+ await putProgress(ev.group_id, ev.op_type, ev.completed_at, false);
+ result.pulled++;
+ result.pulledEvents.push(ev);
+ }
}
}