@@ -82,6 +82,7 @@ class Client() {
82
82
lateinit var apiClient: ApiClient
83
83
lateinit var contacts: Contacts
84
84
lateinit var conversations: Conversations
85
+ var dbPath: String = " "
85
86
var logger: XMTPLogger = XMTPLogger ()
86
87
val libXMTPVersion: String = getVersionInfo()
87
88
private var libXMTPClient: FfiXmtpClient ? = null
@@ -160,6 +161,7 @@ class Client() {
160
161
privateKeyBundleV1: PrivateKeyBundleV1 ,
161
162
apiClient: ApiClient ,
162
163
libXMTPClient: FfiXmtpClient ? = null ,
164
+ dbPath: String = " "
163
165
) : this () {
164
166
this .address = address
165
167
this .privateKeyBundleV1 = privateKeyBundleV1
@@ -168,6 +170,7 @@ class Client() {
168
170
this .libXMTPClient = libXMTPClient
169
171
this .conversations =
170
172
Conversations (client = this , libXMTPConversations = libXMTPClient?.conversations())
173
+ this .dbPath = dbPath
171
174
}
172
175
173
176
fun buildFrom (
@@ -179,7 +182,7 @@ class Client() {
179
182
val clientOptions = options ? : ClientOptions ()
180
183
val apiClient =
181
184
GRPCApiClient (environment = clientOptions.api.env, secure = clientOptions.api.isSecure)
182
- val v3Client: FfiXmtpClient ? = if (isAlphaMlsEnabled(options)) {
185
+ val ( v3Client, dbPath) = if (isAlphaMlsEnabled(options)) {
183
186
runBlocking {
184
187
ffiXmtpClient(
185
188
options,
@@ -190,13 +193,14 @@ class Client() {
190
193
address
191
194
)
192
195
}
193
- } else null
196
+ } else Pair ( null , " " )
194
197
195
198
return Client (
196
199
address = address,
197
200
privateKeyBundleV1 = bundle,
198
201
apiClient = apiClient,
199
- libXMTPClient = v3Client
202
+ libXMTPClient = v3Client,
203
+ dbPath = dbPath
200
204
)
201
205
}
202
206
@@ -226,7 +230,7 @@ class Client() {
226
230
apiClient,
227
231
options
228
232
)
229
- val libXMTPClient: FfiXmtpClient ? =
233
+ val ( libXMTPClient, dbPath) =
230
234
ffiXmtpClient(
231
235
options,
232
236
account,
@@ -236,7 +240,7 @@ class Client() {
236
240
account.address
237
241
)
238
242
val client =
239
- Client (account.address, privateKeyBundleV1, apiClient, libXMTPClient)
243
+ Client (account.address, privateKeyBundleV1, apiClient, libXMTPClient, dbPath )
240
244
client.ensureUserContactPublished()
241
245
client
242
246
} catch (e: java.lang.Exception ) {
@@ -261,7 +265,7 @@ class Client() {
261
265
val newOptions = options ? : ClientOptions ()
262
266
val apiClient =
263
267
GRPCApiClient (environment = newOptions.api.env, secure = newOptions.api.isSecure)
264
- val v3Client: FfiXmtpClient ? = if (isAlphaMlsEnabled(options)) {
268
+ val ( v3Client, dbPath) = if (isAlphaMlsEnabled(options)) {
265
269
runBlocking {
266
270
ffiXmtpClient(
267
271
options,
@@ -272,13 +276,14 @@ class Client() {
272
276
address
273
277
)
274
278
}
275
- } else null
279
+ } else Pair ( null , " " )
276
280
277
281
return Client (
278
282
address = address,
279
283
privateKeyBundleV1 = v1Bundle,
280
284
apiClient = apiClient,
281
- libXMTPClient = v3Client
285
+ libXMTPClient = v3Client,
286
+ dbPath = dbPath
282
287
)
283
288
}
284
289
@@ -293,12 +298,13 @@ class Client() {
293
298
privateKeyBundleV1 : PrivateKeyBundleV1 ,
294
299
legacyIdentitySource : LegacyIdentitySource ,
295
300
accountAddress : String ,
296
- ): FfiXmtpClient ? {
301
+ ): Pair <FfiXmtpClient ?, String > {
302
+ var dbPath = " "
297
303
val v3Client: FfiXmtpClient ? =
298
304
if (isAlphaMlsEnabled(options)) {
299
305
val alias = " xmtp-${options!! .api.env} -${accountAddress.lowercase()} "
300
306
301
- val dbPath = if (options.dbPath == null ) {
307
+ dbPath = if (options.dbPath == null ) {
302
308
val dbDir = File (appContext?.filesDir?.absolutePath, " xmtp_db" )
303
309
dbDir.mkdir()
304
310
dbDir.absolutePath + " /$alias .db3"
@@ -364,7 +370,7 @@ class Client() {
364
370
}
365
371
}
366
372
Log .i(TAG , " LibXMTP $libXMTPVersion " )
367
- return v3Client
373
+ return Pair ( v3Client, dbPath)
368
374
}
369
375
370
376
/* *
@@ -586,6 +592,10 @@ class Client() {
586
592
return ! statuses.contains(false )
587
593
}
588
594
595
+ fun deleteLocalDatabase () {
596
+ File (dbPath).delete()
597
+ }
598
+
589
599
val privateKeyBundle: PrivateKeyBundle
590
600
get() = PrivateKeyBundleBuilder .buildFromV1Key(privateKeyBundleV1)
591
601
0 commit comments