From 757da655255e6be2a469a8ccae1231e12724aa80 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 15 Feb 2024 16:03:37 -0800 Subject: [PATCH] Can message with all addresses (#250) * add can message function * write a test --- Sources/XMTPiOS/Client.swift | 9 +++++++++ Tests/XMTPTests/GroupTests.swift | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/Sources/XMTPiOS/Client.swift b/Sources/XMTPiOS/Client.swift index 7ad48316..d0db7691 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 canMessageV3(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) 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])