Skip to content

Add chats_fetch to find a conversation's chatId - #2

Draft
sebpretzer wants to merge 1 commit into
extract-message-helpersfrom
chats-fetch
Draft

sebpretzer wants to merge 1 commit into
extract-message-helpersfrom
chats-fetch

Conversation

@sebpretzer

@sebpretzer sebpretzer commented Oct 3, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #3 (helper extraction). Follow-up to mattt#251.

messages_fetch can now be scoped with chatId, but the only way to get one was the isPartOf of messages fetched through the sender-based participants filter, which mixes in unrelated chats. chats_fetch finds the conversation first.

Inputs

  • participants: handles of the other people in the chat (you are never in the list)
  • match: all (default), exact or any
    • all: the chat includes every participant and may include others
    • exact: the chat includes exactly those people
    • any: the chat includes at least one of them
  • query: case-insensitive match on the chat name (unnamed chats never match)
  • start / end: chats with messages in the window, parsed the same way as messages_fetch
  • limit: default 30

Output: a bare array of the Conversation object isPartOf uses, plus dateModified, most recent first. Each @id can be passed as chatId to messages_fetch.

Notes

  • Each participant is resolved to its own set of handles. One handle string can match several (with and without a country code), and Madrid's all counts handles, not people. all and exact therefore use one any clause per participant.
  • A participant that resolves to no handle returns [] under all and exact, rather than silently dropping that person. Under any it is skipped.
  • exact and query are checked on the fetched chats, so chats are read in pages of 1024 until limit is filled or none are left.
  • With start/end, dateModified is the latest message within the window (Madrid computes it over the filtered messages).

Testing: builds clean in Debug. Not yet verified against a real chat.db.

messages_fetch accepts a chatId, but the only way to learn one was the
isPartOf of messages fetched through the sender-based participants
filter, which mixes in unrelated chats. chats_fetch finds conversations
by participants, name or activity window and returns the same
Conversation object as isPartOf, plus dateModified.

Each participant is resolved to its own set of handles, since one handle
string can match several (with and without a country code). match
defaults to all: the chat includes each participant and may include
others. any needs at least one of them, and exact also requires that no
one else is in the chat. A participant that resolves to no handle
returns no chats under all and exact.

exact and the name query are checked on the fetched chats, so chats are
read in pages until the limit is filled or none are left.
@sebpretzer
sebpretzer changed the base branch from main to extract-message-helpers October 4, 2026 01:25
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