Skip to content

Commit

Permalink
inboxid or undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Jun 25, 2024
1 parent 55d104c commit 8d5d6ae
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
40 changes: 21 additions & 19 deletions ios/XMTPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ public class XMTPModule: Module {
}
}

AsyncFunction("findInboxIdFromAddress") { (inboxId: String, address: String) -> String in
AsyncFunction("findInboxIdFromAddress") { (inboxId: String, address: String) -> String? in
guard let client = await clientsManager.getClient(key: inboxId) else {
throw Error.noClient
}
client.inboxIdFromAddress(address: address)
return try await client.inboxIdFromAddress(address: address)
}

AsyncFunction("deleteLocalDatabase") { (inboxId: String) in
Expand Down Expand Up @@ -137,25 +137,27 @@ public class XMTPModule: Module {
//
// Auth functions
//
AsyncFunction("auth") { (address: String, environment: String, appVersion: String?, hasCreateIdentityCallback: Bool?, hasEnableIdentityCallback: Bool?, enableV3: Bool?, dbEncryptionKey: [UInt8]?, dbDirectory: String?, historySyncUrl: String?) in
AsyncFunction("auth") {
{ (address: String, environment: String, appVersion: String?, hasCreateIdentityCallback: Bool?, hasEnableIdentityCallback: Bool?, enableV3: Bool?, dbEncryptionKey: [UInt8]?, dbDirectory: String?, historySyncUrl: String?) in

let signer = ReactNativeSigner(module: self, address: address)
self.signer = signer
if(hasCreateIdentityCallback ?? false) {
preCreateIdentityCallbackDeferred = DispatchSemaphore(value: 0)
}
if(hasEnableIdentityCallback ?? false) {
preEnableIdentityCallbackDeferred = DispatchSemaphore(value: 0)
let signer = ReactNativeSigner(module: self, address: address)
self.signer = signer
if(hasCreateIdentityCallback ?? false) {
self.preCreateIdentityCallbackDeferred = DispatchSemaphore(value: 0)
}
if(hasEnableIdentityCallback ?? false) {
self.preEnableIdentityCallbackDeferred = DispatchSemaphore(value: 0)
}
let preCreateIdentityCallback: PreEventCallback? = hasCreateIdentityCallback ?? false ? self.preCreateIdentityCallback : nil
let preEnableIdentityCallback: PreEventCallback? = hasEnableIdentityCallback ?? false ? self.preEnableIdentityCallback : nil
let encryptionKeyData = dbEncryptionKey == nil ? nil : Data(dbEncryptionKey!)

let options = self.createClientConfig(env: environment, appVersion: appVersion, preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, enableV3: enableV3 == true, dbEncryptionKey: encryptionKeyData, dbDirectory: dbDirectory, historySyncUrl: historySyncUrl)
let client = try await XMTP.Client.create(account: signer, options: options)
await self.clientsManager.updateClient(key: client.inboxID, client: client)
self.signer = nil
self.sendEvent("authed", try ClientWrapper.encodeToObj(client))
}
let preCreateIdentityCallback: PreEventCallback? = hasCreateIdentityCallback ?? false ? self.preCreateIdentityCallback : nil
let preEnableIdentityCallback: PreEventCallback? = hasEnableIdentityCallback ?? false ? self.preEnableIdentityCallback : nil
let encryptionKeyData = dbEncryptionKey == nil ? nil : Data(dbEncryptionKey!)

let options = createClientConfig(env: environment, appVersion: appVersion, preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, enableV3: enableV3 == true, dbEncryptionKey: encryptionKeyData, dbDirectory: dbDirectory, historySyncUrl: historySyncUrl)
let client = try await XMTP.Client.create(account: signer, options: options)
await clientsManager.updateClient(key: client.inboxID, client: client)
self.signer = nil
sendEvent("authed", try ClientWrapper.encodeToObj(client))
}

Function("receiveSignature") { (requestID: String, signature: String) in
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function inboxId(): string {
export async function findInboxIdFromAddress(
inboxId: string,
address: string
): Promise<InboxId> {
): Promise<InboxId | undefined> {
return XMTPModule.findInboxIdFromAddress(inboxId, address)
}

Expand Down
4 changes: 3 additions & 1 deletion src/lib/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,9 @@ export class Client<
* @param {string} peerAddress - The address of the peer to check for inboxId.
* @returns {Promise<InboxId>} A Promise resolving to the InboxId.
*/
async findInboxIdFromAddress(peerAddress: string): Promise<InboxId> {
async findInboxIdFromAddress(
peerAddress: string
): Promise<InboxId | undefined> {
return await XMTPModule.findInboxIdFromAddress(this.inboxId, peerAddress)
}

Expand Down

0 comments on commit 8d5d6ae

Please sign in to comment.