Skip to content

Commit f0a3d5e

Browse files
authored
5.7.0 Release - add new device sync functions and tests for libxmtp release 1.10.0 (#773)
* add new device sync functions and tests for libxmtp release 1.10.0 * address feedback * bump package.json for release --------- Co-authored-by: cameronvoell <cameronvoell@users.noreply.github.com>
1 parent 635a705 commit f0a3d5e

15 files changed

Lines changed: 481 additions & 85 deletions

File tree

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ repositories {
9595
dependencies {
9696
implementation project(':expo-modules-core')
9797
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
98-
implementation "org.xmtp:android:4.9.0"
98+
implementation "org.xmtp:android:4.10.0-rc2"
9999
implementation 'com.google.code.gson:gson:2.10.1'
100100
implementation 'com.facebook.react:react-native:0.71.3'
101101
implementation "com.daveanthonythomas.moshipack:moshipack:1.0.1"

android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import expo.modules.kotlin.functions.Coroutine
1313
import expo.modules.kotlin.modules.Module
1414
import expo.modules.kotlin.modules.ModuleDefinition
1515
import expo.modules.xmtpreactnativesdk.wrappers.ArchiveMetadataWrapper
16+
import expo.modules.xmtpreactnativesdk.wrappers.AvailableArchiveWrapper
1617
import expo.modules.xmtpreactnativesdk.wrappers.AuthParamsWrapper
1718
import expo.modules.xmtpreactnativesdk.wrappers.ClientWrapper
1819
import expo.modules.xmtpreactnativesdk.wrappers.ConsentWrapper
@@ -226,12 +227,6 @@ class XMTPModule : Module() {
226227
dbEncryptionKey.foldIndexed(ByteArray(dbEncryptionKey.size)) { i, a, v ->
227228
a.apply { set(i, v.toByte()) }
228229
}
229-
val historySyncUrl = authOptions.historySyncUrl
230-
?: when (authOptions.environment) {
231-
"production" -> "https://message-history.production.ephemera.network/"
232-
"local" -> "http://10.0.2.2:5558"
233-
else -> "https://message-history.dev.ephemera.network/"
234-
}
235230
return ClientOptions(
236231
api = apiEnvironments(
237232
authOptions.environment,
@@ -243,7 +238,6 @@ class XMTPModule : Module() {
243238
appContext = context,
244239
dbEncryptionKey = encryptionKeyBytes,
245240
dbDirectory = authOptions.dbDirectory,
246-
historySyncUrl = historySyncUrl,
247241
deviceSyncEnabled = authOptions.deviceSyncEnabled,
248242
forkRecoveryOptions = authOptions.forkRecoveryOptions
249243
)
@@ -2177,6 +2171,39 @@ class XMTPModule : Module() {
21772171
ArchiveMetadataWrapper.encode(metadata)
21782172
}
21792173
}
2174+
2175+
AsyncFunction("sendSyncArchive") Coroutine { installationId: String, pin: String, serverUrl: String?, startNs: Long?, endNs: Long?, archiveElements: List<String>?, excludeDisappearingMessages: Boolean? ->
2176+
withContext(Dispatchers.IO) {
2177+
val client = clients[installationId] ?: throw XMTPException("No client")
2178+
val elements = archiveElements?.map { getArchiveElement(it) } ?: listOf(ArchiveElement.MESSAGES, ArchiveElement.CONSENT)
2179+
val opts = ArchiveOptions(startNs, endNs, elements, excludeDisappearingMessages ?: false)
2180+
val url = serverUrl?.takeIf { it.isNotBlank() } ?: client.environment.getHistorySyncUrl()
2181+
client.sendSyncArchive(opts, url, pin)
2182+
}
2183+
}
2184+
2185+
AsyncFunction("processSyncArchive") Coroutine { installationId: String, archivePin: String? ->
2186+
withContext(Dispatchers.IO) {
2187+
val client = clients[installationId] ?: throw XMTPException("No client")
2188+
client.processSyncArchive(archivePin)
2189+
}
2190+
}
2191+
2192+
AsyncFunction("listAvailableArchives") Coroutine { installationId: String, daysCutoff: Long ->
2193+
withContext(Dispatchers.IO) {
2194+
val client = clients[installationId] ?: throw XMTPException("No client")
2195+
val archives = client.listAvailableArchives(daysCutoff)
2196+
AvailableArchiveWrapper.encodeList(archives)
2197+
}
2198+
}
2199+
2200+
AsyncFunction("syncAllDeviceSyncGroups") Coroutine { installationId: String ->
2201+
withContext(Dispatchers.IO) {
2202+
val client = clients[installationId] ?: throw XMTPException("No client")
2203+
val summary = client.syncAllDeviceSyncGroups()
2204+
GroupSyncSummaryWrapper.encode(summary)
2205+
}
2206+
}
21802207
}
21812208

21822209

android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/ArchiveMetadataWrapper.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ class ArchiveMetadataWrapper {
3232
}
3333
}
3434

35-
fun encode(metadata: ArchiveMetadata?): String {
36-
val obj = if (metadata != null) {
35+
/** Returns metadata as a map for embedding in another JSON object (avoids double JSON encoding). */
36+
fun encodeToMap(metadata: ArchiveMetadata?): Map<String, Any?> {
37+
return if (metadata != null) {
3738
encodeToObj(metadata)
3839
} else {
39-
// Create a default metadata object when null
4040
mapOf(
4141
"archiveVersion" to 0u,
4242
"elements" to listOf("messages", "consent"),
@@ -45,7 +45,10 @@ class ArchiveMetadataWrapper {
4545
"endNs" to null
4646
)
4747
}
48-
return gson.toJson(obj)
48+
}
49+
50+
fun encode(metadata: ArchiveMetadata?): String {
51+
return gson.toJson(encodeToMap(metadata))
4952
}
5053
}
5154
}

android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/AuthParamsWrapper.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import java.math.BigInteger
1010
class AuthParamsWrapper(
1111
val environment: String,
1212
val dbDirectory: String?,
13-
val historySyncUrl: String?,
1413
val customLocalUrl: String?,
1514
val deviceSyncEnabled: Boolean,
1615
val debugEventsEnabled: Boolean,
@@ -83,7 +82,6 @@ class AuthParamsWrapper(
8382
return AuthParamsWrapper(
8483
jsonOptions.get("environment").asString,
8584
if (jsonOptions.has("dbDirectory")) jsonOptions.get("dbDirectory").asString else null,
86-
if (jsonOptions.has("historySyncUrl")) jsonOptions.get("historySyncUrl").asString else null,
8785
if (jsonOptions.has("customLocalUrl")) jsonOptions.get("customLocalUrl").asString else null,
8886
if (jsonOptions.has("deviceSyncEnabled")) jsonOptions.get("deviceSyncEnabled").asBoolean else true,
8987
if (jsonOptions.has("debugEventsEnabled")) jsonOptions.get("debugEventsEnabled").asBoolean else false,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package expo.modules.xmtpreactnativesdk.wrappers
2+
3+
import android.util.Base64
4+
import com.google.gson.GsonBuilder
5+
import org.xmtp.android.library.libxmtp.AvailableArchive
6+
7+
class AvailableArchiveWrapper {
8+
companion object {
9+
private val gson = GsonBuilder().create()
10+
11+
fun encodeToObj(archive: AvailableArchive): Map<String, Any?> = mapOf(
12+
"pin" to archive.pin,
13+
"metadata" to ArchiveMetadataWrapper.encodeToMap(archive.metadata),
14+
"sentByInstallation" to Base64.encodeToString(archive.sentByInstallation, Base64.NO_WRAP),
15+
)
16+
17+
fun encodeList(archives: List<AvailableArchive>): String {
18+
val list = archives.map { encodeToObj(it) }
19+
return gson.toJson(list)
20+
}
21+
}
22+
}

example/ios/Podfile.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PODS:
22
- boost (1.84.0)
3-
- Connect-Swift (1.2.0):
3+
- Connect-Swift (1.2.1):
44
- SwiftProtobuf (~> 1.30.0)
55
- CryptoSwift (1.8.3)
66
- CSecp256k1 (0.2.0)
@@ -1757,7 +1757,7 @@ PODS:
17571757
- SQLCipher/standard (4.5.7):
17581758
- SQLCipher/common
17591759
- SwiftProtobuf (1.30.0)
1760-
- XMTP (4.9.0):
1760+
- XMTP (4.10.0-rc2):
17611761
- Connect-Swift (~> 1.2.0)
17621762
- CryptoSwift (= 1.8.3)
17631763
- SQLCipher (= 4.5.7)
@@ -1766,7 +1766,7 @@ PODS:
17661766
- ExpoModulesCore
17671767
- MessagePacker
17681768
- SQLCipher (= 4.5.7)
1769-
- XMTP (= 4.9.0)
1769+
- XMTP (= 4.10.0-rc2)
17701770
- Yoga (0.0.0)
17711771

17721772
DEPENDENCIES:
@@ -2077,7 +2077,7 @@ EXTERNAL SOURCES:
20772077

20782078
SPEC CHECKSUMS:
20792079
boost: 1dca942403ed9342f98334bf4c3621f011aa7946
2080-
Connect-Swift: 82bcc0834587bd537f17a9720f62ea9fc7d9f3a5
2080+
Connect-Swift: 8550afdb45aaea9f527d29c74f7224bf78e2bc26
20812081
CryptoSwift: 967f37cea5a3294d9cce358f78861652155be483
20822082
CSecp256k1: 2a59c03e52637ded98896a33be4b2649392cb843
20832083
DoubleConversion: f16ae600a246532c4020132d54af21d0ddb2a385
@@ -2179,8 +2179,8 @@ SPEC CHECKSUMS:
21792179
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
21802180
SQLCipher: 5e6bfb47323635c8b657b1b27d25c5f1baf63bf5
21812181
SwiftProtobuf: 3697407f0d5b23bedeba9c2eaaf3ec6fdff69349
2182-
XMTP: 322f5be971dca2b1f402727ffda2f62d4ab7f71d
2183-
XMTPReactNative: 44d7e20a4affcf6e3c7c62c2331c2dcb9696c934
2182+
XMTP: 40a323abd37322a4d0c323a1fd97e9a67ce9c16f
2183+
XMTPReactNative: f62ff8302fb02c611cae0be0981021d6f3426036
21842184
Yoga: 40f19fff64dce86773bf8b602c7070796c007970
21852185

21862186
PODFILE CHECKSUM: c76510e65e7d9673f44024ae2d0a10eec063a555

0 commit comments

Comments
 (0)