Skip to content

Commit

Permalink
update swift side of the code
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Sep 26, 2024
1 parent 8600996 commit d703bb6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 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.8-beta6)
- LibXMTP (0.5.8-beta7)
- Logging (1.0.0)
- MessagePacker (0.4.7)
- MMKV (1.3.9):
Expand Down Expand Up @@ -449,16 +449,16 @@ PODS:
- GenericJSON (~> 2.0)
- Logging (~> 1.0.0)
- secp256k1.swift (~> 0.1)
- XMTP (0.14.14):
- XMTP (0.14.16):
- Connect-Swift (= 0.12.0)
- GzipSwift
- LibXMTP (= 0.5.8-beta6)
- LibXMTP (= 0.5.8-beta7)
- web3.swift
- XMTPReactNative (0.1.0):
- ExpoModulesCore
- MessagePacker
- secp256k1.swift
- XMTP (= 0.14.14)
- XMTP (= 0.14.16)
- Yoga (1.14.0)

DEPENDENCIES:
Expand Down Expand Up @@ -711,7 +711,7 @@ SPEC CHECKSUMS:
GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa
hermes-engine: d7cc127932c89c53374452d6f93473f1970d8e88
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
LibXMTP: c7338cace222bed90f950579300725325a2c0bfd
LibXMTP: 693447f2c1242dd2f5b2146828c52dbb2bd92d6f
Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26
MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02
MMKV: 817ba1eea17421547e01e087285606eb270a8dcb
Expand Down Expand Up @@ -763,8 +763,8 @@ SPEC CHECKSUMS:
secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634
SwiftProtobuf: 407a385e97fd206c4fbe880cc84123989167e0d1
web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959
XMTP: 37621f1258b12629af305e6697414ccb2fbd4ea8
XMTPReactNative: 7bec275ed26997e6a73f06a678c328e6ba852cd5
XMTP: 8a61cf9d60450a1b7c30521a0283e258d3509a0d
XMTPReactNative: fb305f7d351caeefcb933345982ca29777e7eeca
Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9

PODFILE CHECKSUM: 0e6fe50018f34e575d38dc6a1fdf1f99c9596cdd
Expand Down
8 changes: 4 additions & 4 deletions ios/Wrappers/GroupWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ 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] {
static func encodeToObj(_ group: XMTP.Group, client: XMTP.Client) async throws -> [String: Any] {
return [
"clientAddress": client.address,
"id": group.id,
"createdAt": UInt64(group.createdAt.timeIntervalSince1970 * 1000),
"members": try group.members.compactMap { member in return try MemberWrapper.encode(member) },
"members": try await group.members.compactMap { member in return try MemberWrapper.encode(member) },
"version": "GROUP",
"topic": group.topic,
"creatorInboxId": try group.creatorInboxId(),
Expand All @@ -28,8 +28,8 @@ struct GroupWrapper {
]
}

static func encode(_ group: XMTP.Group, client: XMTP.Client) throws -> String {
let obj = try encodeToObj(group, client: client)
static func encode(_ group: XMTP.Group, client: XMTP.Client) async throws -> String {
let obj = try await encodeToObj(group, client: client)
let data = try JSONSerialization.data(withJSONObject: obj)
guard let result = String(data: data, encoding: .utf8) else {
throw WrapperError.encodeError("could not encode group")
Expand Down
11 changes: 10 additions & 1 deletion ios/Wrappers/InboxStateWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct InboxStateWrapper {
return [
"inboxId": inboxState.inboxId,
"addresses": inboxState.addresses,
"installationIds": inboxState.installationIds,
"installations": inboxState.installations.map { Installation.encodeInstallation(installation: $0) },
"recoveryAddress": inboxState.recoveryAddress
]
}
Expand All @@ -28,3 +28,12 @@ struct InboxStateWrapper {
return result
}
}

struct Installation {
static func encodeInstallation(installation: XMTP.Installation) -> [String: Any] {
return [
"id": installation.id,
"createdAt": installation.createdAt?.timeIntervalSince1970 ?? NSNull()
]
}
}
16 changes: 8 additions & 8 deletions ios/XMTPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ public class XMTPModule: Module {
var results: [String] = []
for group in groupList {
await self.groupsManager.set(group.cacheKey(inboxId), group)
let encodedGroup = try GroupWrapper.encode(group, client: client)
let encodedGroup = try await GroupWrapper.encode(group, client: client)
results.append(encodedGroup)
}

Expand Down Expand Up @@ -644,7 +644,7 @@ public class XMTPModule: Module {
throw Error.noClient
}
if let group = try client.findGroup(groupId: groupId) {
return try GroupWrapper.encode(group, client: client)
return try await GroupWrapper.encode(group, client: client)
} else {
return nil
}
Expand Down Expand Up @@ -878,7 +878,7 @@ public class XMTPModule: Module {
description: createGroupParams.groupDescription,
pinnedFrameUrl: createGroupParams.groupPinnedFrameUrl
)
return try GroupWrapper.encode(group, client: client)
return try await GroupWrapper.encode(group, client: client)
} catch {
print("ERRRO!: \(error.localizedDescription)")
throw error
Expand All @@ -900,7 +900,7 @@ public class XMTPModule: Module {
description: createGroupParams.groupDescription,
pinnedFrameUrl: createGroupParams.groupPinnedFrameUrl
)
return try GroupWrapper.encode(group, client: client)
return try await GroupWrapper.encode(group, client: client)
} catch {
print("ERRRO!: \(error.localizedDescription)")
throw error
Expand All @@ -915,7 +915,7 @@ public class XMTPModule: Module {
guard let group = try await findGroup(inboxId: inboxId, id: groupId) else {
throw Error.conversationNotFound("no group found for \(groupId)")
}
return try group.members.map(\.inboxId)
return try await group.members.map(\.inboxId)
}

AsyncFunction("listGroupMembers") { (inboxId: String, groupId: String) -> [String] in
Expand All @@ -926,7 +926,7 @@ public class XMTPModule: Module {
guard let group = try await findGroup(inboxId: inboxId, id: groupId) else {
throw Error.conversationNotFound("no group found for \(groupId)")
}
return try group.members.compactMap { member in
return try await group.members.compactMap { member in
return try MemberWrapper.encode(member)
}
}
Expand Down Expand Up @@ -1333,7 +1333,7 @@ public class XMTPModule: Module {
throw Error.conversationNotFound("no group found")
}

return try GroupWrapper.encode(group, client: client)
return try await GroupWrapper.encode(group, client: client)
}

AsyncFunction("subscribeToConversations") { (inboxId: String) in
Expand Down Expand Up @@ -1811,7 +1811,7 @@ public class XMTPModule: Module {
await subscriptionsManager.set(getGroupsKey(inboxId: client.inboxID), Task {
do {
for try await group in try await client.conversations.streamGroups() {
try sendEvent("group", [
try await sendEvent("group", [
"inboxId": inboxId,
"group": GroupWrapper.encodeToObj(group, client: client),
])
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.14.14"
s.dependency "XMTP", "= 0.14.17"
end

0 comments on commit d703bb6

Please sign in to comment.