Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group Admin Permissions #253

Merged
merged 5 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/XMTPiOS/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}


Expand Down
4 changes: 2 additions & 2 deletions Sources/XMTPiOS/Conversations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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.
Expand Down
65 changes: 59 additions & 6 deletions Tests/XMTPTests/GroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import CryptoKit
import XCTest
@testable import XMTPiOS
import LibXMTP
import XMTPTestHelpers

func assertThrowsAsyncError<T>(
Expand Down Expand Up @@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XCode is giving me Extra argument 'permissions' in call @zombieobject am I doing this wrong?

Copy link
Contributor

@zombieobject zombieobject Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nplasterer I was heads down working on fixing the tests for libXMTPSwift and XMPT-iOS when this came in. I don't see the error any longer using the HEAD from this branch. The interface method resolves correctly from I can tell at this point. Has this been resolved already?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must have just been an xcode issue. 🤔 The tests did pass.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Xcode has been showing ghost errors from time to time since version 14.3. 🙄 When they get too annoying, I temporarily disable "Show Live Issues" in Settings->General until I move onto the next task.

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 {
Expand Down Expand Up @@ -142,7 +195,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])
}

Expand All @@ -169,15 +222,15 @@ 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])
}

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])
let cannotMessage = try await fixtures.aliceClient.canMessageV3(addresses: [notOnNetwork.address, fixtures.bobClient.address])
XCTAssert(canMessage)
XCTAssert(!cannotMessage)
}
Expand Down
2 changes: 1 addition & 1 deletion XMTP.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading