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 Updates #257

Merged
merged 4 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 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()
}

var metadata: FfiGroupMetadata {
return 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(): Bool {
return metadata.creatorAccountAddress() == client.address
}

public func permissionLevel(): GroupPermissions {
return metadata.policyType()
}

public func adminAddress(): String {
return 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(bobGroup.permissionLevel(), .everyoneIsAdmin)
XCTAssertEqual(aliceGroup.permissionLevel(), .everyoneIsAdmin)
XCTAssertEqual(bobGroup.adminAddress(), fixtures.bobClient.address)
XCTAssertEqual(aliceGroup.adminAddress(), fixtures.bobClient.address)
XCTAssert(bobGroup.isAdmin())
XCTAssert(!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(bobGroup.permissionLevel(), .groupCreatorIsAdmin)
XCTAssertEqual(aliceGroup.permissionLevel(), .groupCreatorIsAdmin)
XCTAssertEqual(bobGroup.adminAddress(), fixtures.bobClient.address)
XCTAssertEqual(aliceGroup.adminAddress(), fixtures.bobClient.address)
XCTAssert(bobGroup.isAdmin())
XCTAssert(!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" : "de859c86a5854bdc2cfd54e8f98b6088a38a2f3c",
"version" : "0.4.2-beta2"
}
},
{
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
Loading