diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index c9330b885..1a294b45c 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -160,22 +160,15 @@ public class XMTPModule: Module { let beforeDate = before != nil ? Date(timeIntervalSince1970: before!) : nil let afterDate = after != nil ? Date(timeIntervalSince1970: after!) : nil var messages:[String] = [] - // TODO: use batchQuery instead of one-at-a-time (once iOS and libxmtp support it). - for (topic, conversationID) in zip(topics, conversationIDs) { - guard let conversation = try await findConversation( - clientAddress: clientAddress, - topic: topic, - conversationID: conversationID) else { - throw Error.conversationNotFound("no conversation found for \(topic)") - } - messages += try await conversation.messages( - limit: limit, - before: beforeDate, - after: afterDate) - .map { (msg) in try DecodedMessageWrapper.encode(msg) } + guard let client = clients[clientAddress] else { + throw Error.noClient } - // print("found \(messages.count) messages from \(topics.count) conversations"); - return messages + return try await client.conversations.listBatchMessages( + topics: topics, + limit: limit, + before: beforeDate, + after: afterDate) + .map { (msg) in try DecodedMessageWrapper.encode(msg) } } // TODO: Support content types