From 1afa531b207d7a9ca3b41b32830d803033c5e668 Mon Sep 17 00:00:00 2001 From: kele-leanes Date: Tue, 28 Nov 2023 09:55:10 -0300 Subject: [PATCH 1/6] expose canMessage method --- Sources/XMTP/Client.swift | 12 ++++++++++++ Tests/XMTPTests/ClientTests.swift | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/Sources/XMTP/Client.swift b/Sources/XMTP/Client.swift index 2ebffcf1..2461a8a0 100644 --- a/Sources/XMTP/Client.swift +++ b/Sources/XMTP/Client.swift @@ -192,6 +192,18 @@ public final class Client: Sendable { public func canMessage(_ peerAddress: String) async throws -> Bool { return try await query(topic: .contact(peerAddress)).envelopes.count > 0 } + + public static func canMessage(_ peerAddress: String, options: ClientOptions? = nil) async throws -> Bool { + let options = options ?? ClientOptions() + + let client = try await XMTPRust.create_client(GRPCApiClient.envToUrl(env: options.api.env), options.api.env != .local) + let apiClient = try GRPCApiClient( + environment: options.api.env, + secure: options.api.isSecure, + rustClient: client + ) + return try await apiClient.query(topic: .contact(peerAddress)).envelopes.count > 0 + } public func importConversation(from conversationData: Data) throws -> Conversation? { let jsonDecoder = JSONDecoder() diff --git a/Tests/XMTPTests/ClientTests.swift b/Tests/XMTPTests/ClientTests.swift index 164043ae..4207564f 100644 --- a/Tests/XMTPTests/ClientTests.swift +++ b/Tests/XMTPTests/ClientTests.swift @@ -30,6 +30,18 @@ class ClientTests: XCTestCase { XCTAssertFalse(cannotMessage) } + func testStaticCanMessage() async throws { + try TestConfig.skip(because: "run manually against dev") + let fixtures = await fixtures() + let notOnNetwork = try PrivateKey.generate() + let opts = ClientOptions(api: .init(env: .local, isSecure: false)) + + let canMessage = try await Client.canMessage(fixtures.bobClient.address, options: opts) + let cannotMessage = try await Client.canMessage(notOnNetwork.address, options: opts) + XCTAssertTrue(canMessage) + XCTAssertFalse(cannotMessage) + } + func testHasPrivateKeyBundleV1() async throws { let fakeWallet = try PrivateKey.generate() let client = try await Client.create(account: fakeWallet, apiClient: FakeApiClient()) From f0cfe1fb5260c0a386c2f970a3c46a471f127008 Mon Sep 17 00:00:00 2001 From: kele-leanes Date: Tue, 28 Nov 2023 15:58:25 -0300 Subject: [PATCH 2/6] improve staticCanMessage test --- Tests/XMTPTests/ClientTests.swift | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Tests/XMTPTests/ClientTests.swift b/Tests/XMTPTests/ClientTests.swift index 4207564f..2b44a529 100644 --- a/Tests/XMTPTests/ClientTests.swift +++ b/Tests/XMTPTests/ClientTests.swift @@ -31,12 +31,14 @@ class ClientTests: XCTestCase { } func testStaticCanMessage() async throws { - try TestConfig.skip(because: "run manually against dev") - let fixtures = await fixtures() + let opts = ClientOptions(api: ClientOptions.Api(env: .local, isSecure: false)) + + let aliceWallet = try PrivateKey.generate() let notOnNetwork = try PrivateKey.generate() - let opts = ClientOptions(api: .init(env: .local, isSecure: false)) + let alice = try await Client.create(account: aliceWallet, options: opts) + _ = try await alice.getUserContact(peerAddress: alice.address) - let canMessage = try await Client.canMessage(fixtures.bobClient.address, options: opts) + let canMessage = try await Client.canMessage(alice.address, options: opts) let cannotMessage = try await Client.canMessage(notOnNetwork.address, options: opts) XCTAssertTrue(canMessage) XCTAssertFalse(cannotMessage) From 9815b470bc98940601825b6b3dbf43e8a82ac9c6 Mon Sep 17 00:00:00 2001 From: kele-leanes Date: Tue, 28 Nov 2023 16:04:56 -0300 Subject: [PATCH 3/6] skip test for run manually on dev --- Tests/XMTPTests/ClientTests.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Tests/XMTPTests/ClientTests.swift b/Tests/XMTPTests/ClientTests.swift index 2b44a529..4993281e 100644 --- a/Tests/XMTPTests/ClientTests.swift +++ b/Tests/XMTPTests/ClientTests.swift @@ -31,6 +31,7 @@ class ClientTests: XCTestCase { } func testStaticCanMessage() async throws { + try TestConfig.skip(because: "run manually against dev") let opts = ClientOptions(api: ClientOptions.Api(env: .local, isSecure: false)) let aliceWallet = try PrivateKey.generate() From 8009db6783fa57c3b69a005f50df7917f32ba375 Mon Sep 17 00:00:00 2001 From: kele-leanes Date: Tue, 28 Nov 2023 16:30:49 -0300 Subject: [PATCH 4/6] remove unnecesary code --- Tests/XMTPTests/ClientTests.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Tests/XMTPTests/ClientTests.swift b/Tests/XMTPTests/ClientTests.swift index 4993281e..efb6e4a9 100644 --- a/Tests/XMTPTests/ClientTests.swift +++ b/Tests/XMTPTests/ClientTests.swift @@ -37,7 +37,6 @@ class ClientTests: XCTestCase { let aliceWallet = try PrivateKey.generate() let notOnNetwork = try PrivateKey.generate() let alice = try await Client.create(account: aliceWallet, options: opts) - _ = try await alice.getUserContact(peerAddress: alice.address) let canMessage = try await Client.canMessage(alice.address, options: opts) let cannotMessage = try await Client.canMessage(notOnNetwork.address, options: opts) From 77324ec4ef097325b224cb90994af012fb60603a Mon Sep 17 00:00:00 2001 From: kele-leanes Date: Wed, 29 Nov 2023 15:46:37 -0300 Subject: [PATCH 5/6] bump the pod --- XMTP.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XMTP.podspec b/XMTP.podspec index d4a17258..8ba20f8a 100644 --- a/XMTP.podspec +++ b/XMTP.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |spec| # spec.name = "XMTP" - spec.version = "0.6.12-alpha0" + spec.version = "0.6.13-alpha0" spec.summary = "XMTP SDK Cocoapod" # This description is used to generate tags and improve search results. From 6393110b2ad50d0c2bc52055a0fa6fbd54972b60 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 29 Nov 2023 10:46:43 -0800 Subject: [PATCH 6/6] fix up spacing issues --- Sources/XMTP/Client.swift | 22 +++++++++++----------- Tests/XMTPTests/ClientTests.swift | 28 ++++++++++++++-------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Sources/XMTP/Client.swift b/Sources/XMTP/Client.swift index 2461a8a0..ebcd0cd7 100644 --- a/Sources/XMTP/Client.swift +++ b/Sources/XMTP/Client.swift @@ -193,17 +193,17 @@ public final class Client: Sendable { return try await query(topic: .contact(peerAddress)).envelopes.count > 0 } - public static func canMessage(_ peerAddress: String, options: ClientOptions? = nil) async throws -> Bool { - let options = options ?? ClientOptions() - - let client = try await XMTPRust.create_client(GRPCApiClient.envToUrl(env: options.api.env), options.api.env != .local) - let apiClient = try GRPCApiClient( - environment: options.api.env, - secure: options.api.isSecure, - rustClient: client - ) - return try await apiClient.query(topic: .contact(peerAddress)).envelopes.count > 0 - } + public static func canMessage(_ peerAddress: String, options: ClientOptions? = nil) async throws -> Bool { + let options = options ?? ClientOptions() + + let client = try await XMTPRust.create_client(GRPCApiClient.envToUrl(env: options.api.env), options.api.env != .local) + let apiClient = try GRPCApiClient( + environment: options.api.env, + secure: options.api.isSecure, + rustClient: client + ) + return try await apiClient.query(topic: .contact(peerAddress)).envelopes.count > 0 + } public func importConversation(from conversationData: Data) throws -> Conversation? { let jsonDecoder = JSONDecoder() diff --git a/Tests/XMTPTests/ClientTests.swift b/Tests/XMTPTests/ClientTests.swift index efb6e4a9..7a156c82 100644 --- a/Tests/XMTPTests/ClientTests.swift +++ b/Tests/XMTPTests/ClientTests.swift @@ -30,20 +30,20 @@ class ClientTests: XCTestCase { XCTAssertFalse(cannotMessage) } - func testStaticCanMessage() async throws { - try TestConfig.skip(because: "run manually against dev") - let opts = ClientOptions(api: ClientOptions.Api(env: .local, isSecure: false)) - - let aliceWallet = try PrivateKey.generate() - let notOnNetwork = try PrivateKey.generate() - let alice = try await Client.create(account: aliceWallet, options: opts) - - let canMessage = try await Client.canMessage(alice.address, options: opts) - let cannotMessage = try await Client.canMessage(notOnNetwork.address, options: opts) - XCTAssertTrue(canMessage) - XCTAssertFalse(cannotMessage) - } - + func testStaticCanMessage() async throws { + try TestConfig.skip(because: "run manually against local") + let opts = ClientOptions(api: ClientOptions.Api(env: .local, isSecure: false)) + + let aliceWallet = try PrivateKey.generate() + let notOnNetwork = try PrivateKey.generate() + let alice = try await Client.create(account: aliceWallet, options: opts) + + let canMessage = try await Client.canMessage(alice.address, options: opts) + let cannotMessage = try await Client.canMessage(notOnNetwork.address, options: opts) + XCTAssertTrue(canMessage) + XCTAssertFalse(cannotMessage) + } + func testHasPrivateKeyBundleV1() async throws { let fakeWallet = try PrivateKey.generate() let client = try await Client.create(account: fakeWallet, apiClient: FakeApiClient())