Skip to content

Commit

Permalink
Add group image url (#349)
Browse files Browse the repository at this point in the history
* update the package

* add the functionality

* write a test for it
  • Loading branch information
nplasterer authored Jun 13, 2024
1 parent c890044 commit f1b75f9
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 16 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.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.
Expand Down
13 changes: 10 additions & 3 deletions Sources/XMTPiOS/Conversations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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])

Expand Down
8 changes: 8 additions & 0 deletions Sources/XMTPiOS/Group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
22 changes: 15 additions & 7 deletions Tests/XMTPTests/GroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
}

Expand Down
6 changes: 3 additions & 3 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.11.6"
spec.version = "0.11.7"
spec.summary = "XMTP SDK Cocoapod"

# This description is used to generate tags and improve search results.
Expand All @@ -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'

Expand All @@ -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
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" : "c5e9ed9d3ee9de55beec4d7a8f76861c9d43230d",
"version" : "0.5.1-beta1"
"revision" : "61cf883b0a6e3bdd00a1d41f6b93556c35124b7b",
"version" : "0.5.1-beta2"
}
},
{
Expand Down

0 comments on commit f1b75f9

Please sign in to comment.