Skip to content

Commit

Permalink
feat: (iOS) use batchQuery instead of one-at-a-time for messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dmccartney committed Jun 1, 2023
1 parent bd825f0 commit fdbd5f5
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions ios/XMTPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fdbd5f5

Please sign in to comment.