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)) }