Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/xmtp/xmtp-react-native into…
Browse files Browse the repository at this point in the history
… np/pagination-direction
  • Loading branch information
nplasterer committed Sep 14, 2023
2 parents 57516c4 + fbf645c commit 43c5b0a
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 19 deletions.
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:0.6.1"
implementation "org.xmtp:android:0.6.2"
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 @@ -263,6 +263,7 @@ class XMTPModule : Module() {
DecryptedLocalAttachment(
fileUri = file.toURI().toString(),
mimeType = attachment.mimeType,
filename = attachment.filename
).toJson()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import org.xmtp.android.library.codecs.Reply
import org.xmtp.android.library.codecs.ReplyCodec
import org.xmtp.android.library.codecs.TextCodec
import org.xmtp.android.library.codecs.description
import org.xmtp.android.library.codecs.getReactionAction
import org.xmtp.android.library.codecs.getReactionSchema
import org.xmtp.android.library.codecs.id

import java.lang.Exception
Expand Down Expand Up @@ -80,8 +82,8 @@ class ContentJson(
val reaction = obj.get("reaction").asJsonObject
return ContentJson(ContentTypeReaction, Reaction(
reference = reaction.get("reference").asString,
action = ReactionAction.valueOf(reaction.get("action").asString),
schema = ReactionSchema.valueOf(reaction.get("schema").asString),
action = getReactionAction(reaction.get("action").asString.lowercase()),
schema = getReactionSchema(reaction.get("schema").asString.lowercase()),
content = reaction.get("content").asString,
))
} else if (obj.has("reply")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -26,6 +28,7 @@ class DecryptedLocalAttachment(
fun toJsonMap(): Map<String, Any> = mapOf(
"fileUri" to fileUri,
"mimeType" to mimeType,
"filename" to filename,
)

fun toJson(): String = GsonBuilder().create().toJson(toJsonMap())
Expand Down
20 changes: 10 additions & 10 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
PODS:
- BigInt (5.0.0)
- boost (1.76.0)
- Connect-Swift (0.6.0):
- SwiftProtobuf (~> 1.22.0)
- Connect-Swift (0.7.0):
- SwiftProtobuf (~> 1.23.0)
- DoubleConversion (1.1.6)
- EXApplication (5.1.1):
- ExpoModulesCore
Expand Down Expand Up @@ -409,21 +409,21 @@ PODS:
- RNSVG (13.9.0):
- React-Core
- secp256k1.swift (0.1.4)
- SwiftProtobuf (1.22.1)
- SwiftProtobuf (1.23.0)
- web3.swift (1.6.0):
- BigInt (~> 5.0.0)
- GenericJSON (~> 2.0)
- Logging (~> 1.0.0)
- secp256k1.swift (~> 0.1)
- XMTP (0.5.3-alpha0):
- XMTP (0.5.4-alpha0):
- Connect-Swift
- GzipSwift
- web3.swift
- XMTPRust (= 0.3.1-beta0)
- XMTPReactNative (0.1.0):
- ExpoModulesCore
- MessagePacker
- XMTP (= 0.5.3-alpha0)
- XMTP (= 0.5.4-alpha0)
- XMTPRust (0.3.1-beta0)
- Yoga (1.14.0)

Expand Down Expand Up @@ -617,7 +617,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
BigInt: 74b4d88367b0e819d9f77393549226d36faeb0d8
boost: 57d2868c099736d80fcd648bf211b4431e51a558
Connect-Swift: ba76bc64b2153cacce4f7985a21d4d81473dac90
Connect-Swift: 3b305e8305a8b88a33be087dad207d84aad57dd2
DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54
EXApplication: d8f53a7eee90a870a75656280e8d4b85726ea903
EXConstants: f348da07e21b23d2b085e270d7b74f282df1a7d9
Expand Down Expand Up @@ -678,13 +678,13 @@ SPEC CHECKSUMS:
RNScreens: 218801c16a2782546d30bd2026bb625c0302d70f
RNSVG: 53c661b76829783cdaf9b7a57258f3d3b4c28315
secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634
SwiftProtobuf: 7773c4e96a99d7b8ab7cda0fc30a883732ff93b1
SwiftProtobuf: b70d65f419fbfe61a2d58003456ca5da58e337d6
web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959
XMTP: 01fd25bc966b9546f1a04210d4162764861b076d
XMTPReactNative: 6feac2b747871f469660b43b85576efaa6c558d1
XMTP: 8e220d6c064c293911d88adb08087b90d06c22c5
XMTPReactNative: cfa66e30fa730f3b5f6cb4fed64eb3d11552e4b6
XMTPRust: 78f65f77b1454392980da244961777aee955652f
Yoga: 065f0b74dba4832d6e328238de46eb72c5de9556

PODFILE CHECKSUM: 522d88edc2d5fac4825e60a121c24abc18983367

COCOAPODS: 1.12.1
COCOAPODS: 1.11.3
3 changes: 3 additions & 0 deletions example/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,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");
Expand Down
7 changes: 5 additions & 2 deletions ios/Wrappers/DecodedMessageWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
3 changes: 2 additions & 1 deletion ios/XMTPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
2 changes: 1 addition & 1 deletion ios/XMTPReactNative.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ Pod::Spec.new do |s|

s.source_files = "**/*.{h,m,swift}"
s.dependency "MessagePacker"
s.dependency "XMTP", "= 0.5.3-alpha0"
s.dependency "XMTP", "= 0.5.4-alpha0"
end
5 changes: 3 additions & 2 deletions src/XMTP.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export type ReplyContent = {

export type ReactionContent = {
reference: string;
action: "added" | "removed";
schema: "unicode" | "shortcode" | "custom";
action: "added" | "removed" | "unknown";
schema: "unicode" | "shortcode" | "custom" | "unknown";
content: string;
};

Expand All @@ -23,6 +23,7 @@ export type StaticAttachmentContent = {
export type DecryptedLocalAttachment = {
fileUri: string;
mimeType?: string;
filename?: string;
};

export type RemoteAttachmentMetadata = {
Expand Down

0 comments on commit 43c5b0a

Please sign in to comment.