Skip to content

Commit

Permalink
Group Admin Updates (#257)
Browse files Browse the repository at this point in the history
* update the pod spec for the new group admin stuff

* add more involved tests for the functions

* fix up the tests

* fix up the tests
  • Loading branch information
nplasterer authored Feb 21, 2024
1 parent 2a6081e commit 587e13c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ let package = Package(
.package(url: "https://github.com/1024jp/GzipSwift", from: "5.2.0"),
.package(url: "https://github.com/bufbuild/connect-swift", exact: "0.3.0"),
.package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.0.0"),
.package(url: "https://github.com/xmtp/libxmtp-swift", exact: "0.4.2-beta2"),
.package(url: "https://github.com/xmtp/libxmtp-swift", exact: "0.4.2-beta3"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
16 changes: 16 additions & 0 deletions Sources/XMTPiOS/Group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public struct Group: Identifiable, Equatable, Hashable {
public var id: Data {
ffiGroup.id()
}

func metadata() throws -> FfiGroupMetadata {
return try ffiGroup.groupMetadata()
}

public func sync() async throws {
try await ffiGroup.sync()
Expand All @@ -58,7 +62,19 @@ public struct Group: Identifiable, Equatable, Hashable {
public func isActive() throws -> Bool {
return try ffiGroup.isActive()
}

public func isAdmin() throws -> Bool {
return try metadata().creatorAccountAddress().lowercased() == client.address.lowercased()
}

public func permissionLevel() throws -> GroupPermissions {
return try metadata().policyType()
}

public func adminAddress() throws -> String {
return try metadata().creatorAccountAddress()
}

public var memberAddresses: [String] {
do {
return try ffiGroup.listMembers().map(\.fromFFI.accountAddress)
Expand Down
14 changes: 14 additions & 0 deletions Tests/XMTPTests/GroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ class GroupTests: XCTestCase {
try await aliceGroup.sync()
XCTAssertEqual(aliceGroup.memberAddresses.count, 3)
XCTAssertEqual(bobGroup.memberAddresses.count, 3)

XCTAssertEqual(try bobGroup.permissionLevel(), .everyoneIsAdmin)
XCTAssertEqual(try aliceGroup.permissionLevel(), .everyoneIsAdmin)
XCTAssertEqual(try bobGroup.adminAddress().lowercased(), fixtures.bobClient.address.lowercased())
XCTAssertEqual(try aliceGroup.adminAddress().lowercased(), fixtures.bobClient.address.lowercased())
XCTAssert(try bobGroup.isAdmin())
XCTAssert(try !aliceGroup.isAdmin())
}

func testCanCreateAGroupWithAdminPermissions() async throws {
Expand Down Expand Up @@ -141,6 +148,13 @@ class GroupTests: XCTestCase {
try await bobGroup.sync()
XCTAssertEqual(aliceGroup.memberAddresses.count, 2)
XCTAssertEqual(bobGroup.memberAddresses.count, 2)

XCTAssertEqual(try bobGroup.permissionLevel(), .groupCreatorIsAdmin)
XCTAssertEqual(try aliceGroup.permissionLevel(), .groupCreatorIsAdmin)
XCTAssertEqual(try bobGroup.adminAddress().lowercased(), fixtures.bobClient.address.lowercased())
XCTAssertEqual(try aliceGroup.adminAddress().lowercased(), fixtures.bobClient.address.lowercased())
XCTAssert(try bobGroup.isAdmin())
XCTAssert(try !aliceGroup.isAdmin())
}

func testCanListGroups() async throws {
Expand Down
4 changes: 2 additions & 2 deletions 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.8"
spec.version = "0.8.9"
spec.summary = "XMTP SDK Cocoapod"

# This description is used to generate tags and improve search results.
Expand Down Expand Up @@ -44,5 +44,5 @@ Pod::Spec.new do |spec|
spec.dependency "web3.swift"
spec.dependency "GzipSwift"
spec.dependency "Connect-Swift", "= 0.3.0"
spec.dependency 'LibXMTP', '= 0.4.2-beta1'
spec.dependency 'LibXMTP', '= 0.4.2-beta3'
end
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/xmtp/libxmtp-swift",
"state" : {
"revision" : "db13df1fef0e4a11880a889640a3df2998e4abac",
"version" : "0.4.2-beta1"
"revision" : "f6571b6b771b4c0a2a9469bd407ce124a9d91fed",
"version" : "0.4.2-beta3"
}
},
{
Expand Down Expand Up @@ -230,8 +230,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/WalletConnect/WalletConnectSwiftV2",
"state" : {
"branch" : "main",
"revision" : "13446a81e678e8eddc6ab506e85c522df0163f1f"
"revision" : "addf9a3688ef5e5d9d148ecbb30ca0fd3132b908",
"version" : "1.9.8"
}
},
{
Expand Down

0 comments on commit 587e13c

Please sign in to comment.