From d703bb60feb2486595ad909825de553c08c23682 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 26 Sep 2024 09:51:36 -0600 Subject: [PATCH] update swift side of the code --- example/ios/Podfile.lock | 14 +++++++------- ios/Wrappers/GroupWrapper.swift | 8 ++++---- ios/Wrappers/InboxStateWrapper.swift | 11 ++++++++++- ios/XMTPModule.swift | 16 ++++++++-------- ios/XMTPReactNative.podspec | 2 +- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 5c0dfc6bc..28aa9bd9c 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -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): @@ -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: @@ -711,7 +711,7 @@ SPEC CHECKSUMS: GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa hermes-engine: d7cc127932c89c53374452d6f93473f1970d8e88 libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913 - LibXMTP: c7338cace222bed90f950579300725325a2c0bfd + LibXMTP: 693447f2c1242dd2f5b2146828c52dbb2bd92d6f Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26 MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02 MMKV: 817ba1eea17421547e01e087285606eb270a8dcb @@ -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 diff --git a/ios/Wrappers/GroupWrapper.swift b/ios/Wrappers/GroupWrapper.swift index bab4d2082..76f827dd1 100644 --- a/ios/Wrappers/GroupWrapper.swift +++ b/ios/Wrappers/GroupWrapper.swift @@ -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(), @@ -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") diff --git a/ios/Wrappers/InboxStateWrapper.swift b/ios/Wrappers/InboxStateWrapper.swift index 62f0f2290..d7645943f 100644 --- a/ios/Wrappers/InboxStateWrapper.swift +++ b/ios/Wrappers/InboxStateWrapper.swift @@ -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 ] } @@ -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() + ] + } +} diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index d1c365eb4..2b5001e51 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -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) } @@ -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 } @@ -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 @@ -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 @@ -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 @@ -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) } } @@ -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 @@ -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), ]) diff --git a/ios/XMTPReactNative.podspec b/ios/XMTPReactNative.podspec index 5d012342e..dd72e3ee0 100644 --- a/ios/XMTPReactNative.podspec +++ b/ios/XMTPReactNative.podspec @@ -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