Skip to content

Commit

Permalink
fix: add list all and gets iOS working
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Feb 16, 2024
1 parent ff17d1b commit 0217c13
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
14 changes: 7 additions & 7 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ PODS:
- hermes-engine/Pre-built (= 0.71.14)
- hermes-engine/Pre-built (0.71.14)
- libevent (2.1.12)
- LibXMTP (0.4.1-beta3)
- LibXMTP (0.4.2-beta1)
- Logging (1.0.0)
- MessagePacker (0.4.7)
- MMKV (1.3.3):
Expand Down Expand Up @@ -442,16 +442,16 @@ PODS:
- GenericJSON (~> 2.0)
- Logging (~> 1.0.0)
- secp256k1.swift (~> 0.1)
- XMTP (0.8.5):
- XMTP (0.8.6):
- Connect-Swift (= 0.3.0)
- GzipSwift
- LibXMTP (= 0.4.1-beta3)
- LibXMTP (= 0.4.2-beta1)
- web3.swift
- XMTPReactNative (0.1.0):
- ExpoModulesCore
- MessagePacker
- secp256k1.swift
- XMTP (= 0.8.5)
- XMTP (= 0.8.6)
- Yoga (1.14.0)

DEPENDENCIES:
Expand Down Expand Up @@ -695,7 +695,7 @@ SPEC CHECKSUMS:
GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa
hermes-engine: d7cc127932c89c53374452d6f93473f1970d8e88
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
LibXMTP: 678390cd0049d090af4aa6a7d5c9133ded3473b3
LibXMTP: 026f2fec3c88b24e92f21895b29a12817fa54779
Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26
MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02
MMKV: f902fb6719da13c2ab0965233d8963a59416f911
Expand Down Expand Up @@ -744,8 +744,8 @@ SPEC CHECKSUMS:
secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634
SwiftProtobuf: b02b5075dcf60c9f5f403000b3b0c202a11b6ae1
web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959
XMTP: 1957e318059e8723bc1e76b1723c1eeb98e7760b
XMTPReactNative: 048504b17f0a7f9380b48ddeda6bfb15f7a5d799
XMTP: 2cd39f7244fdeeb0a5f544da37e027cddc10df45
XMTPReactNative: 491b7689b36dacf6ca1a63d99e1481b8b3926dfa
Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9

PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2
Expand Down
2 changes: 1 addition & 1 deletion example/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ test('can list all groups and conversations', async () => {

const listedContainers = await aliceClient.conversations.listAll()

// Verify informatioin in listed containers is correct
// Verify information in listed containers is correct
if (
listedContainers[0].topic !== bobGroup.topic ||
listedContainers[0].version !== ConversationVersion.GROUP ||
Expand Down
9 changes: 9 additions & 0 deletions ios/Wrappers/ConversationContainerWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,13 @@ struct ConversationContainerWrapper {
return try ConversationWrapper.encodeToObj(conversation, client: client)
}
}

static func encode(_ conversation: XMTP.Conversation, client: XMTP.Client) throws -> String {
let obj = try encodeToObj(conversation, client: client)
let data = try JSONSerialization.data(withJSONObject: obj)
guard let result = String(data: data, encoding: .utf8) else {
throw WrapperError.encodeError("could not encode conversation")
}
return result
}
}
23 changes: 23 additions & 0 deletions ios/XMTPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,29 @@ public class XMTPModule: Module {
return results
}
}

AsyncFunction("listAll") { (clientAddress: String) -> [String] in
guard let client = await clientsManager.getClient(key: clientAddress) else {
throw Error.noClient
}
let conversationContainerList = try await client.conversations.list(includeGroups: true)

return try await withThrowingTaskGroup(of: String.self) { taskGroup in
for conversation in conversationContainerList {
taskGroup.addTask {
await self.conversationsManager.set(conversation.cacheKey(clientAddress), conversation)
return try ConversationContainerWrapper.encode(conversation, client: client)
}
}

var results: [String] = []
for try await result in taskGroup {
results.append(result)
}

return results
}
}

AsyncFunction("loadMessages") { (clientAddress: String, topic: String, limit: Int?, before: Double?, after: Double?, direction: String?) -> [String] in
let beforeDate = before != nil ? Date(timeIntervalSince1970: TimeInterval(before!) / 1000) : nil
Expand Down

0 comments on commit 0217c13

Please sign in to comment.