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' 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/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 7a3b0b58a..dada7fe1b 100644 --- a/example/src/tests/groupTests.ts +++ b/example/src/tests/groupTests.ts @@ -27,6 +27,41 @@ test('can make a MLS V3 client', async () => { return true }) +test('can delete a local database', async () => { + let 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]) + 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() + client = await Client.createRandom({ + env: 'local', + appVersion: 'Testing/0.0.0', + enableAlphaMls: true, + }) + 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}` + ) + + 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` diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index f2dc78c38..68dc71c63 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 + } + try client.deleteLocalDatabase() + } + // // Auth functions // 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 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. *