Skip to content

Commit

Permalink
make it faster
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Dec 18, 2024
1 parent 940825e commit fd6b8fc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class XMTPModule : Module() {
withContext(Dispatchers.IO) {
logV("connectToApiBackend")
val api = apiEnvironments(environment, null)
val xmtpApiClient = Client().connectToApiBackend(api)
val xmtpApiClient = Client.connectToApiBackend(api)
apiClient = xmtpApiClient
}
}
Expand All @@ -310,7 +310,8 @@ class XMTPModule : Module() {
authParams,
hasPreAuthenticateToInboxCallback,
)
val randomClient = Client().create(account = privateKey, options = options, apiClient = apiClient)
val randomClient =
Client().create(account = privateKey, options = options, apiClient = apiClient)

ContentJson.Companion
clients[randomClient.installationId] = randomClient
Expand All @@ -336,7 +337,8 @@ class XMTPModule : Module() {
authParams,
hasAuthInboxCallback,
)
val client = Client().create(account = reactSigner, options = options, apiClient = apiClient)
val client =
Client().create(account = reactSigner, options = options, apiClient = apiClient)
clients[client.installationId] = client
apiClient = client.apiClient
ContentJson.Companion
Expand All @@ -352,7 +354,12 @@ class XMTPModule : Module() {
dbEncryptionKey,
authParams,
)
val client = Client().build(address = address, options = options, inboxId = inboxId, apiClient = apiClient)
val client = Client().build(
address = address,
options = options,
inboxId = inboxId,
apiClient = apiClient
)
ContentJson.Companion
clients[client.installationId] = client
apiClient = client.apiClient
Expand Down Expand Up @@ -464,7 +471,8 @@ class XMTPModule : Module() {
Client.canMessage(
peerAddresses,
context,
apiEnvironments(environment, null)
apiEnvironments(environment, null),
apiClient = apiClient
)
}
}
Expand Down
20 changes: 16 additions & 4 deletions ios/XMTPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ actor IsolatedManager<T> {
public class XMTPModule: Module {
var signer: ReactNativeSigner?
let clientsManager = ClientsManager()
var apiClient: XmtpApiClient?
let subscriptionsManager = IsolatedManager<Task<Void, Never>>()
private var preAuthenticateToInboxCallbackDeferred: DispatchSemaphore?

Expand Down Expand Up @@ -219,6 +220,14 @@ public class XMTPModule: Module {
try signer?.handleSCW(id: requestID, signature: signature)
}

AsyncFunction("connectToApiBackend") {
(environment: String) in
let xmtpApiClient = try await XMTP.Client.connectToApiBackend(
api: createApiClient(env: environment)
)
apiClient = xmtpApiClient
}

AsyncFunction("createRandom") {
(
hasAuthenticateToInboxCallback: Bool?, dbEncryptionKey: [UInt8],
Expand All @@ -241,8 +250,8 @@ public class XMTPModule: Module {
preAuthenticateToInboxCallback: preAuthenticateToInboxCallback
)
let client = try await Client.create(
account: privateKey, options: options)

account: privateKey, options: options, apiClient: apiClient)
apiClient = client.apiClient
await clientsManager.updateClient(
key: client.installationID, client: client)
return try ClientWrapper.encodeToObj(client)
Expand Down Expand Up @@ -277,9 +286,10 @@ public class XMTPModule: Module {
preAuthenticateToInboxCallback: preAuthenticateToInboxCallback
)
let client = try await XMTP.Client.create(
account: signer, options: options)
account: signer, options: options, apiClient: apiClient)
await self.clientsManager.updateClient(
key: client.installationID, client: client)
apiClient = client.apiClient
self.signer = nil
self.sendEvent("authed", try ClientWrapper.encodeToObj(client))
}
Expand All @@ -299,9 +309,11 @@ public class XMTPModule: Module {
preAuthenticateToInboxCallback: preAuthenticateToInboxCallback
)
let client = try await XMTP.Client.build(
address: address, options: options, inboxId: inboxId)
address: address, options: options, inboxId: inboxId,
apiClient: apiClient)
await clientsManager.updateClient(
key: client.installationID, client: client)
apiClient = client.apiClient
return try ClientWrapper.encodeToObj(client)
}

Expand Down

0 comments on commit fd6b8fc

Please sign in to comment.