Problem
tgcli messages list --after-id <N> returns an empty list even when the chat has messages newer than N.
Found on tgcli 2.2.3 (Homebrew), --source live, chat me (Saved Messages):
# newest messages in the chat: 501195, 501004, 500803, 500802, 500673, ...
tgcli --json messages list --chat me --source live --limit 5
# -> [501195, 501004, 500803, 500802, 500673]
tgcli --json messages list --chat me --source live --after-id 500673
tgcli --json messages list --chat me --source live --after-id 500673 --limit 2
tgcli --json messages list --chat me --source live --after-id 500673 --limit 10
# -> "messages": [], "hasMore": false
tgcli --json messages list --chat me --source live --after-id 501000 --limit 5
# -> "messages": [], "hasMore": false (expected 501004, 501195)
--before-id works: --before-id 501004 --limit 3 returns [500803, 500802, 500673], hasMore: true.
Where to look
getMessagesByChannelId in telegram-client.js (same code on main after v2.2.3). With afterId set, it calls iterHistory with reverse: true and minId, but no offset:
const iterOptions = {
limit: effectiveLimit,
chunkSize: Math.min(effectiveLimit, 100),
reverse: useAfterIdPagination ? true : reverse,
};
if (effectiveMinId) {
iterOptions.minId = effectiveMinId;
}
Hypothesis, not verified: when mtcute iterates in reverse without an offset, it starts from the wrong end, so every message gets filtered out by minId. Passing offset: { id: afterId + 1, date: 0 } (plus a matching addOffset) may fix it.
Workaround
Page backwards with --before-id until reaching the known id.
Acceptance
messages list --after-id N returns messages with id > N, oldest first or documented order, respecting --limit
hasMore / next cursor lets a caller page forward through everything newer than N
- a test covers
--after-id against a chat with more than --limit newer messages
Problem
tgcli messages list --after-id <N>returns an empty list even when the chat has messages newer thanN.Found on tgcli 2.2.3 (Homebrew),
--source live, chatme(Saved Messages):--before-idworks:--before-id 501004 --limit 3returns[500803, 500802, 500673],hasMore: true.Where to look
getMessagesByChannelIdintelegram-client.js(same code onmainafter v2.2.3). WithafterIdset, it callsiterHistorywithreverse: trueandminId, but nooffset:Hypothesis, not verified: when mtcute iterates in reverse without an offset, it starts from the wrong end, so every message gets filtered out by
minId. Passingoffset: { id: afterId + 1, date: 0 }(plus a matchingaddOffset) may fix it.Workaround
Page backwards with
--before-iduntil reaching the known id.Acceptance
messages list --after-id Nreturns messages with id > N, oldest first or documented order, respecting--limithasMore/ next cursor lets a caller page forward through everything newer than N--after-idagainst a chat with more than--limitnewer messages