Add chats_fetch to find a conversation's chatId - #2
Draft
sebpretzer wants to merge 1 commit into
Draft
sebpretzer wants to merge 1 commit into
sebpretzer wants to merge 1 commit into
Conversation
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
force-pushed
the
chats-fetch
branch
from
October 4, 2026 01:25
d1ccae0 to
39b2c20
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #3 (helper extraction). Follow-up to mattt#251.
messages_fetchcan now be scoped withchatId, but the only way to get one was theisPartOfof messages fetched through the sender-basedparticipantsfilter, which mixes in unrelated chats.chats_fetchfinds the conversation first.Inputs
participants: handles of the other people in the chat (you are never in the list)match:all(default),exactoranyall: the chat includes every participant and may include othersexact: the chat includes exactly those peopleany: the chat includes at least one of themquery: case-insensitive match on the chat name (unnamed chats never match)start/end: chats with messages in the window, parsed the same way asmessages_fetchlimit: default 30Output: a bare array of the
ConversationobjectisPartOfuses, plusdateModified, most recent first. Each@idcan be passed aschatIdtomessages_fetch.Notes
allcounts handles, not people.allandexacttherefore use oneanyclause per participant.[]underallandexact, rather than silently dropping that person. Underanyit is skipped.exactandqueryare checked on the fetched chats, so chats are read in pages of 1024 untillimitis filled or none are left.start/end,dateModifiedis 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.