From 8700d77813a50666c6999ae453c519adb4252d08 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Tue, 26 Sep 2023 16:02:53 -0700 Subject: [PATCH 1/2] fix: decrypt reactions correctly --- .../expo/modules/xmtpreactnativesdk/wrappers/ContentJson.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/ContentJson.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/ContentJson.kt index 28278fea9..13c171047 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/ContentJson.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/ContentJson.kt @@ -1,6 +1,7 @@ package expo.modules.xmtpreactnativesdk.wrappers import android.util.Base64 +import android.util.Log import com.google.gson.JsonObject import com.google.gson.JsonParser import com.google.protobuf.ByteString @@ -146,8 +147,8 @@ class ContentJson( ContentTypeReaction.id -> mapOf( "reaction" to mapOf( "reference" to (content as Reaction).reference, - "action" to content.action, - "schema" to content.schema, + "action" to content.action.javaClass.simpleName.lowercase(), + "schema" to content.schema.javaClass.simpleName.lowercase(), "content" to content.content, ) ) From e61993ab642c4d183abcc385c7ee2d2f9e52cbc1 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Tue, 26 Sep 2023 16:04:43 -0700 Subject: [PATCH 2/2] fix linter issues --- .../wrappers/ContentJson.kt | 55 ++++++++++--------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/ContentJson.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/ContentJson.kt index 13c171047..775891a85 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/ContentJson.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/ContentJson.kt @@ -1,26 +1,21 @@ package expo.modules.xmtpreactnativesdk.wrappers import android.util.Base64 -import android.util.Log import com.google.gson.JsonObject import com.google.gson.JsonParser import com.google.protobuf.ByteString import org.xmtp.android.library.Client -import org.xmtp.proto.message.contents.Content.EncodedContent -import org.xmtp.android.library.codecs.decoded +import org.xmtp.android.library.codecs.Attachment +import org.xmtp.android.library.codecs.AttachmentCodec import org.xmtp.android.library.codecs.ContentTypeAttachment import org.xmtp.android.library.codecs.ContentTypeId import org.xmtp.android.library.codecs.ContentTypeReaction -import org.xmtp.android.library.codecs.ContentTypeText -import org.xmtp.android.library.codecs.AttachmentCodec -import org.xmtp.android.library.codecs.Attachment import org.xmtp.android.library.codecs.ContentTypeReadReceipt import org.xmtp.android.library.codecs.ContentTypeRemoteAttachment import org.xmtp.android.library.codecs.ContentTypeReply -import org.xmtp.android.library.codecs.ReactionAction -import org.xmtp.android.library.codecs.ReactionSchema -import org.xmtp.android.library.codecs.ReactionCodec +import org.xmtp.android.library.codecs.ContentTypeText import org.xmtp.android.library.codecs.Reaction +import org.xmtp.android.library.codecs.ReactionCodec import org.xmtp.android.library.codecs.ReadReceipt import org.xmtp.android.library.codecs.ReadReceiptCodec import org.xmtp.android.library.codecs.RemoteAttachment @@ -28,12 +23,12 @@ import org.xmtp.android.library.codecs.RemoteAttachmentCodec 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.decoded 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 +import org.xmtp.proto.message.contents.Content.EncodedContent import java.net.URL class ContentJson( @@ -62,11 +57,13 @@ class ContentJson( return ContentJson(ContentTypeText, obj.get("text").asString) } else if (obj.has("attachment")) { val attachment = obj.get("attachment").asJsonObject - return ContentJson(ContentTypeAttachment, Attachment( - filename = attachment.get("filename").asString, - mimeType = attachment.get("mimeType").asString, - data = ByteString.copyFrom(bytesFrom64(attachment.get("data").asString)), - )) + return ContentJson( + ContentTypeAttachment, Attachment( + filename = attachment.get("filename").asString, + mimeType = attachment.get("mimeType").asString, + data = ByteString.copyFrom(bytesFrom64(attachment.get("data").asString)), + ) + ) } else if (obj.has("remoteAttachment")) { val remoteAttachment = obj.get("remoteAttachment").asJsonObject val metadata = EncryptedAttachmentMetadata.fromJsonObj(remoteAttachment) @@ -85,12 +82,14 @@ class ContentJson( ) } else if (obj.has("reaction")) { val reaction = obj.get("reaction").asJsonObject - return ContentJson(ContentTypeReaction, Reaction( - reference = reaction.get("reference").asString, - action = getReactionAction(reaction.get("action").asString.lowercase()), - schema = getReactionSchema(reaction.get("schema").asString.lowercase()), - content = reaction.get("content").asString, - )) + return ContentJson( + ContentTypeReaction, Reaction( + reference = reaction.get("reference").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")) { val reply = obj.get("reply").asJsonObject val nested = fromJsonObject(reply.get("content").asJsonObject) @@ -100,11 +99,13 @@ class ContentJson( if (nested.content == null) { throw Exception("Bad reply content") } - return ContentJson(ContentTypeReply, Reply( - reference = reply.get("reference").asString, - content = nested.content, - contentType = nested.type, - )) + return ContentJson( + ContentTypeReply, Reply( + reference = reply.get("reference").asString, + content = nested.content, + contentType = nested.type, + ) + ) } else if (obj.has("readReceipt")) { return ContentJson(ContentTypeReadReceipt, ReadReceipt) } else {