Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ repositories {
dependencies {
implementation project(':expo-modules-core')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
implementation "org.xmtp:android:4.9.0"
implementation "org.xmtp:android:4.10.0-rc2"
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import expo.modules.kotlin.functions.Coroutine
import expo.modules.kotlin.modules.Module
import expo.modules.kotlin.modules.ModuleDefinition
import expo.modules.xmtpreactnativesdk.wrappers.ArchiveMetadataWrapper
import expo.modules.xmtpreactnativesdk.wrappers.AvailableArchiveWrapper
import expo.modules.xmtpreactnativesdk.wrappers.AuthParamsWrapper
import expo.modules.xmtpreactnativesdk.wrappers.ClientWrapper
import expo.modules.xmtpreactnativesdk.wrappers.ConsentWrapper
Expand Down Expand Up @@ -226,12 +227,6 @@ class XMTPModule : Module() {
dbEncryptionKey.foldIndexed(ByteArray(dbEncryptionKey.size)) { i, a, v ->
a.apply { set(i, v.toByte()) }
}
val historySyncUrl = authOptions.historySyncUrl
?: when (authOptions.environment) {
"production" -> "https://message-history.production.ephemera.network/"
"local" -> "http://10.0.2.2:5558"
else -> "https://message-history.dev.ephemera.network/"
}
return ClientOptions(
api = apiEnvironments(
authOptions.environment,
Expand All @@ -243,7 +238,6 @@ class XMTPModule : Module() {
appContext = context,
dbEncryptionKey = encryptionKeyBytes,
dbDirectory = authOptions.dbDirectory,
historySyncUrl = historySyncUrl,
deviceSyncEnabled = authOptions.deviceSyncEnabled,
forkRecoveryOptions = authOptions.forkRecoveryOptions
)
Expand Down Expand Up @@ -2177,6 +2171,39 @@ class XMTPModule : Module() {
ArchiveMetadataWrapper.encode(metadata)
}
}

AsyncFunction("sendSyncArchive") Coroutine { installationId: String, pin: String, serverUrl: String?, startNs: Long?, endNs: Long?, archiveElements: List<String>?, excludeDisappearingMessages: Boolean? ->
withContext(Dispatchers.IO) {
val client = clients[installationId] ?: throw XMTPException("No client")
val elements = archiveElements?.map { getArchiveElement(it) } ?: listOf(ArchiveElement.MESSAGES, ArchiveElement.CONSENT)
val opts = ArchiveOptions(startNs, endNs, elements, excludeDisappearingMessages ?: false)
val url = serverUrl?.takeIf { it.isNotBlank() } ?: client.environment.getHistorySyncUrl()
client.sendSyncArchive(opts, url, pin)
}
}

AsyncFunction("processSyncArchive") Coroutine { installationId: String, archivePin: String? ->
withContext(Dispatchers.IO) {
val client = clients[installationId] ?: throw XMTPException("No client")
client.processSyncArchive(archivePin)
}
}

AsyncFunction("listAvailableArchives") Coroutine { installationId: String, daysCutoff: Long ->
withContext(Dispatchers.IO) {
val client = clients[installationId] ?: throw XMTPException("No client")
val archives = client.listAvailableArchives(daysCutoff)
AvailableArchiveWrapper.encodeList(archives)
}
}

AsyncFunction("syncAllDeviceSyncGroups") Coroutine { installationId: String ->
withContext(Dispatchers.IO) {
val client = clients[installationId] ?: throw XMTPException("No client")
val summary = client.syncAllDeviceSyncGroups()
GroupSyncSummaryWrapper.encode(summary)
}
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class ArchiveMetadataWrapper {
}
}

fun encode(metadata: ArchiveMetadata?): String {
val obj = if (metadata != null) {
/** Returns metadata as a map for embedding in another JSON object (avoids double JSON encoding). */
fun encodeToMap(metadata: ArchiveMetadata?): Map<String, Any?> {
return if (metadata != null) {
encodeToObj(metadata)
} else {
// Create a default metadata object when null
mapOf(
"archiveVersion" to 0u,
"elements" to listOf("messages", "consent"),
Expand All @@ -45,7 +45,10 @@ class ArchiveMetadataWrapper {
"endNs" to null
)
}
return gson.toJson(obj)
}

fun encode(metadata: ArchiveMetadata?): String {
return gson.toJson(encodeToMap(metadata))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import java.math.BigInteger
class AuthParamsWrapper(
val environment: String,
val dbDirectory: String?,
val historySyncUrl: String?,
val customLocalUrl: String?,
val deviceSyncEnabled: Boolean,
val debugEventsEnabled: Boolean,
Expand Down Expand Up @@ -83,7 +82,6 @@ class AuthParamsWrapper(
return AuthParamsWrapper(
jsonOptions.get("environment").asString,
if (jsonOptions.has("dbDirectory")) jsonOptions.get("dbDirectory").asString else null,
if (jsonOptions.has("historySyncUrl")) jsonOptions.get("historySyncUrl").asString else null,
if (jsonOptions.has("customLocalUrl")) jsonOptions.get("customLocalUrl").asString else null,
if (jsonOptions.has("deviceSyncEnabled")) jsonOptions.get("deviceSyncEnabled").asBoolean else true,
if (jsonOptions.has("debugEventsEnabled")) jsonOptions.get("debugEventsEnabled").asBoolean else false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package expo.modules.xmtpreactnativesdk.wrappers

import android.util.Base64
import com.google.gson.GsonBuilder
import org.xmtp.android.library.libxmtp.AvailableArchive

class AvailableArchiveWrapper {
companion object {
private val gson = GsonBuilder().create()

fun encodeToObj(archive: AvailableArchive): Map<String, Any?> = mapOf(
"pin" to archive.pin,
"metadata" to ArchiveMetadataWrapper.encodeToMap(archive.metadata),
"sentByInstallation" to Base64.encodeToString(archive.sentByInstallation, Base64.NO_WRAP),
)

fun encodeList(archives: List<AvailableArchive>): String {
val list = archives.map { encodeToObj(it) }
return gson.toJson(list)
}
}
}
12 changes: 6 additions & 6 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PODS:
- boost (1.84.0)
- Connect-Swift (1.2.0):
- Connect-Swift (1.2.1):
- SwiftProtobuf (~> 1.30.0)
- CryptoSwift (1.8.3)
- CSecp256k1 (0.2.0)
Expand Down Expand Up @@ -1757,7 +1757,7 @@ PODS:
- SQLCipher/standard (4.5.7):
- SQLCipher/common
- SwiftProtobuf (1.30.0)
- XMTP (4.9.0):
- XMTP (4.10.0-rc2):
- Connect-Swift (~> 1.2.0)
- CryptoSwift (= 1.8.3)
- SQLCipher (= 4.5.7)
Expand All @@ -1766,7 +1766,7 @@ PODS:
- ExpoModulesCore
- MessagePacker
- SQLCipher (= 4.5.7)
- XMTP (= 4.9.0)
- XMTP (= 4.10.0-rc2)
- Yoga (0.0.0)

DEPENDENCIES:
Expand Down Expand Up @@ -2077,7 +2077,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
boost: 1dca942403ed9342f98334bf4c3621f011aa7946
Connect-Swift: 82bcc0834587bd537f17a9720f62ea9fc7d9f3a5
Connect-Swift: 8550afdb45aaea9f527d29c74f7224bf78e2bc26
CryptoSwift: 967f37cea5a3294d9cce358f78861652155be483
CSecp256k1: 2a59c03e52637ded98896a33be4b2649392cb843
DoubleConversion: f16ae600a246532c4020132d54af21d0ddb2a385
Expand Down Expand Up @@ -2179,8 +2179,8 @@ SPEC CHECKSUMS:
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
SQLCipher: 5e6bfb47323635c8b657b1b27d25c5f1baf63bf5
SwiftProtobuf: 3697407f0d5b23bedeba9c2eaaf3ec6fdff69349
XMTP: 322f5be971dca2b1f402727ffda2f62d4ab7f71d
XMTPReactNative: 44d7e20a4affcf6e3c7c62c2331c2dcb9696c934
XMTP: 40a323abd37322a4d0c323a1fd97e9a67ce9c16f
XMTPReactNative: f62ff8302fb02c611cae0be0981021d6f3426036
Yoga: 40f19fff64dce86773bf8b602c7070796c007970

PODFILE CHECKSUM: c76510e65e7d9673f44024ae2d0a10eec063a555
Expand Down
Loading
Loading