diff --git a/android/build.gradle b/android/build.gradle index 815f26921..d864f9119 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -95,7 +95,7 @@ repositories { dependencies { implementation project(':expo-modules-core') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}" - implementation "org.xmtp:android:0.5.6" + implementation "org.xmtp:android:0.6.0" 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" diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index f8b946a20..148f29a8f 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -262,6 +262,7 @@ class XMTPModule : Module() { DecryptedLocalAttachment( fileUri = file.toURI().toString(), mimeType = attachment.mimeType, + filename = attachment.filename ).toJson() } diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DecryptedLocalAttachment.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DecryptedLocalAttachment.kt index e2099fe2f..ab6f53979 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DecryptedLocalAttachment.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DecryptedLocalAttachment.kt @@ -10,11 +10,13 @@ import com.google.gson.JsonParser class DecryptedLocalAttachment( val fileUri: String, val mimeType: String, + val filename: String, ) { companion object { fun fromJsonObject(obj: JsonObject) = DecryptedLocalAttachment( obj.get("fileUri").asString, obj.get("mimeType").asString, + obj.get("filename")?.asString ?: "", ) fun fromJson(json: String): DecryptedLocalAttachment { @@ -26,6 +28,7 @@ class DecryptedLocalAttachment( fun toJsonMap(): Map = mapOf( "fileUri" to fileUri, "mimeType" to mimeType, + "filename" to filename, ) fun toJson(): String = GsonBuilder().create().toJson(toJsonMap()) diff --git a/example/src/tests.ts b/example/src/tests.ts index c76df7011..cd08f43ee 100644 --- a/example/src/tests.ts +++ b/example/src/tests.ts @@ -438,6 +438,9 @@ test("remote attachments should work", async () => { if (attached.mimeType !== "text/plain") { throw new Error("Expected mimeType to match"); } + if (attached.filename !== filename) { + throw new Error(`Expected ${attached.filename} to equal ${filename}`); + } const text = await fs.readFile(new URL(attached.fileUri).pathname, "utf8"); if (text !== "hello world") { throw new Error("Expected text to match"); diff --git a/ios/Wrappers/DecodedMessageWrapper.swift b/ios/Wrappers/DecodedMessageWrapper.swift index 4c8edf96e..4310711a2 100644 --- a/ios/Wrappers/DecodedMessageWrapper.swift +++ b/ios/Wrappers/DecodedMessageWrapper.swift @@ -251,20 +251,23 @@ struct EncryptedLocalAttachment { struct DecryptedLocalAttachment { var fileUri: String var mimeType: String + var filename: String static func fromJson(_ json: String) throws -> DecryptedLocalAttachment { let data = json.data(using: .utf8)! let obj = (try? JSONSerialization.jsonObject(with: data) as? [String: Any]) ?? [:] return DecryptedLocalAttachment( fileUri: obj["fileUri"] as? String ?? "", - mimeType: obj["mimeType"] as? String ?? "" + mimeType: obj["mimeType"] as? String ?? "", + filename: obj["filename"] as? String ?? "" ) } func toJson() throws -> String { let obj: [String: Any] = [ "fileUri": fileUri, - "mimeType": mimeType + "mimeType": mimeType, + "filename": filename ] return try obj.toJson() } diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index 50f65d8b4..0dac703f7 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -223,7 +223,8 @@ public class XMTPModule: Module { try attachment.data.write(to: file) return try DecryptedLocalAttachment( fileUri: file.absoluteString, - mimeType: attachment.mimeType + mimeType: attachment.mimeType, + filename: attachment.filename ).toJson() } diff --git a/src/XMTP.types.ts b/src/XMTP.types.ts index c92ee67a1..fb85fa2e9 100644 --- a/src/XMTP.types.ts +++ b/src/XMTP.types.ts @@ -23,6 +23,7 @@ export type StaticAttachmentContent = { export type DecryptedLocalAttachment = { fileUri: string; mimeType?: string; + filename?: string; }; export type RemoteAttachmentMetadata = {