Skip to content

Commit

Permalink
Expose dbPath and static inboxId (#281)
Browse files Browse the repository at this point in the history
* make public and move to companion object

* add a test

* add another test
  • Loading branch information
nplasterer authored Jul 31, 2024
1 parent 773eb34 commit 85c8bb2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,24 @@ class ClientTest {
val key = SecureRandom().generateSeed(32)
val context = InstrumentationRegistry.getInstrumentation().targetContext
val fakeWallet = PrivateKeyBuilder()
val options = ClientOptions(
ClientOptions.Api(XMTPEnvironment.LOCAL, false),
enableV3 = true,
appContext = context,
dbEncryptionKey = key
)
val inboxId = runBlocking { Client.getOrCreateInboxId(options, fakeWallet.address) }
val client = runBlocking {
Client().create(
account = fakeWallet,
options = ClientOptions(
ClientOptions.Api(XMTPEnvironment.LOCAL, false),
enableV3 = true,
appContext = context,
dbEncryptionKey = key
)
options = options
)
}
runBlocking {
client.canMessageV3(listOf(client.address))[client.address]?.let { assert(it) }
}
assert(client.installationId.isNotEmpty())
assertEquals(inboxId, client.inboxId)
}

@Test
Expand Down Expand Up @@ -178,6 +181,7 @@ class ClientTest {
assertEquals(client.conversations.listGroups().size, 1)
}

assert(client.dbPath.isNotEmpty())
client.deleteLocalDatabase()

client = runBlocking {
Expand Down
28 changes: 14 additions & 14 deletions library/src/main/java/org/xmtp/android/library/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Client() {
val libXMTPVersion: String = getVersionInfo()
var installationId: String = ""
private var v3Client: FfiXmtpClient? = null
private var dbPath: String = ""
var dbPath: String = ""
lateinit var inboxId: String

companion object {
Expand All @@ -96,6 +96,19 @@ class Client() {
registry
}

suspend fun getOrCreateInboxId(options: ClientOptions, address: String): String {
var inboxId = getInboxIdForAddress(
logger = XMTPLogger(),
host = options.api.env.getUrl(),
isSecure = options.api.isSecure,
accountAddress = address
)
if (inboxId.isNullOrBlank()) {
inboxId = generateInboxId(address, 0.toULong())
}
return inboxId
}

fun register(codec: ContentCodec<*>) {
codecRegistry.register(codec = codec)
}
Expand Down Expand Up @@ -620,19 +633,6 @@ class Client() {
v3Client?.dbReconnect() ?: throw XMTPException("Error no V3 client initialized")
}

suspend fun getOrCreateInboxId(options: ClientOptions, address: String): String {
var inboxId = getInboxIdForAddress(
logger = logger,
host = options.api.env.getUrl(),
isSecure = options.api.isSecure,
accountAddress = address
)
if (inboxId.isNullOrBlank()) {
inboxId = generateInboxId(address, 0.toULong())
}
return inboxId
}

suspend fun requestMessageHistorySync() {
v3Client?.requestHistorySync() ?: throw XMTPException("Error no V3 client initialized")
}
Expand Down

0 comments on commit 85c8bb2

Please sign in to comment.