From 0fbc3992ba6ac1287f3bf0b3db5b59512d9b1a62 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Fri, 16 Feb 2024 15:29:12 -0800 Subject: [PATCH 1/5] fix up the can message function --- Sources/XMTPiOS/Client.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/XMTPiOS/Client.swift b/Sources/XMTPiOS/Client.swift index 3201c082..5b82ffb0 100644 --- a/Sources/XMTPiOS/Client.swift +++ b/Sources/XMTPiOS/Client.swift @@ -238,7 +238,7 @@ public final class Client { return false } - return try await v3Client.canMessage(accountAddresses: addresses) == [true] + return try await v3Client.canMessage(accountAddresses: addresses).contains(false) } From d1c0ec7796792a329bb4395b1a9cc4ae34a3fb80 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Fri, 16 Feb 2024 15:29:41 -0800 Subject: [PATCH 2/5] bump the pod --- XMTP.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XMTP.podspec b/XMTP.podspec index ba78832d..62a1c6c1 100644 --- a/XMTP.podspec +++ b/XMTP.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |spec| # spec.name = "XMTP" - spec.version = "0.8.7" + spec.version = "0.8.8" spec.summary = "XMTP SDK Cocoapod" # This description is used to generate tags and improve search results. From e55c255f4c0de125534f1373e36a45990c36a91f Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Mon, 19 Feb 2024 13:30:30 -0800 Subject: [PATCH 3/5] fix up all the tests around can message --- Sources/XMTPiOS/Client.swift | 2 +- Tests/XMTPTests/GroupTests.swift | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/XMTPiOS/Client.swift b/Sources/XMTPiOS/Client.swift index 5b82ffb0..3a949a7b 100644 --- a/Sources/XMTPiOS/Client.swift +++ b/Sources/XMTPiOS/Client.swift @@ -238,7 +238,7 @@ public final class Client { return false } - return try await v3Client.canMessage(accountAddresses: addresses).contains(false) + return try await !v3Client.canMessage(accountAddresses: addresses).contains(false) } diff --git a/Tests/XMTPTests/GroupTests.swift b/Tests/XMTPTests/GroupTests.swift index 3ca12f29..d72a1eca 100644 --- a/Tests/XMTPTests/GroupTests.swift +++ b/Tests/XMTPTests/GroupTests.swift @@ -142,7 +142,7 @@ class GroupTests: XCTestCase { fixtures.fred.address.localizedLowercase ].sorted(), members) - let groupChangedMessage: GroupMembershipChanges = try await group.messages().last!.content() + let groupChangedMessage: GroupMembershipChanges = try await group.messages().first!.content() XCTAssertEqual(groupChangedMessage.membersAdded.map(\.accountAddress.localizedLowercase), [fixtures.fred.address.localizedLowercase]) } @@ -169,7 +169,7 @@ class GroupTests: XCTestCase { fixtures.alice.address.localizedLowercase, ].sorted(), newMembers) - let groupChangedMessage: GroupMembershipChanges = try await group.messages().last!.content() + let groupChangedMessage: GroupMembershipChanges = try await group.messages().first!.content() XCTAssertEqual(groupChangedMessage.membersRemoved.map(\.accountAddress.localizedLowercase), [fixtures.fred.address.localizedLowercase]) } @@ -177,7 +177,7 @@ class GroupTests: XCTestCase { 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]) + let cannotMessage = try await fixtures.aliceClient.canMessageV3(addresses: [notOnNetwork.address, fixtures.bobClient.address]) XCTAssert(canMessage) XCTAssert(!cannotMessage) } From 010b9b308d6bf0388ee25cf61bf5406399f00f0c Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Mon, 19 Feb 2024 13:32:20 -0800 Subject: [PATCH 4/5] add the ability to pass in permissions --- Sources/XMTPiOS/Conversations.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/XMTPiOS/Conversations.swift b/Sources/XMTPiOS/Conversations.swift index e474d2b3..371323af 100644 --- a/Sources/XMTPiOS/Conversations.swift +++ b/Sources/XMTPiOS/Conversations.swift @@ -115,7 +115,7 @@ public actor Conversations { } } - public func newGroup(with addresses: [String]) async throws -> Group { + public func newGroup(with addresses: [String], permissions: GroupPermissions = .everyoneIsAdmin) async throws -> Group { guard let v3Client = client.v3Client else { throw GroupError.alphaMLSNotEnabled } @@ -153,7 +153,7 @@ public actor Conversations { throw GroupError.memberNotRegistered(erroredAddresses) } - return try await v3Client.conversations().createGroup(accountAddresses: addresses, permissions: nil).fromFFI(client: client) + return try await v3Client.conversations().createGroup(accountAddresses: addresses, permissions: permissions).fromFFI(client: client) } /// Import a previously seen conversation. From d3cfc01e56472f93cb2030d4a4c8f80c3526ac9a Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Mon, 19 Feb 2024 13:48:23 -0800 Subject: [PATCH 5/5] add tests for it --- Tests/XMTPTests/GroupTests.swift | 59 ++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/Tests/XMTPTests/GroupTests.swift b/Tests/XMTPTests/GroupTests.swift index d72a1eca..e782d728 100644 --- a/Tests/XMTPTests/GroupTests.swift +++ b/Tests/XMTPTests/GroupTests.swift @@ -8,6 +8,7 @@ import CryptoKit import XCTest @testable import XMTPiOS +import LibXMTP import XMTPTestHelpers func assertThrowsAsyncError( @@ -83,11 +84,63 @@ class GroupTests: XCTestCase { ) } - func testCanCreateGroups() async throws { + func testCanCreateAGroupWithDefaultPermissions() async throws { let fixtures = try await localFixtures() - let group = try await fixtures.aliceClient.conversations.newGroup(with: [fixtures.bob.address]) + let bobGroup = try await fixtures.bobClient.conversations.newGroup(with: [fixtures.alice.address]) + try await fixtures.aliceClient.conversations.sync() + let aliceGroup = try await fixtures.aliceClient.conversations.groups().first! + XCTAssert(!bobGroup.id.isEmpty) + XCTAssert(!aliceGroup.id.isEmpty) + + + try await aliceGroup.addMembers(addresses: [fixtures.fred.address]) + try await bobGroup.sync() + XCTAssertEqual(aliceGroup.memberAddresses.count, 3) + XCTAssertEqual(bobGroup.memberAddresses.count, 3) + + try await aliceGroup.removeMembers(addresses: [fixtures.fred.address]) + try await bobGroup.sync() + XCTAssertEqual(aliceGroup.memberAddresses.count, 2) + XCTAssertEqual(bobGroup.memberAddresses.count, 2) - XCTAssert(!group.id.isEmpty) + try await bobGroup.addMembers(addresses: [fixtures.fred.address]) + try await aliceGroup.sync() + XCTAssertEqual(aliceGroup.memberAddresses.count, 3) + XCTAssertEqual(bobGroup.memberAddresses.count, 3) + } + + func testCanCreateAGroupWithAdminPermissions() async throws { + let fixtures = try await localFixtures() + let bobGroup = try await fixtures.bobClient.conversations.newGroup(with: [fixtures.alice.address], permissions: GroupPermissions.groupCreatorIsAdmin) + try await fixtures.aliceClient.conversations.sync() + let aliceGroup = try await fixtures.aliceClient.conversations.groups().first! + XCTAssert(!bobGroup.id.isEmpty) + XCTAssert(!aliceGroup.id.isEmpty) + + + try await bobGroup.addMembers(addresses: [fixtures.fred.address]) + try await aliceGroup.sync() + XCTAssertEqual(aliceGroup.memberAddresses.count, 3) + XCTAssertEqual(bobGroup.memberAddresses.count, 3) + + await assertThrowsAsyncError( + try await aliceGroup.removeMembers(addresses: [fixtures.fred.address]) + ) + try await bobGroup.sync() + XCTAssertEqual(aliceGroup.memberAddresses.count, 3) + XCTAssertEqual(bobGroup.memberAddresses.count, 3) + + try await bobGroup.removeMembers(addresses: [fixtures.fred.address]) + try await aliceGroup.sync() + XCTAssertEqual(aliceGroup.memberAddresses.count, 2) + XCTAssertEqual(bobGroup.memberAddresses.count, 2) + + await assertThrowsAsyncError( + try await aliceGroup.addMembers(addresses: [fixtures.fred.address]) + ) + try await bobGroup.sync() + XCTAssertEqual(aliceGroup.memberAddresses.count, 2) + XCTAssertEqual(bobGroup.memberAddresses.count, 2) } func testCanListGroups() async throws {