From 94ae8baaa23ddd5a4b8404c6ea3a87086f4ca5c7 Mon Sep 17 00:00:00 2001 From: Seb Pretzer <24555985+sebpretzer@users.noreply.github.com> Date: Sun, 27 Sep 2026 14:40:40 -0500 Subject: [PATCH] Add chatId to messages_fetch to scope a fetch to one conversation isPartOf reports each message's conversation @id, but nothing accepted it back. chatId maps to Madrid's chatID predicate and composes with the other filters, so chatId plus participants returns those senders' messages in that conversation. An unknown chatId matches nothing rather than falling back to every chat. --- App/Services/Messages.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/App/Services/Messages.swift b/App/Services/Messages.swift index 7e0a9281..1581fd12 100644 --- a/App/Services/Messages.swift +++ b/App/Services/Messages.swift @@ -109,6 +109,10 @@ final class MessageService: NSObject, Service, NSOpenSavePanelDelegate { "Participant handles (phone or email). Phone numbers should use E.164 format", items: .string() ), + "chatId": .string( + description: + "Conversation @id, as reported in a message's isPartOf. Fetches only messages in that conversation" + ), "start": .string( description: "Start of the date range (inclusive). If timezone is omitted, local time is assumed. Date-only uses local midnight.", @@ -151,6 +155,14 @@ final class MessageService: NSObject, Service, NSOpenSavePanelDelegate { $0.stringValue }) ?? [] + var requestedChatID: Chat.ID? + if let value = arguments["chatId"], !value.isNull { + guard let string = value.stringValue else { + throw ArgumentError.invalid("chatId has the wrong type") + } + requestedChatID = Chat.ID(rawValue: string) + } + // Either bound may be given alone; the other stays open. // chat.db stores dates as Int64 nanoseconds since 2001, so the open ends // use dates that fit, rather than Date.distantPast and Date.distantFuture. @@ -201,6 +213,9 @@ final class MessageService: NSObject, Service, NSOpenSavePanelDelegate { if !handles.isEmpty { predicates.append(.participantHandles(Set(handles))) } + if let requestedChatID { + predicates.append(.chatID(requestedChatID)) + } if let dateRange { predicates.append(.dateRange(dateRange)) }