From 0217c13d78a83a7845b1804b557394a727a6aef1 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 15 Feb 2024 20:42:35 -0800 Subject: [PATCH] fix: add list all and gets iOS working --- example/ios/Podfile.lock | 14 +++++------ example/src/tests.ts | 2 +- .../ConversationContainerWrapper.swift | 9 ++++++++ ios/XMTPModule.swift | 23 +++++++++++++++++++ 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 45b159e13..d0cdbffe7 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -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): @@ -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: @@ -695,7 +695,7 @@ SPEC CHECKSUMS: GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa hermes-engine: d7cc127932c89c53374452d6f93473f1970d8e88 libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913 - LibXMTP: 678390cd0049d090af4aa6a7d5c9133ded3473b3 + LibXMTP: 026f2fec3c88b24e92f21895b29a12817fa54779 Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26 MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02 MMKV: f902fb6719da13c2ab0965233d8963a59416f911 @@ -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 diff --git a/example/src/tests.ts b/example/src/tests.ts index 0f061f3fa..af7f53c2b 100644 --- a/example/src/tests.ts +++ b/example/src/tests.ts @@ -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 || diff --git a/ios/Wrappers/ConversationContainerWrapper.swift b/ios/Wrappers/ConversationContainerWrapper.swift index 6eac51882..171a49599 100644 --- a/ios/Wrappers/ConversationContainerWrapper.swift +++ b/ios/Wrappers/ConversationContainerWrapper.swift @@ -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 + } } diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index d54d9c050..11a753d44 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -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