Skip to content

Commit

Permalink
added pinned frame url (#362)
Browse files Browse the repository at this point in the history
Co-authored-by: cameronvoell <[email protected]>
  • Loading branch information
cameronvoell and cameronvoell authored Jul 3, 2024
1 parent 8091f03 commit 93d54d6
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/xmtp/libxmtp-swift.git",
"state" : {
"revision" : "577a61e568cb5aaff10486172b1ef055faeff5b9",
"version" : "0.5.4-beta1"
"revision" : "6bcf6f2514856f134a8b0faaf176f0beefc1bc83",
"version" : "0.5.4-beta2"
}
},
{
Expand Down
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.12.0"),
.package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.0.0"),
.package(url: "https://github.com/xmtp/libxmtp-swift.git", exact: "0.5.4-beta1"),
.package(url: "https://github.com/xmtp/libxmtp-swift.git", exact: "0.5.4-beta2"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
6 changes: 4 additions & 2 deletions Sources/XMTPiOS/Conversations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ public actor Conversations {
permissions: GroupPermissionPreconfiguration = .allMembers,
name: String = "",
imageUrlSquare: String = "",
description: String = ""
description: String = "",
pinnedFrameUrl: String = ""
) async throws -> Group {
guard let v3Client = client.v3Client else {
throw GroupError.alphaMLSNotEnabled
Expand Down Expand Up @@ -179,7 +180,8 @@ public actor Conversations {
opts: FfiCreateGroupOptions(permissions: GroupPermissionPreconfiguration.toFfiGroupPermissionOptions(option: permissions),
groupName: name,
groupImageUrlSquare: imageUrlSquare,
groupDescription: description
groupDescription: description,
groupPinnedFrameUrl: pinnedFrameUrl
)).fromFFI(client: client)
try await client.contacts.allowGroups(groupIds: [group.id])
return group
Expand Down
12 changes: 12 additions & 0 deletions Sources/XMTPiOS/Group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ public struct Group: Identifiable, Equatable, Hashable {
return try ffiGroup.groupDescription()
}

public func groupPinnedFrameUrl() throws -> String {
return try ffiGroup.groupPinnedFrameUrl()
}

public func updateGroupName(groupName: String) async throws {
try await ffiGroup.updateGroupName(groupName: groupName)
}
Expand All @@ -173,6 +177,10 @@ public struct Group: Identifiable, Equatable, Hashable {
try await ffiGroup.updateGroupDescription(groupDescription: groupDescription)
}

public func updateGroupPinnedFrameUrl(groupPinnedFrameUrl: String) async throws {
try await ffiGroup.updateGroupPinnedFrameUrl(pinnedFrameUrl: groupPinnedFrameUrl)
}

public func updateAddMemberPermission(newPermissionOption: PermissionOption) async throws {
try await ffiGroup.updatePermissionPolicy(permissionUpdateType: FfiPermissionUpdateType.addMember, permissionPolicyOption: PermissionOption.toFfiPermissionPolicy(option: newPermissionOption), metadataField: nil)
}
Expand Down Expand Up @@ -201,6 +209,10 @@ public struct Group: Identifiable, Equatable, Hashable {
try await ffiGroup.updatePermissionPolicy(permissionUpdateType: FfiPermissionUpdateType.updateMetadata, permissionPolicyOption: PermissionOption.toFfiPermissionPolicy(option: newPermissionOption), metadataField: FfiMetadataField.imageUrlSquare)
}

public func updateGroupPinnedFrameUrlPermission(newPermissionOption: PermissionOption) async throws {
try await ffiGroup.updatePermissionPolicy(permissionUpdateType: FfiPermissionUpdateType.updateMetadata, permissionPolicyOption: PermissionOption.toFfiPermissionPolicy(option: newPermissionOption), metadataField: FfiMetadataField.pinnedFrameUrl)
}


public func processMessage(envelopeBytes: Data) async throws -> DecodedMessage {
let message = try await ffiGroup.processStreamedGroupMessage(envelopeBytes: envelopeBytes)
Expand Down
4 changes: 4 additions & 0 deletions Sources/XMTPiOS/Mls/PermissionPolicySet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,8 @@ public class PermissionPolicySet {
public var updateGroupImagePolicy: PermissionOption {
return PermissionOption.fromFfiPermissionPolicy(ffiPolicy: ffiPermissionPolicySet.updateGroupImageUrlSquarePolicy)
}

public var updateGroupPinnedFrameUrlPolicy: PermissionOption {
return PermissionOption.fromFfiPermissionPolicy(ffiPolicy: ffiPermissionPolicySet.updateGroupPinnedFrameUrlPolicy)
}
}
34 changes: 34 additions & 0 deletions Tests/XMTPTests/GroupPermissionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,38 @@ class GroupPermissionTests: XCTestCase {
XCTAssertEqual(try bobGroup.groupDescription(), "Alice group description")
XCTAssertEqual(try aliceGroup.groupDescription(), "Alice group description")
}

func testCanUpdatePinnedFrameUrl() async throws {
let fixtures = try await localFixtures()
let bobGroup = try await fixtures.bobClient.conversations.newGroup(
with: [fixtures.alice.walletAddress, fixtures.caro.walletAddress],
permissions: .adminOnly,
pinnedFrameUrl: "initial url"
)
try await fixtures.aliceClient.conversations.sync()
let aliceGroup = try await fixtures.aliceClient.conversations.groups().first!

// Verify that Alice cannot update group pinned frame url
XCTAssertEqual(try bobGroup.groupPinnedFrameUrl(), "initial url")
await assertThrowsAsyncError(
try await aliceGroup.updateGroupPinnedFrameUrl(groupPinnedFrameUrl: "https://foo/bar.com")
)

try await aliceGroup.sync()
try await bobGroup.sync()
XCTAssertEqual(try bobGroup.permissionPolicySet().updateGroupPinnedFrameUrlPolicy, .admin)

// Update group pinned frame url permissions so Alice can update
try await bobGroup.updateGroupPinnedFrameUrlPermission(newPermissionOption: .allow)
try await bobGroup.sync()
try await aliceGroup.sync()
XCTAssertEqual(try bobGroup.permissionPolicySet().updateGroupPinnedFrameUrlPolicy, .allow)

// Verify that Alice can now update group pinned frame url
try await aliceGroup.updateGroupPinnedFrameUrl(groupPinnedFrameUrl: "https://foo/barz.com")
try await aliceGroup.sync()
try await bobGroup.sync()
XCTAssertEqual(try bobGroup.groupPinnedFrameUrl(), "https://foo/barz.com")
XCTAssertEqual(try aliceGroup.groupPinnedFrameUrl(), "https://foo/barz.com")
}
}
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.13.2"
spec.version = "0.13.3"
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.12.0"
spec.dependency 'LibXMTP', '= 0.5.4-beta1'
spec.dependency 'LibXMTP', '= 0.5.4-beta2'
end

0 comments on commit 93d54d6

Please sign in to comment.