Skip to content

Commit

Permalink
fix: add the installation id on ios as well
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Jun 10, 2024
1 parent f8ceabd commit e413cd9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
29 changes: 29 additions & 0 deletions ios/Wrappers/ClientWrapper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// ClientWrapper.swift
// XMTPReactNative
//
// Created by Naomi Plasterer on 6/10/24.
//

import Foundation
import XMTP

// Wrapper around XMTP.Client to allow passing these objects back into react native.
struct ClientWrapper {
static func encodeToObj(_ client: XMTP.Client) throws -> [String: Any] {
return [
"inboxId": client.inboxID,
"address": client.address,
"installationId": client.installationID,
]
}

static func encode(_ client: XMTP.Client) throws -> String {
let obj = try encodeToObj(client)
let data = try JSONSerialization.data(withJSONObject: obj)
guard let result = String(data: data, encoding: .utf8) else {
throw WrapperError.encodeError("could not encode client")
}
return result
}
}
2 changes: 1 addition & 1 deletion ios/Wrappers/MemberWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation
import XMTP

// Wrapper around XMTP.Group to allow passing these objects back into react native.
// Wrapper around XMTP.Member to allow passing these objects back into react native.
struct MemberWrapper {
static func encodeToObj(_ member: XMTP.Member) throws -> [String: Any] {
let permissionString = switch member.permissionLevel {
Expand Down
12 changes: 3 additions & 9 deletions ios/XMTPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public class XMTPModule: Module {
let client = try await XMTP.Client.create(account: signer, options: options)
await clientsManager.updateClient(key: address, client: client)
self.signer = nil
sendEvent("authed", ["inboxId": client.inboxID])
sendEvent("authed", try ClientWrapper.encodeToObj(client))
}

Function("receiveSignature") { (requestID: String, signature: String) in
Expand All @@ -168,10 +168,7 @@ public class XMTPModule: Module {
let client = try await Client.create(account: privateKey, options: options)

await clientsManager.updateClient(key: client.address, client: client)
return [
"address": client.address,
"inboxId": client.inboxID
]
return try ClientWrapper.encodeToObj(client)
}

// Create a client using its serialized key bundle.
Expand All @@ -188,10 +185,7 @@ public class XMTPModule: Module {
let options = createClientConfig(env: environment, appVersion: appVersion, mlsAlpha: enableAlphaMls == true, encryptionKey: encryptionKeyData, dbDirectory: dbDirectory)
let client = try await Client.from(bundle: bundle, options: options)
await clientsManager.updateClient(key: client.address, client: client)
return [
"address": client.address,
"inboxId": client.inboxID
]
return try ClientWrapper.encodeToObj(client)
} catch {
print("ERRO! Failed to create client: \(error)")
throw error
Expand Down

0 comments on commit e413cd9

Please sign in to comment.