fix(core): verify conversation read updates

Replace message-header sequence forwarding with a server-guided read flow for group and private conversations.

Batch read reports conservatively, validate per-conversation results and cursor advancement, and fail with actionable errors when the server does not apply an update.

Add regression coverage for mixed batches, pagination, already-current sessions, malformed responses, and private sequence-domain mismatches.
This commit is contained in:
DrSmoothl committed 2026-07-13 23:01:39 +08:00
1 parent 6f484e06e6
commit 03aec3b052
5 files changed
+456 -51

No files matched your search

+4 -4
View File
@@ -370,7 +370,7 @@ export const actions = [
return failedResponse(RETCODE.BAD_REQUEST, 'group_id does not match message session');
}
await ctx.bridge.apis.message.markGroupRead(meta.targetId, meta.sequence);
await ctx.bridge.apis.message.markGroupRead(meta.targetId);
return okResponse();
},
}),
@@ -392,7 +392,7 @@ export const actions = [
return failedResponse(RETCODE.BAD_REQUEST, 'user_id does not match message session');
}
await ctx.bridge.apis.message.markPrivateRead(meta.targetId, meta.sequence);
await ctx.bridge.apis.message.markPrivateRead(meta.targetId);
return okResponse();
},
}),
@@ -413,9 +413,9 @@ export const actions = [
}
if (meta.isGroup) {
await ctx.bridge.apis.message.markGroupRead(meta.targetId, meta.sequence);
await ctx.bridge.apis.message.markGroupRead(meta.targetId);
} else {
await ctx.bridge.apis.message.markPrivateRead(meta.targetId, meta.sequence);
await ctx.bridge.apis.message.markPrivateRead(meta.targetId);
}
return okResponse();
},
@@ -289,6 +289,34 @@ describe('extended-actions / history accepts negative message_id', () => {
});
});
describe('extended-actions / mark conversation read', () => {
it('uses a group message only to identify the conversation', async () => {
const markGroupRead = vi.fn(async () => undefined);
const bridge = fakeBridge({ apis: { message: { markGroupRead } } });
const ctx = fakeCtx(bridge, {
getMessageMeta: () => fakeMeta({ targetId: 12345, sequence: 42708 }),
});
const res = await makeHandler(ctx).handle('mark_group_msg_as_read', { message_id: 1 });
expect(markGroupRead).toHaveBeenCalledWith(12345);
expect(res).toMatchObject({ status: 'ok', retcode: 0 });
});
it('routes a private message to the C2C read implementation without forwarding its header sequence', async () => {
const markPrivateRead = vi.fn(async () => undefined);
const bridge = fakeBridge({ apis: { message: { markPrivateRead } } });
const ctx = fakeCtx(bridge, {
getMessageMeta: () => fakeMeta({ isGroup: false, targetId: 1787882683, sequence: 42708 }),
});
const res = await makeHandler(ctx).handle('mark_private_msg_as_read', { message_id: 1 });
expect(markPrivateRead).toHaveBeenCalledWith(1787882683);
expect(res).toMatchObject({ status: 'ok', retcode: 0 });
});
});
// ─── Tier 1: nc_get_packet_status / nc_get_rkey ───
describe('extended-actions / nc_get_packet_status', () => {