Skip to content

Commit

Permalink
Can message with all addresses (#250)
Browse files Browse the repository at this point in the history
* add can message function

* write a test
  • Loading branch information
nplasterer authored Feb 16, 2024
1 parent 0c7db3a commit 757da65
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Sources/XMTPiOS/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions Tests/XMTPTests/GroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit 757da65

Please sign in to comment.