Skip to content

Commit

Permalink
Merge pull request #420 from xmtp/np/production-release
Browse files Browse the repository at this point in the history
Enable Group Chat in Production
  • Loading branch information
nplasterer authored Jun 17, 2024
2 parents 30e6970 + 9f6a41e commit 0004729
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 102 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ repositories {
dependencies {
implementation project(':expo-modules-core')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
implementation "org.xmtp:android:0.12.5"
implementation "org.xmtp:android:0.13.5"
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.facebook.react:react-native:0.71.3'
implementation "com.daveanthonythomas.moshipack:moshipack:1.0.1"
Expand Down
29 changes: 10 additions & 19 deletions android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ class XMTPModule : Module() {
}

AsyncFunction("deleteLocalDatabase") { inboxId: String ->
logV("LOPI")
logV(inboxId)
logV(clients.toString())
val client = clients[inboxId] ?: throw XMTPException("No client")
Expand All @@ -213,9 +212,8 @@ class XMTPModule : Module() {
//
// Auth functions
//
AsyncFunction("auth") { address: String, environment: String, appVersion: String?, hasCreateIdentityCallback: Boolean?, hasEnableIdentityCallback: Boolean?, enableAlphaMls: Boolean?, dbEncryptionKey: List<Int>?, dbDirectory: String? ->
AsyncFunction("auth") { address: String, environment: String, appVersion: String?, hasCreateIdentityCallback: Boolean?, hasEnableIdentityCallback: Boolean?, enableV3: Boolean?, dbEncryptionKey: List<Int>?, dbDirectory: String? ->
logV("auth")
requireNotProductionEnvForAlphaMLS(enableAlphaMls, environment)
val reactSigner = ReactNativeSigner(module = this@XMTPModule, address = address)
signer = reactSigner

Expand All @@ -227,7 +225,7 @@ class XMTPModule : Module() {
preCreateIdentityCallback.takeIf { hasCreateIdentityCallback == true }
val preEnableIdentityCallback: PreEventCallback? =
preEnableIdentityCallback.takeIf { hasEnableIdentityCallback == true }
val context = if (enableAlphaMls == true) context else null
val context = if (enableV3 == true) context else null
val encryptionKeyBytes =
dbEncryptionKey?.foldIndexed(ByteArray(dbEncryptionKey.size)) { i, a, v ->
a.apply { set(i, v.toByte()) }
Expand All @@ -237,7 +235,7 @@ class XMTPModule : Module() {
api = apiEnvironments(environment, appVersion),
preCreateIdentityCallback = preCreateIdentityCallback,
preEnableIdentityCallback = preEnableIdentityCallback,
enableAlphaMls = enableAlphaMls == true,
enableV3 = enableV3 == true,
appContext = context,
dbEncryptionKey = encryptionKeyBytes,
dbDirectory = dbDirectory
Expand All @@ -255,9 +253,8 @@ class XMTPModule : Module() {
}

// Generate a random wallet and set the client to that
AsyncFunction("createRandom") { environment: String, appVersion: String?, hasCreateIdentityCallback: Boolean?, hasEnableIdentityCallback: Boolean?, enableAlphaMls: Boolean?, dbEncryptionKey: List<Int>?, dbDirectory: String? ->
AsyncFunction("createRandom") { environment: String, appVersion: String?, hasCreateIdentityCallback: Boolean?, hasEnableIdentityCallback: Boolean?, enableV3: Boolean?, dbEncryptionKey: List<Int>?, dbDirectory: String? ->
logV("createRandom")
requireNotProductionEnvForAlphaMLS(enableAlphaMls, environment)
val privateKey = PrivateKeyBuilder()

if (hasCreateIdentityCallback == true)
Expand All @@ -268,7 +265,7 @@ class XMTPModule : Module() {
preCreateIdentityCallback.takeIf { hasCreateIdentityCallback == true }
val preEnableIdentityCallback: PreEventCallback? =
preEnableIdentityCallback.takeIf { hasEnableIdentityCallback == true }
val context = if (enableAlphaMls == true) context else null
val context = if (enableV3 == true) context else null
val encryptionKeyBytes =
dbEncryptionKey?.foldIndexed(ByteArray(dbEncryptionKey.size)) { i, a, v ->
a.apply { set(i, v.toByte()) }
Expand All @@ -278,30 +275,30 @@ class XMTPModule : Module() {
api = apiEnvironments(environment, appVersion),
preCreateIdentityCallback = preCreateIdentityCallback,
preEnableIdentityCallback = preEnableIdentityCallback,
enableAlphaMls = enableAlphaMls == true,
enableV3 = enableV3 == true,
appContext = context,
dbEncryptionKey = encryptionKeyBytes,
dbDirectory = dbDirectory
)
val randomClient = Client().create(account = privateKey, options = options)

ContentJson.Companion
clients[randomClient.inboxId] = randomClient
ClientWrapper.encodeToObj(randomClient)
}

AsyncFunction("createFromKeyBundle") { keyBundle: String, environment: String, appVersion: String?, enableAlphaMls: Boolean?, dbEncryptionKey: List<Int>?, dbDirectory: String? ->
AsyncFunction("createFromKeyBundle") { keyBundle: String, environment: String, appVersion: String?, enableV3: Boolean?, dbEncryptionKey: List<Int>?, dbDirectory: String? ->
logV("createFromKeyBundle")
requireNotProductionEnvForAlphaMLS(enableAlphaMls, environment)

try {
val context = if (enableAlphaMls == true) context else null
val context = if (enableV3 == true) context else null
val encryptionKeyBytes =
dbEncryptionKey?.foldIndexed(ByteArray(dbEncryptionKey.size)) { i, a, v ->
a.apply { set(i, v.toByte()) }
}
val options = ClientOptions(
api = apiEnvironments(environment, appVersion),
enableAlphaMls = enableAlphaMls == true,
enableV3 = enableV3 == true,
appContext = context,
dbEncryptionKey = encryptionKeyBytes,
dbDirectory = dbDirectory
Expand Down Expand Up @@ -1590,12 +1587,6 @@ class XMTPModule : Module() {
preCreateIdentityCallbackDeferred?.await()
preCreateIdentityCallbackDeferred = null
}

private fun requireNotProductionEnvForAlphaMLS(enableAlphaMls: Boolean?, environment: String) {
if (enableAlphaMls == true && (environment == "production")) {
throw XMTPException("Environment must be \"local\" or \"dev\" to enable alpha MLS")
}
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,25 @@ class ContentJson(
)

ContentTypeGroupUpdated.id -> mapOf(
"initiatedByInboxId" to (content as GroupUpdated).initiatedByInboxId,
"groupUpdated" to mapOf(
"membersAdded" to (content as GroupUpdated).addedInboxesList.map {
"membersAdded" to content.addedInboxesList.map {
mapOf(
"inboxId" to it.inboxId,
"initiatedByInboxId" to content.initiatedByInboxId
)},
"inboxId" to it.inboxId
)
},
"membersRemoved" to content.removedInboxesList.map {
mapOf(
"inboxId" to it.inboxId,
"initiatedByInboxId" to content.initiatedByInboxId
)},
"inboxId" to it.inboxId
)
},
"metadataFieldsChanged" to content.metadataFieldChangesList.map {
mapOf(
"oldValue" to it.oldValue,
"newValue" to it.newValue,
"fieldName" to it.fieldName,
)
},
)
)

Expand Down
8 changes: 4 additions & 4 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ PODS:
- GenericJSON (~> 2.0)
- Logging (~> 1.0.0)
- secp256k1.swift (~> 0.1)
- XMTP (0.11.7):
- XMTP (0.12.0):
- Connect-Swift (= 0.12.0)
- GzipSwift
- LibXMTP (= 0.5.1-beta2)
Expand All @@ -458,7 +458,7 @@ PODS:
- ExpoModulesCore
- MessagePacker
- secp256k1.swift
- XMTP (= 0.11.7)
- XMTP (= 0.12.0)
- Yoga (1.14.0)

DEPENDENCIES:
Expand Down Expand Up @@ -763,8 +763,8 @@ SPEC CHECKSUMS:
secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634
SwiftProtobuf: 407a385e97fd206c4fbe880cc84123989167e0d1
web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959
XMTP: b8ab59997ee95106778f445992fa00adce6c2d71
XMTPReactNative: fc0eae046a9a3e3031c6d3b9921e15a6d5b13e09
XMTP: 3d34d8922840d75b8d281ed989843ee813000582
XMTPReactNative: 4d103fca76e388aebf1cb829e37f4a8e36193e58
Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9

PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2
Expand Down
10 changes: 4 additions & 6 deletions example/src/GroupScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1082,16 +1082,14 @@ function GroupUpdatedContents({ content }: { content: GroupUpdatedContent }) {
<Text style={{ opacity: 0.5, fontStyle: 'italic' }}>
{`${formatAddress(
content.membersAdded[0].inboxId
)} has been added by ${formatAddress(
content.membersAdded[0].initiatedByInboxId
)}`}
)} has been added by ${formatAddress(content.initiatedByInboxId)}`}
</Text>
) : (
<Text style={{ opacity: 0.5, fontStyle: 'italic' }}>
{`${
content.membersAdded.length
} members have been added by ${formatAddress(
content.membersAdded[0].initiatedByInboxId
content.initiatedByInboxId
)}`}
</Text>
))}
Expand All @@ -1101,15 +1099,15 @@ function GroupUpdatedContents({ content }: { content: GroupUpdatedContent }) {
{`${formatAddress(
content.membersRemoved[0].inboxId
)} has been removed by ${formatAddress(
content.membersRemoved[0].initiatedByInboxId
content.initiatedByInboxId
)}`}
</Text>
) : (
<Text style={{ opacity: 0.5, fontStyle: 'italic', flexWrap: 'wrap' }}>
{`${
content.membersRemoved.length
} members have been removed by ${formatAddress(
content.membersRemoved[0].initiatedByInboxId
content.initiatedByInboxId
)}`}
</Text>
))}
Expand Down
12 changes: 6 additions & 6 deletions example/src/LaunchScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export default function LaunchScreen(
console.log(
'Using network ' +
selectedNetwork +
' and enableAlphaMLS ' +
' and enableV3 ' +
enableGroups
)

Expand All @@ -224,7 +224,7 @@ export default function LaunchScreen(
appVersion,
preCreateIdentityCallback,
preEnableIdentityCallback,
enableAlphaMls: enableGroups === 'true',
enableV3: enableGroups === 'true',
dbEncryptionKey,
})
)
Expand All @@ -243,7 +243,7 @@ export default function LaunchScreen(
console.log(
'Using network ' +
selectedNetwork +
' and enableAlphaMLS ' +
' and enableV3 ' +
enableGroups
)
const dbEncryptionKey = await getDbEncryptionKey(
Expand All @@ -258,7 +258,7 @@ export default function LaunchScreen(
codecs: supportedCodecs,
preCreateIdentityCallback,
preEnableIdentityCallback,
enableAlphaMls: enableGroups === 'true',
enableV3: enableGroups === 'true',
dbEncryptionKey,
})
)
Expand All @@ -277,7 +277,7 @@ export default function LaunchScreen(
console.log(
'Using network ' +
selectedNetwork +
' and enableAlphaMLS ' +
' and enableV3 ' +
enableGroups
)
const dbEncryptionKey =
Expand All @@ -288,7 +288,7 @@ export default function LaunchScreen(
env: selectedNetwork,
appVersion,
codecs: supportedCodecs,
enableAlphaMls: enableGroups === 'true',
enableV3: enableGroups === 'true',
dbEncryptionKey,
})
)
Expand Down
Loading

0 comments on commit 0004729

Please sign in to comment.