Skip to content

GET /fmsg: list most recently arrived first, so a fresh add-to comes first - #66

Merged
markmnl merged 1 commit into
mainfrom
list-order-by-arrival
Nov 9, 2026
Merged

markmnl merged 1 commit into
mainfrom
list-order-by-arrival

Conversation

@markmnl

@markmnl markmnl commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Problem

GET /fmsg ordered the inbox by message id. When someone adds an identity to an older message, it stays at its original position, far below newer messages. A client reading the latest page, whether a person or an agent checking for new mail, never sees it.

Change

The inbox is now ordered by when each message arrived for that identity:

  • the message's time_sent, where the identity is in msg_to;
  • the time_added of any add-to batch that added the identity;
  • whichever of these is latest.

Ties fall back to id descending.

  • Adding someone else doesn't move the message for its other recipients.
  • Visibility, the trash filter and the response shape are unchanged. Only the order changes.
  • The query collects arrivals from msg_to and msg_add_to/msg_add_to_batch for the identity first (both use the existing lower(addr) indexes), then joins msg.
  • The README's GET /fmsg section describes the new order.

Tests

TestListOrdersByArrival covers:

  • a message aged an hour, plus newer ones;
  • after the add-to, the added recipient sees that message first, including across limit/offset pages;
  • the original recipient's order doesn't change.

It fails on main and passes with the change. The full go test ./... passes against Postgres 17 with fmsgd's dd.sql.

🤖 Generated with Claude Code

…first

The inbox was ordered by message id, so an older message an identity was
just added to sat at its original position, far below newer messages, and
clients scanning the latest page missed it. Order by when the message
arrived for that identity: the later of its send time (as a recipient) and
the time_added of any add-to batch that added the identity. Ties fall back
to id descending.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@markmnl
markmnl merged commit 3f285c6 into main Nov 9, 2026
1 check passed
@markmnl
markmnl deleted the list-order-by-arrival branch November 9, 2026 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant