@@ -41,9 +41,11 @@ import org.xmtp.android.library.messages.walletAddress
41
41
import org.xmtp.proto.message.api.v1.MessageApiOuterClass
42
42
import org.xmtp.proto.message.api.v1.MessageApiOuterClass.BatchQueryResponse
43
43
import org.xmtp.proto.message.api.v1.MessageApiOuterClass.QueryRequest
44
+ import uniffi.xmtpv3.FfiV2ApiClient
44
45
import uniffi.xmtpv3.FfiXmtpClient
45
46
import uniffi.xmtpv3.LegacyIdentitySource
46
47
import uniffi.xmtpv3.createClient
48
+ import uniffi.xmtpv3.createV2Client
47
49
import uniffi.xmtpv3.getVersionInfo
48
50
import java.io.File
49
51
import java.nio.charset.StandardCharsets
@@ -86,6 +88,7 @@ class Client() {
86
88
val libXMTPVersion: String = getVersionInfo()
87
89
private var libXMTPClient: FfiXmtpClient ? = null
88
90
private var dbPath: String = " "
91
+ private lateinit var v2RustClient: FfiV2ApiClient
89
92
90
93
companion object {
91
94
private const val TAG = " Client"
@@ -160,12 +163,14 @@ class Client() {
160
163
address: String ,
161
164
privateKeyBundleV1: PrivateKeyBundleV1 ,
162
165
apiClient: ApiClient ,
166
+ v2Client: FfiV2ApiClient ,
163
167
libXMTPClient: FfiXmtpClient ? = null ,
164
168
dbPath: String = " " ,
165
169
) : this () {
166
170
this .address = address
167
171
this .privateKeyBundleV1 = privateKeyBundleV1
168
172
this .apiClient = apiClient
173
+ this .v2RustClient = v2Client
169
174
this .contacts = Contacts (client = this )
170
175
this .libXMTPClient = libXMTPClient
171
176
this .conversations =
@@ -180,6 +185,12 @@ class Client() {
180
185
): Client {
181
186
val address = bundle.identityKey.publicKey.recoverWalletSignerPublicKey().walletAddress
182
187
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
+ }
183
194
val apiClient =
184
195
GRPCApiClient (environment = clientOptions.api.env, secure = clientOptions.api.isSecure)
185
196
val (v3Client, dbPath) = if (isAlphaMlsEnabled(options)) {
@@ -199,6 +210,7 @@ class Client() {
199
210
address = address,
200
211
privateKeyBundleV1 = bundle,
201
212
apiClient = apiClient,
213
+ v2Client = v2Client,
202
214
libXMTPClient = v3Client,
203
215
dbPath = dbPath
204
216
)
@@ -223,24 +235,36 @@ class Client() {
223
235
apiClient : ApiClient ,
224
236
options : ClientOptions ? = null,
225
237
): Client {
238
+ val clientOptions = options ? : ClientOptions ()
226
239
return runBlocking {
227
240
try {
228
241
val (privateKeyBundleV1, legacyIdentityKey) = loadOrCreateKeys(
229
242
account,
230
243
apiClient,
231
- options
244
+ clientOptions
232
245
)
233
246
val (libXMTPClient, dbPath) =
234
247
ffiXmtpClient(
235
248
options,
236
249
account,
237
- options? .appContext,
250
+ clientOptions .appContext,
238
251
privateKeyBundleV1,
239
252
legacyIdentityKey,
240
253
account.address
241
254
)
255
+ val v2Client = createV2Client(
256
+ host = " http://${clientOptions.api.env.getValue()} :5556" ,
257
+ isSecure = clientOptions.api.isSecure
258
+ )
242
259
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
+ )
244
268
client.ensureUserContactPublished()
245
269
client
246
270
} catch (e: java.lang.Exception ) {
@@ -263,6 +287,12 @@ class Client() {
263
287
): Client {
264
288
val address = v1Bundle.identityKey.publicKey.recoverWalletSignerPublicKey().walletAddress
265
289
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
+ }
266
296
val apiClient =
267
297
GRPCApiClient (environment = newOptions.api.env, secure = newOptions.api.isSecure)
268
298
val (v3Client, dbPath) = if (isAlphaMlsEnabled(options)) {
@@ -282,6 +312,7 @@ class Client() {
282
312
address = address,
283
313
privateKeyBundleV1 = v1Bundle,
284
314
apiClient = apiClient,
315
+ v2Client = v2Client,
285
316
libXMTPClient = v3Client,
286
317
dbPath = dbPath
287
318
)
0 commit comments