Skip to content

Commit

Permalink
feat: Enable Group Chat for Production (#259)
Browse files Browse the repository at this point in the history
* rename all of the flags and remove the block on production

* write a test for it

* feat: groups in production
  • Loading branch information
nplasterer authored Jun 14, 2024
1 parent fb443cc commit afc47b9
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object ClientManager {
appVersion = "XMTPAndroidExample/v1.0.0",
isSecure = true
),
enableAlphaMls = true,
enableV3 = true,
appContext = appContext
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class ClientTest {
val fakeWallet = PrivateKeyBuilder()
val options = ClientOptions(
ClientOptions.Api(XMTPEnvironment.LOCAL, false),
enableAlphaMls = true,
enableV3 = true,
appContext = context
)
val client =
Expand Down Expand Up @@ -125,7 +125,7 @@ class ClientTest {
account = fakeWallet,
options = ClientOptions(
ClientOptions.Api(XMTPEnvironment.LOCAL, false),
enableAlphaMls = true,
enableV3 = true,
appContext = context
)
)
Expand All @@ -145,7 +145,7 @@ class ClientTest {
account = fakeWallet,
options = ClientOptions(
ClientOptions.Api(XMTPEnvironment.LOCAL, false),
enableAlphaMls = true,
enableV3 = true,
appContext = context
)
)
Expand All @@ -154,7 +154,7 @@ class ClientTest {
account = fakeWallet2,
options = ClientOptions(
ClientOptions.Api(XMTPEnvironment.LOCAL, false),
enableAlphaMls = true,
enableV3 = true,
appContext = context
)
)
Expand All @@ -172,7 +172,7 @@ class ClientTest {
account = fakeWallet,
options = ClientOptions(
ClientOptions.Api(XMTPEnvironment.LOCAL, false),
enableAlphaMls = true,
enableV3 = true,
appContext = context
)
)
Expand All @@ -192,7 +192,25 @@ class ClientTest {
account = fakeWallet,
options = ClientOptions(
ClientOptions.Api(XMTPEnvironment.DEV, true),
enableAlphaMls = true,
enableV3 = true,
appContext = context
)
)
runBlocking {
client.canMessageV3(listOf(client.address))[client.address]?.let { assert(it) }
}
}

@Test
fun testCreatesAV3ProductionClient() {
val context = InstrumentationRegistry.getInstrumentation().targetContext
val fakeWallet = PrivateKeyBuilder()
val client =
Client().create(
account = fakeWallet,
options = ClientOptions(
ClientOptions.Api(XMTPEnvironment.PRODUCTION, true),
enableV3 = true,
appContext = context
)
)
Expand Down Expand Up @@ -291,7 +309,7 @@ class ClientTest {
account = fakeWallet,
options = ClientOptions(
ClientOptions.Api(XMTPEnvironment.LOCAL, false),
enableAlphaMls = true,
enableV3 = true,
appContext = context
)
)
Expand All @@ -300,7 +318,7 @@ class ClientTest {
account = fakeWallet2,
options = ClientOptions(
ClientOptions.Api(XMTPEnvironment.LOCAL, false),
enableAlphaMls = true,
enableV3 = true,
appContext = context
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class GroupPermissionsTest {
fixtures(
clientOptions = ClientOptions(
ClientOptions.Api(XMTPEnvironment.LOCAL, false),
enableAlphaMls = true,
enableV3 = true,
appContext = context
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class GroupTest {
fixtures(
clientOptions = ClientOptions(
ClientOptions.Api(XMTPEnvironment.LOCAL, false),
enableAlphaMls = true,
enableV3 = true,
appContext = context
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class GroupUpdatedTest {
fixtures = fixtures(
clientOptions = ClientOptions(
ClientOptions.Api(XMTPEnvironment.LOCAL, false),
enableAlphaMls = true,
enableV3 = true,
appContext = context,
)
)
Expand Down
20 changes: 10 additions & 10 deletions library/src/main/java/org/xmtp/android/library/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ data class ClientOptions(
val preCreateIdentityCallback: PreEventCallback? = null,
val preEnableIdentityCallback: PreEventCallback? = null,
val appContext: Context? = null,
val enableAlphaMls: Boolean = false,
val enableV3: Boolean = false,
val dbDirectory: String? = null,
val dbEncryptionKey: ByteArray? = null,
) {
Expand All @@ -88,7 +88,7 @@ class Client() {
var logger: XMTPLogger = XMTPLogger()
val libXMTPVersion: String = getVersionInfo()
var installationId: String = ""
private var libXMTPClient: FfiXmtpClient? = null
private var v3Client: FfiXmtpClient? = null
private var dbPath: String = ""
var inboxId: String = ""

Expand Down Expand Up @@ -174,7 +174,7 @@ class Client() {
this.privateKeyBundleV1 = privateKeyBundleV1
this.apiClient = apiClient
this.contacts = Contacts(client = this)
this.libXMTPClient = libXMTPClient
this.v3Client = libXMTPClient
this.conversations =
Conversations(client = this, libXMTPConversations = libXMTPClient?.conversations())
this.dbPath = dbPath
Expand Down Expand Up @@ -267,7 +267,7 @@ class Client() {
environment = newOptions.api.env,
secure = newOptions.api.isSecure,
)
val (v3Client, dbPath) = if (isAlphaMlsEnabled(options)) {
val (v3Client, dbPath) = if (isV3Enabled(options)) {
runBlocking {
ffiXmtpClient(
options,
Expand All @@ -290,8 +290,8 @@ class Client() {
)
}

private fun isAlphaMlsEnabled(options: ClientOptions?): Boolean {
return (options != null && options.enableAlphaMls && options.api.env != XMTPEnvironment.PRODUCTION && options.appContext != null)
private fun isV3Enabled(options: ClientOptions?): Boolean {
return (options != null && options.enableV3 && options.appContext != null)
}

private suspend fun ffiXmtpClient(
Expand All @@ -304,7 +304,7 @@ class Client() {
var dbPath = ""
val accountAddress = address.lowercase()
val v3Client: FfiXmtpClient? =
if (isAlphaMlsEnabled(options)) {
if (isV3Enabled(options)) {
var inboxId = getInboxIdForAddress(
logger = logger,
host = options!!.api.env.getUrl(),
Expand Down Expand Up @@ -603,7 +603,7 @@ class Client() {
}

suspend fun canMessageV3(addresses: List<String>): Map<String, Boolean> {
libXMTPClient?.let {
v3Client?.let {
return it.canMessage(addresses)
}
throw XMTPException("Error no V3 client initialized")
Expand All @@ -617,11 +617,11 @@ class Client() {
message = "This function is delicate and should be used with caution. App will error if database not properly reconnected. See: reconnectLocalDatabase()",
)
fun dropLocalDatabaseConnection() {
libXMTPClient?.releaseDbConnection()
v3Client?.releaseDbConnection()
}

suspend fun reconnectLocalDatabase() {
libXMTPClient?.dbReconnect() ?: throw XMTPException("Error no V3 client initialized")
v3Client?.dbReconnect() ?: throw XMTPException("Error no V3 client initialized")
}

val privateKeyBundle: PrivateKeyBundle
Expand Down

0 comments on commit afc47b9

Please sign in to comment.