From 587e13c2fee3d51544d638be96f4ddcdb70feb72 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Tue, 20 Feb 2024 20:08:28 -0800 Subject: [PATCH] Group Admin Updates (#257) * 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 --- Package.swift | 2 +- Sources/XMTPiOS/Group.swift | 16 ++++++++++++++++ Tests/XMTPTests/GroupTests.swift | 14 ++++++++++++++ XMTP.podspec | 4 ++-- .../xcshareddata/swiftpm/Package.resolved | 8 ++++---- 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/Package.swift b/Package.swift index 6d45c0ec..66509435 100644 --- a/Package.swift +++ b/Package.swift @@ -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. diff --git a/Sources/XMTPiOS/Group.swift b/Sources/XMTPiOS/Group.swift index d5932dfb..e0af35d7 100644 --- a/Sources/XMTPiOS/Group.swift +++ b/Sources/XMTPiOS/Group.swift @@ -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() @@ -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) diff --git a/Tests/XMTPTests/GroupTests.swift b/Tests/XMTPTests/GroupTests.swift index e782d728..d4e56f52 100644 --- a/Tests/XMTPTests/GroupTests.swift +++ b/Tests/XMTPTests/GroupTests.swift @@ -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 { @@ -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 { diff --git a/XMTP.podspec b/XMTP.podspec index 62a1c6c1..e1b4095f 100644 --- a/XMTP.podspec +++ b/XMTP.podspec @@ -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. @@ -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 diff --git a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index ae2d9158..3612b1e6 100644 --- a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -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" } }, { @@ -230,8 +230,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/WalletConnect/WalletConnectSwiftV2", "state" : { - "branch" : "main", - "revision" : "13446a81e678e8eddc6ab506e85c522df0163f1f" + "revision" : "addf9a3688ef5e5d9d148ecbb30ca0fd3132b908", + "version" : "1.9.8" } }, {