From f1b75f9b9bfbf170a776d979ed9474123d740cfa Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 13 Jun 2024 12:31:39 -0700 Subject: [PATCH] Add group image url (#349) * update the package * add the functionality * write a test for it --- Package.swift | 2 +- Sources/XMTPiOS/Conversations.swift | 13 ++++++++--- Sources/XMTPiOS/Group.swift | 8 +++++++ Tests/XMTPTests/GroupTests.swift | 22 +++++++++++++------ XMTP.podspec | 6 ++--- .../xcshareddata/swiftpm/Package.resolved | 4 ++-- 6 files changed, 39 insertions(+), 16 deletions(-) diff --git a/Package.swift b/Package.swift index d2492281..c7a8e678 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.12.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.5.1-beta1"), + .package(url: "https://github.com/xmtp/libxmtp-swift", exact: "0.5.1-beta2"), ], 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/Conversations.swift b/Sources/XMTPiOS/Conversations.swift index 3ed23a76..c157659b 100644 --- a/Sources/XMTPiOS/Conversations.swift +++ b/Sources/XMTPiOS/Conversations.swift @@ -122,12 +122,15 @@ public actor Conversations { } } - public func newGroup(with addresses: [String], permissions: GroupPermissions = .allMembers) async throws -> Group { + public func newGroup(with addresses: [String], + permissions: GroupPermissions = .allMembers, + name: String = "", + imageUrlSquare: String = "" + ) async throws -> Group { guard let v3Client = client.v3Client else { throw GroupError.alphaMLSNotEnabled } - if addresses.first(where: { $0.lowercased() == client.address.lowercased() }) != nil { throw GroupError.memberCannotBeSelf } @@ -157,7 +160,11 @@ public actor Conversations { throw GroupError.memberNotRegistered(erroredAddresses) } - let group = try await v3Client.conversations().createGroup(accountAddresses: addresses, permissions: permissions).fromFFI(client: client) + let group = try await v3Client.conversations().createGroup(accountAddresses: addresses, + opts: FfiCreateGroupOptions(permissions: permissions, + groupName: name, + groupImageUrlSquare: imageUrlSquare + )).fromFFI(client: client) try await client.contacts.allowGroups(groupIds: [group.id]) diff --git a/Sources/XMTPiOS/Group.swift b/Sources/XMTPiOS/Group.swift index acb83bd2..39f401e1 100644 --- a/Sources/XMTPiOS/Group.swift +++ b/Sources/XMTPiOS/Group.swift @@ -152,11 +152,19 @@ public struct Group: Identifiable, Equatable, Hashable { public func groupName() throws -> String { return try ffiGroup.groupName() } + + public func groupImageUrlSquare() throws -> String { + return try ffiGroup.groupImageUrlSquare() + } public func updateGroupName(groupName: String) async throws { try await ffiGroup.updateGroupName(groupName: groupName) } + public func updateGroupImageUrlSquare(imageUrlSquare: String) async throws { + try await ffiGroup.updateGroupImageUrlSquare(groupImageUrlSquare: imageUrlSquare) + } + public func processMessage(envelopeBytes: Data) async throws -> DecodedMessage { let message = try await ffiGroup.processStreamedGroupMessage(envelopeBytes: envelopeBytes) return try MessageV3(client: client, ffiMessage: message).decode() diff --git a/Tests/XMTPTests/GroupTests.swift b/Tests/XMTPTests/GroupTests.swift index 5585c035..5cc8a8c1 100644 --- a/Tests/XMTPTests/GroupTests.swift +++ b/Tests/XMTPTests/GroupTests.swift @@ -664,20 +664,26 @@ class GroupTests: XCTestCase { await waitForExpectations(timeout: 3) } - func testCanUpdateGroupName() async throws { + func testCanUpdateGroupMetadata() async throws { let fixtures = try await localFixtures() - let group = try await fixtures.aliceClient.conversations.newGroup(with: [fixtures.bob.address]) + let group = try await fixtures.aliceClient.conversations.newGroup(with: [fixtures.bob.address], name: "Start Name", imageUrlSquare: "starturl.com") var groupName = try group.groupName() + var groupImageUrlSquare = try group.groupImageUrlSquare() - XCTAssertEqual(groupName, "") + XCTAssertEqual(groupName, "Start Name") + XCTAssertEqual(groupImageUrlSquare, "starturl.com") + try await group.updateGroupName(groupName: "Test Group Name 1") + try await group.updateGroupImageUrlSquare(imageUrlSquare: "newurl.com") groupName = try group.groupName() - + groupImageUrlSquare = try group.groupImageUrlSquare() + XCTAssertEqual(groupName, "Test Group Name 1") - + XCTAssertEqual(groupImageUrlSquare, "newurl.com") + let bobConv = try await fixtures.bobClient.conversations.list(includeGroups: true)[0] let bobGroup: Group; switch bobConv { @@ -691,11 +697,13 @@ class GroupTests: XCTestCase { bobGroup = group } groupName = try bobGroup.groupName() - XCTAssertEqual(groupName, "") + XCTAssertEqual(groupName, "Start Name") try await bobGroup.sync() groupName = try bobGroup.groupName() - + groupImageUrlSquare = try bobGroup.groupImageUrlSquare() + + XCTAssertEqual(groupImageUrlSquare, "newurl.com") XCTAssertEqual(groupName, "Test Group Name 1") } diff --git a/XMTP.podspec b/XMTP.podspec index a6ce80d0..3428d098 100644 --- a/XMTP.podspec +++ b/XMTP.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |spec| # spec.name = "XMTP" - spec.version = "0.11.6" + spec.version = "0.11.7" spec.summary = "XMTP SDK Cocoapod" # This description is used to generate tags and improve search results. @@ -31,7 +31,7 @@ Pod::Spec.new do |spec| spec.homepage = "https://github.com/xmtp/xmtp-ios" spec.license = "MIT" - spec.author = { "Pat Nakajima" => "pat@xmtp.com" } + spec.author = { "XMTP" => "eng@xmtp.com" } spec.platform = :ios, '14.0', :macos, '11.0' @@ -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.1-beta1' + spec.dependency 'LibXMTP', '= 0.5.1-beta2' end diff --git a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index f2d03777..cb0b4d32 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" : "c5e9ed9d3ee9de55beec4d7a8f76861c9d43230d", - "version" : "0.5.1-beta1" + "revision" : "61cf883b0a6e3bdd00a1d41f6b93556c35124b7b", + "version" : "0.5.1-beta2" } }, {