From 86365aefc29e04d9197ff29abe04aa6850aa15f6 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 15 Feb 2024 12:08:58 -0800 Subject: [PATCH 1/2] add can message function --- Sources/XMTPiOS/Client.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sources/XMTPiOS/Client.swift b/Sources/XMTPiOS/Client.swift index 7ad48316..b230714b 100644 --- a/Sources/XMTPiOS/Client.swift +++ b/Sources/XMTPiOS/Client.swift @@ -237,6 +237,15 @@ public final class Client { return try await v3Client.canMessage(accountAddresses: [address]) == [true] } + + public func canMessage(addresses: [String]) async throws -> Bool { + guard let v3Client else { + return false + } + + return try await v3Client.canMessage(accountAddresses: addresses) == [true] + } + public static func from(bundle: PrivateKeyBundle, options: ClientOptions? = nil) async throws -> Client { return try await from(v1Bundle: bundle.v1, options: options) From 0a214c9748ac8755dc510e5b8fd92bd72348208e Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 15 Feb 2024 15:45:50 -0800 Subject: [PATCH 2/2] write a test --- Sources/XMTPiOS/Client.swift | 2 +- Tests/XMTPTests/GroupTests.swift | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Sources/XMTPiOS/Client.swift b/Sources/XMTPiOS/Client.swift index b230714b..d0db7691 100644 --- a/Sources/XMTPiOS/Client.swift +++ b/Sources/XMTPiOS/Client.swift @@ -238,7 +238,7 @@ public final class Client { return try await v3Client.canMessage(accountAddresses: [address]) == [true] } - public func canMessage(addresses: [String]) async throws -> Bool { + public func canMessageV3(addresses: [String]) async throws -> Bool { guard let v3Client else { return false } diff --git a/Tests/XMTPTests/GroupTests.swift b/Tests/XMTPTests/GroupTests.swift index 6ae3ae30..57d4cfd5 100644 --- a/Tests/XMTPTests/GroupTests.swift +++ b/Tests/XMTPTests/GroupTests.swift @@ -173,6 +173,15 @@ class GroupTests: XCTestCase { XCTAssertEqual(groupChangedMessage.membersRemoved.map(\.accountAddress.localizedLowercase), [fixtures.fred.address.localizedLowercase]) } + func testCanMessage() async throws { + let fixtures = try await localFixtures() + let notOnNetwork = try PrivateKey.generate() + let canMessage = try await fixtures.aliceClient.canMessageV3(addresses: [fixtures.bobClient.address]) + let cannotMessage = try await fixtures.aliceClient.canMessageV3(addresses: [notOnNetwork.address]) + XCTAssert(canMessage) + XCTAssert(!cannotMessage) + } + func testIsActive() async throws { let fixtures = try await localFixtures() let group = try await fixtures.aliceClient.conversations.newGroup(with: [fixtures.bob.address, fixtures.fred.address])