Skip to content

Commit 7e16d6c

Browse files
committed
add v2 rust client to the client creation methods
1 parent 35d5427 commit 7e16d6c

File tree

1 file changed

+34
-3
lines changed
  • library/src/main/java/org/xmtp/android/library

1 file changed

+34
-3
lines changed

library/src/main/java/org/xmtp/android/library/Client.kt

+34-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ import org.xmtp.android.library.messages.walletAddress
4141
import org.xmtp.proto.message.api.v1.MessageApiOuterClass
4242
import org.xmtp.proto.message.api.v1.MessageApiOuterClass.BatchQueryResponse
4343
import org.xmtp.proto.message.api.v1.MessageApiOuterClass.QueryRequest
44+
import uniffi.xmtpv3.FfiV2ApiClient
4445
import uniffi.xmtpv3.FfiXmtpClient
4546
import uniffi.xmtpv3.LegacyIdentitySource
4647
import uniffi.xmtpv3.createClient
48+
import uniffi.xmtpv3.createV2Client
4749
import uniffi.xmtpv3.getVersionInfo
4850
import java.io.File
4951
import java.nio.charset.StandardCharsets
@@ -86,6 +88,7 @@ class Client() {
8688
val libXMTPVersion: String = getVersionInfo()
8789
private var libXMTPClient: FfiXmtpClient? = null
8890
private var dbPath: String = ""
91+
private lateinit var v2RustClient: FfiV2ApiClient
8992

9093
companion object {
9194
private const val TAG = "Client"
@@ -160,12 +163,14 @@ class Client() {
160163
address: String,
161164
privateKeyBundleV1: PrivateKeyBundleV1,
162165
apiClient: ApiClient,
166+
v2Client: FfiV2ApiClient,
163167
libXMTPClient: FfiXmtpClient? = null,
164168
dbPath: String = "",
165169
) : this() {
166170
this.address = address
167171
this.privateKeyBundleV1 = privateKeyBundleV1
168172
this.apiClient = apiClient
173+
this.v2RustClient = v2Client
169174
this.contacts = Contacts(client = this)
170175
this.libXMTPClient = libXMTPClient
171176
this.conversations =
@@ -180,6 +185,12 @@ class Client() {
180185
): Client {
181186
val address = bundle.identityKey.publicKey.recoverWalletSignerPublicKey().walletAddress
182187
val clientOptions = options ?: ClientOptions()
188+
val v2Client = runBlocking {
189+
createV2Client(
190+
host = "http://${clientOptions.api.env.getValue()}:5556",
191+
isSecure = clientOptions.api.isSecure
192+
)
193+
}
183194
val apiClient =
184195
GRPCApiClient(environment = clientOptions.api.env, secure = clientOptions.api.isSecure)
185196
val (v3Client, dbPath) = if (isAlphaMlsEnabled(options)) {
@@ -199,6 +210,7 @@ class Client() {
199210
address = address,
200211
privateKeyBundleV1 = bundle,
201212
apiClient = apiClient,
213+
v2Client = v2Client,
202214
libXMTPClient = v3Client,
203215
dbPath = dbPath
204216
)
@@ -223,24 +235,36 @@ class Client() {
223235
apiClient: ApiClient,
224236
options: ClientOptions? = null,
225237
): Client {
238+
val clientOptions = options ?: ClientOptions()
226239
return runBlocking {
227240
try {
228241
val (privateKeyBundleV1, legacyIdentityKey) = loadOrCreateKeys(
229242
account,
230243
apiClient,
231-
options
244+
clientOptions
232245
)
233246
val (libXMTPClient, dbPath) =
234247
ffiXmtpClient(
235248
options,
236249
account,
237-
options?.appContext,
250+
clientOptions.appContext,
238251
privateKeyBundleV1,
239252
legacyIdentityKey,
240253
account.address
241254
)
255+
val v2Client = createV2Client(
256+
host = "http://${clientOptions.api.env.getValue()}:5556",
257+
isSecure = clientOptions.api.isSecure
258+
)
242259
val client =
243-
Client(account.address, privateKeyBundleV1, apiClient, libXMTPClient, dbPath)
260+
Client(
261+
account.address,
262+
privateKeyBundleV1,
263+
apiClient,
264+
v2Client,
265+
libXMTPClient,
266+
dbPath
267+
)
244268
client.ensureUserContactPublished()
245269
client
246270
} catch (e: java.lang.Exception) {
@@ -263,6 +287,12 @@ class Client() {
263287
): Client {
264288
val address = v1Bundle.identityKey.publicKey.recoverWalletSignerPublicKey().walletAddress
265289
val newOptions = options ?: ClientOptions()
290+
val v2Client = runBlocking {
291+
createV2Client(
292+
host = "http://${newOptions.api.env.getValue()}:5556",
293+
isSecure = newOptions.api.isSecure
294+
)
295+
}
266296
val apiClient =
267297
GRPCApiClient(environment = newOptions.api.env, secure = newOptions.api.isSecure)
268298
val (v3Client, dbPath) = if (isAlphaMlsEnabled(options)) {
@@ -282,6 +312,7 @@ class Client() {
282312
address = address,
283313
privateKeyBundleV1 = v1Bundle,
284314
apiClient = apiClient,
315+
v2Client = v2Client,
285316
libXMTPClient = v3Client,
286317
dbPath = dbPath
287318
)

0 commit comments

Comments
 (0)