From 69c3fbc86533dce84a7bdec2d61bdef0012a62e8 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Sun, 25 Feb 2024 07:56:02 -0800 Subject: [PATCH 1/7] bump to the latest gradle --- android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/build.gradle b/android/build.gradle index d029f957b..61d0f8f1b 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -101,7 +101,7 @@ dependencies { 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" - implementation "org.xmtp:android:0.7.17" + implementation "org.xmtp:android:0.8.0" // xmtp-android local testing setup below (comment org.xmtp:android above) // implementation files('/xmtp-android/library/build/outputs/aar/library-debug.aar') // implementation 'com.google.crypto.tink:tink-android:1.7.0' From 1710bb3ca7a3ae97f05497455fd133cd5ddceb87 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Sun, 25 Feb 2024 20:38:58 -0800 Subject: [PATCH 2/7] add the native side of the database deletion --- .../modules/xmtpreactnativesdk/XMTPModule.kt | 22 ++++++++++++------- ios/XMTPModule.swift | 7 ++++++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index f65d89480..fdad38cf0 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -167,6 +167,11 @@ class XMTPModule : Module() { client?.address ?: "No Client." } + AsyncFunction("deleteLocalDatabase") { clientAddress: String -> + val client = clients[clientAddress] ?: throw XMTPException("No client") + client.deleteLocalDatabase() + } + // // Auth functions // @@ -1014,15 +1019,16 @@ class XMTPModule : Module() { subscriptions[getMessagesKey(clientAddress)]?.cancel() subscriptions[getMessagesKey(clientAddress)] = CoroutineScope(Dispatchers.IO).launch { try { - client.conversations.streamAllDecryptedMessages(includeGroups = includeGroups).collect { message -> - sendEvent( - "message", - mapOf( - "clientAddress" to clientAddress, - "message" to DecodedMessageWrapper.encodeMap(message), + client.conversations.streamAllDecryptedMessages(includeGroups = includeGroups) + .collect { message -> + sendEvent( + "message", + mapOf( + "clientAddress" to clientAddress, + "message" to DecodedMessageWrapper.encodeMap(message), + ) ) - ) - } + } } catch (e: Exception) { Log.e("XMTPModule", "Error in all messages subscription: $e") subscriptions[getMessagesKey(clientAddress)]?.cancel() diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index f2dc78c38..ab8391cae 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -75,6 +75,13 @@ public class XMTPModule: Module { } } + AsyncFunction("deleteLocalDatabase") { (clientAddress: String) in + guard let client = await clientsManager.getClient(key: clientAddress) else { + throw Error.noClient + } + client.deleteLocalDatabase() + } + // // Auth functions // From e397054eb9ae772267aaf8b1a2ae7695623fb166 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Sun, 25 Feb 2024 20:44:09 -0800 Subject: [PATCH 3/7] Update the react native to add the function --- src/index.ts | 4 ++++ src/lib/Client.ts | 17 +++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index 2a682b8c7..0fe0f2f6b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -39,6 +39,10 @@ export function address(): string { return XMTPModule.address() } +export async function deleteLocalDatabase(address: string) { + return XMTPModule.deleteLocalDatabase(address) +} + export async function auth( address: string, environment: 'local' | 'dev' | 'production', diff --git a/src/lib/Client.ts b/src/lib/Client.ts index 048a58fd2..9796eba78 100644 --- a/src/lib/Client.ts +++ b/src/lib/Client.ts @@ -19,13 +19,11 @@ import { DecodedMessage } from '../index' declare const Buffer -export type GetMessageContentTypeFromClient = C extends Client - ? T - : never +export type GetMessageContentTypeFromClient = + C extends Client ? T : never -export type ExtractDecodedType = C extends XMTPModule.ContentCodec - ? T - : never +export type ExtractDecodedType = + C extends XMTPModule.ContentCodec ? T : never export class Client< ContentTypes extends DefaultContentTypes = DefaultContentTypes, @@ -197,6 +195,13 @@ export class Client< return await XMTPModule.canMessage(this.address, peerAddress) } + /** + * Deletes the local database. This cannot be undone and these stored messages will not be refetched from the network. + */ + async deleteLocalDatabase() { + return await XMTPModule.deleteLocalDatabase(this.address) + } + /** * Determines whether the current user can send messages to the specified peers over groups. * From 721b95799d903d00621f05273f8031966af938e3 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Sun, 25 Feb 2024 20:47:44 -0800 Subject: [PATCH 4/7] write a test for it --- example/src/tests/groupTests.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/example/src/tests/groupTests.ts b/example/src/tests/groupTests.ts index 7a3b0b58a..05cd03d19 100644 --- a/example/src/tests/groupTests.ts +++ b/example/src/tests/groupTests.ts @@ -27,6 +27,37 @@ test('can make a MLS V3 client', async () => { return true }) +test('can delete a local database', async () => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const client = await Client.createRandom({ + env: 'local', + appVersion: 'Testing/0.0.0', + enableAlphaMls: true, + }) + + const anotherClient = await Client.createRandom({ + env: 'local', + appVersion: 'Testing/0.0.0', + enableAlphaMls: true, + }) + + await client.conversations.newGroup([anotherClient.address]) + assert( + (await client.conversations.listGroups()).length === 1, + `should have a group size of 1 but was ${(await client.conversations.listGroups()).length}` + ) + + await client.deleteLocalDatabase() + + await client.conversations.newGroup([anotherClient.address]) + assert( + (await client.conversations.listGroups()).length === 0, + `should have a group size of 0 but was ${(await client.conversations.listGroups()).length}` + ) + + return true +}) + test('can make a MLS V3 client with encryption key and database path', async () => { // eslint-disable-next-line @typescript-eslint/no-unused-vars const dbDirPath = `${RNFS.DocumentDirectoryPath}/xmtp_db` From 0215e4b275fde6cc98e030b1cf37b23e98770199 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Sun, 25 Feb 2024 20:52:58 -0800 Subject: [PATCH 5/7] fix up the test --- example/src/tests/groupTests.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/src/tests/groupTests.ts b/example/src/tests/groupTests.ts index 05cd03d19..02105f11f 100644 --- a/example/src/tests/groupTests.ts +++ b/example/src/tests/groupTests.ts @@ -42,14 +42,14 @@ test('can delete a local database', async () => { }) await client.conversations.newGroup([anotherClient.address]) + await client.conversations.syncGroups() assert( (await client.conversations.listGroups()).length === 1, `should have a group size of 1 but was ${(await client.conversations.listGroups()).length}` ) await client.deleteLocalDatabase() - - await client.conversations.newGroup([anotherClient.address]) + await client.conversations.syncGroups() assert( (await client.conversations.listGroups()).length === 0, `should have a group size of 0 but was ${(await client.conversations.listGroups()).length}` From ef86836631b07c5763ad7828351c5cb2fb1538d4 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 29 Feb 2024 10:52:17 -0700 Subject: [PATCH 6/7] bump the pod and fix up the test --- example/ios/Podfile.lock | 8 ++++---- example/src/tests/groupTests.ts | 8 ++++++-- ios/XMTPModule.swift | 2 +- ios/XMTPReactNative.podspec | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 4b388425e..a7d3dbfbe 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -446,7 +446,7 @@ PODS: - GenericJSON (~> 2.0) - Logging (~> 1.0.0) - secp256k1.swift (~> 0.1) - - XMTP (0.8.13): + - XMTP (0.8.14): - Connect-Swift (= 0.3.0) - GzipSwift - LibXMTP (= 0.4.2-beta3) @@ -455,7 +455,7 @@ PODS: - ExpoModulesCore - MessagePacker - secp256k1.swift - - XMTP (= 0.8.13) + - XMTP (= 0.8.14) - Yoga (1.14.0) DEPENDENCIES: @@ -756,8 +756,8 @@ SPEC CHECKSUMS: secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634 SwiftProtobuf: b02b5075dcf60c9f5f403000b3b0c202a11b6ae1 web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959 - XMTP: 0424f5521008373eaa0a8cdba9d4244ba13700f2 - XMTPReactNative: cba9ca301d6ae82f649702e5befb3551f98d679f + XMTP: f716708390140ef0542425898888e2346e04174e + XMTPReactNative: 145687cf515815fcc26f89e4347c44814708981b Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9 PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2 diff --git a/example/src/tests/groupTests.ts b/example/src/tests/groupTests.ts index 02105f11f..dada7fe1b 100644 --- a/example/src/tests/groupTests.ts +++ b/example/src/tests/groupTests.ts @@ -28,8 +28,7 @@ test('can make a MLS V3 client', async () => { }) test('can delete a local database', async () => { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const client = await Client.createRandom({ + let client = await Client.createRandom({ env: 'local', appVersion: 'Testing/0.0.0', enableAlphaMls: true, @@ -49,6 +48,11 @@ test('can delete a local database', async () => { ) await client.deleteLocalDatabase() + client = await Client.createRandom({ + env: 'local', + appVersion: 'Testing/0.0.0', + enableAlphaMls: true, + }) await client.conversations.syncGroups() assert( (await client.conversations.listGroups()).length === 0, diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index ab8391cae..68dc71c63 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -79,7 +79,7 @@ public class XMTPModule: Module { guard let client = await clientsManager.getClient(key: clientAddress) else { throw Error.noClient } - client.deleteLocalDatabase() + try client.deleteLocalDatabase() } // diff --git a/ios/XMTPReactNative.podspec b/ios/XMTPReactNative.podspec index f666457ac..9bfc7c288 100644 --- a/ios/XMTPReactNative.podspec +++ b/ios/XMTPReactNative.podspec @@ -26,5 +26,5 @@ Pod::Spec.new do |s| s.source_files = "**/*.{h,m,swift}" s.dependency 'secp256k1.swift' s.dependency "MessagePacker" - s.dependency "XMTP", "= 0.8.13" + s.dependency "XMTP", "= 0.8.14" end From 678da640a4f62540a97ad7028404370d61a797fc Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 29 Feb 2024 10:56:48 -0700 Subject: [PATCH 7/7] feat: allow deleting local databse