Skip to content

Commit

Permalink
feat: added pinned frame url
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronvoell committed Jul 3, 2024
1 parent 91968ad commit fb74c00
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 16 deletions.
14 changes: 7 additions & 7 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ PODS:
- hermes-engine/Pre-built (= 0.71.14)
- hermes-engine/Pre-built (0.71.14)
- libevent (2.1.12)
- LibXMTP (0.5.4-beta1)
- LibXMTP (0.5.4-beta2)
- Logging (1.0.0)
- MessagePacker (0.4.7)
- MMKV (1.3.5):
Expand Down Expand Up @@ -449,16 +449,16 @@ PODS:
- GenericJSON (~> 2.0)
- Logging (~> 1.0.0)
- secp256k1.swift (~> 0.1)
- XMTP (0.13.2):
- XMTP (0.13.3):
- Connect-Swift (= 0.12.0)
- GzipSwift
- LibXMTP (= 0.5.4-beta1)
- LibXMTP (= 0.5.4-beta2)
- web3.swift
- XMTPReactNative (0.1.0):
- ExpoModulesCore
- MessagePacker
- secp256k1.swift
- XMTP (= 0.13.2)
- XMTP (= 0.13.3)
- Yoga (1.14.0)

DEPENDENCIES:
Expand Down Expand Up @@ -711,7 +711,7 @@ SPEC CHECKSUMS:
GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa
hermes-engine: d7cc127932c89c53374452d6f93473f1970d8e88
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
LibXMTP: f080197cea545a7daf3bc8476d97efc3b225a8d8
LibXMTP: 16096f324c99d44712ed40876fe25150f694feab
Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26
MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02
MMKV: 506311d0494023c2f7e0b62cc1f31b7370fa3cfb
Expand Down Expand Up @@ -763,8 +763,8 @@ SPEC CHECKSUMS:
secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634
SwiftProtobuf: 407a385e97fd206c4fbe880cc84123989167e0d1
web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959
XMTP: 76ac90da19ba43afbde1382d57fbcdbdfe9491d8
XMTPReactNative: d3104af9a1504fb42b16c60888993d1d0516afae
XMTP: ca70dd11d709df02999325663e677fe775623d1e
XMTPReactNative: 1b79a6c8748387062ebcebe2c345f77f4998cae2
Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9

PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2
Expand Down
1 change: 0 additions & 1 deletion example/src/tests/groupPermissionsTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ test('can not remove a super admin from a group', async () => {

// Now bo can remove Alix from the group
await boGroup.removeMembers([alix.address])
console.log('alix inbox id:' + String(alix.inboxId))
await boGroup.sync()
numMembers = (await boGroup.memberInboxIds()).length
assert(
Expand Down
25 changes: 25 additions & 0 deletions ios/Wrappers/CreateGroupParamsWrapper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Foundation

struct CreateGroupParamsWrapper {
let groupName: String
let groupImageUrlSquare: String
let groupDescription: String
let groupPinnedFrameUrl: String

static func createGroupParamsFromJson(_ authParams: String) -> CreateGroupParamsWrapper {
let data = authParams.data(using: .utf8) ?? Data()
let jsonOptions = (try? JSONSerialization.jsonObject(with: data, options: [])) as? [String: Any] ?? [:]

let groupName = jsonOptions["name"] as? String ?? ""
let groupImageUrlSquare = jsonOptions["imageUrlSquare"] as? String ?? ""
let groupDescription = jsonOptions["description"] as? String ?? ""
let groupPinnedFrameUrl = jsonOptions["pinnedFrameUrl"] as? String ?? ""

return CreateGroupParamsWrapper(
groupName: groupName,
groupImageUrlSquare: groupImageUrlSquare,
groupDescription: groupDescription,
groupPinnedFrameUrl: groupPinnedFrameUrl
)
}
}
4 changes: 0 additions & 4 deletions ios/Wrappers/GroupWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import XMTP
// Wrapper around XMTP.Group to allow passing these objects back into react native.
struct GroupWrapper {
static func encodeToObj(_ group: XMTP.Group, client: XMTP.Client) throws -> [String: Any] {
let permissionPolicySet = try PermissionPolicySetWrapper.encodeToJsonString(group.permissionPolicySet())
return [
"clientAddress": client.address,
"id": group.id.toHex,
Expand All @@ -20,10 +19,7 @@ struct GroupWrapper {
"version": "GROUP",
"topic": group.topic,
"creatorInboxId": try group.creatorInboxId(),
"name": try group.groupName(),
"isActive": try group.isActive(),
"imageUrlSquare": try group.groupImageUrlSquare(),
"description": try group.groupDescription(),
]
}

Expand Down
3 changes: 2 additions & 1 deletion ios/Wrappers/PermissionPolicySetWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class PermissionPolicySetWrapper {
"removeAdminPolicy": fromPermissionOption(policySet.removeAdminPolicy),
"updateGroupNamePolicy": fromPermissionOption(policySet.updateGroupNamePolicy),
"updateGroupDescriptionPolicy": fromPermissionOption(policySet.updateGroupDescriptionPolicy),
"updateGroupImagePolicy": fromPermissionOption(policySet.updateGroupImagePolicy)
"updateGroupImagePolicy": fromPermissionOption(policySet.updateGroupImagePolicy),
"updateGroupPinnedFrameUrlPolicy": fromPermissionOption(policySet.updateGroupPinnedFrameUrlPolicy)
]
}

Expand Down
46 changes: 44 additions & 2 deletions ios/XMTPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ public class XMTPModule: Module {
}
}

AsyncFunction("createGroup") { (inboxId: String, peerAddresses: [String], permission: String, groupName: String, groupImageUrlSquare: String, groupDescription: String) -> String in
AsyncFunction("createGroup") { (inboxId: String, peerAddresses: [String], permission: String, groupOptionsJson: String) -> String in
guard let client = await clientsManager.getClient(key: inboxId) else {
throw Error.noClient
}
Expand All @@ -709,7 +709,15 @@ public class XMTPModule: Module {
}
}()
do {
let group = try await client.conversations.newGroup(with: peerAddresses, permissions: permissionLevel, name: groupName, imageUrlSquare: groupImageUrlSquare, description: groupDescription)
let createGroupParams = CreateGroupParamsWrapper.createGroupParamsFromJson(groupOptionsJson)
let group = try await client.conversations.newGroup(
with: peerAddresses,
permissions: permissionLevel,
name: createGroupParams.groupName,
imageUrlSquare: createGroupParams.groupImageUrlSquare,
description: createGroupParams.groupDescription,
pinnedFrameUrl: createGroupParams.groupPinnedFrameUrl
)
return try GroupWrapper.encode(group, client: client)
} catch {
print("ERRRO!: \(error.localizedDescription)")
Expand Down Expand Up @@ -877,6 +885,30 @@ public class XMTPModule: Module {

try await group.updateGroupDescription(groupDescription: description)
}

AsyncFunction("groupPinnedFrameUrl") { (inboxId: String, id: String) -> String in
guard let client = await clientsManager.getClient(key: inboxId) else {
throw Error.noClient
}

guard let group = try await findGroup(inboxId: inboxId, id: id) else {
throw Error.conversationNotFound("no group found for \(id)")
}

return try group.groupPinnedFrameUrl()
}

AsyncFunction("updateGroupPinnedFrameUrl") { (inboxId: String, id: String, pinnedFrameUrl: String) in
guard let client = await clientsManager.getClient(key: inboxId) else {
throw Error.noClient
}

guard let group = try await findGroup(inboxId: inboxId, id: id) else {
throw Error.conversationNotFound("no group found for \(id)")
}

try await group.updateGroupPinnedFrameUrl(groupPinnedFrameUrl: pinnedFrameUrl)
}

AsyncFunction("isGroupActive") { (inboxId: String, id: String) -> Bool in
guard let client = await clientsManager.getClient(key: inboxId) else {
Expand Down Expand Up @@ -1057,6 +1089,16 @@ public class XMTPModule: Module {
}
try await group.updateGroupDescriptionPermission(newPermissionOption: getPermissionOption(permission: newPermission))
}

AsyncFunction("updateGroupPinnedFrameUrlPermission") { (clientInboxId: String, id: String, newPermission: String) in
guard let client = await clientsManager.getClient(key: clientInboxId) else {
throw Error.noClient
}
guard let group = try await findGroup(inboxId: clientInboxId, id: id) else {
throw Error.conversationNotFound("no group found for \(id)")
}
try await group.updateGroupPinnedFrameUrlPermission(newPermissionOption: getPermissionOption(permission: newPermission))
}

AsyncFunction("permissionPolicySet") { (inboxId: String, id: String) async throws -> String in

Expand Down
2 changes: 1 addition & 1 deletion ios/XMTPReactNative.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ Pod::Spec.new do |s|
s.source_files = "**/*.{h,m,swift}"
s.dependency 'secp256k1.swift'
s.dependency "MessagePacker"
s.dependency "XMTP", "= 0.13.2"
s.dependency "XMTP", "= 0.13.3"
end

0 comments on commit fb74c00

Please sign in to comment.