Skip to content

Commit 5cfaa52

Browse files
authored
fix: use type from the reply nested content directly (#104)
1 parent 18f1788 commit 5cfaa52

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

library/src/main/java/org/xmtp/android/library/codecs/ContentTypeId.kt

+3
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ class ContentTypeIdBuilder {
2222

2323
val ContentTypeId.id: String
2424
get() = "$authorityId:$typeId"
25+
26+
val ContentTypeId.description: String
27+
get() = "$authorityId/$typeId:$versionMajor.$versionMinor"

library/src/main/java/org/xmtp/android/library/codecs/ReplyCodec.kt

+3-4
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,18 @@ data class ReplyCodec(override var contentType: ContentTypeId = ContentTypeReply
2424

2525
return EncodedContent.newBuilder().also {
2626
it.type = ContentTypeReply
27-
it.putParameters("contentType", reply.contentType.id)
27+
// TODO: cut when we're certain no one is looking for "contentType" here.
28+
it.putParameters("contentType", reply.contentType.description)
2829
it.putParameters("reference", reply.reference)
2930
it.content = encodeReply(replyCodec, reply.content).toByteString()
3031
}.build()
3132
}
3233

3334
override fun decode(content: EncodedContent): Reply {
34-
val contentTypeIdString =
35-
content.getParametersOrThrow("contentType") ?: throw XMTPException("Codec Not Found")
3635
val reference =
3736
content.getParametersOrThrow("reference") ?: throw XMTPException("Invalid Content")
3837
val replyEncodedContent = EncodedContent.parseFrom(content.content)
39-
val replyCodec = Client.codecRegistry.findFromId(contentTypeIdString)
38+
val replyCodec = Client.codecRegistry.find(replyEncodedContent.type)
4039
val replyContent = replyCodec.decode(content = replyEncodedContent)
4140
?: throw XMTPException("Invalid Content")
4241
return Reply(

0 commit comments

Comments
 (0)