From 25efe83176ad3768fe4c893f5825299fb1d463eb Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Mon, 29 Jan 2024 10:59:32 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20undo=E3=81=ABpublished=E3=81=8C?= =?UTF-8?q?=E5=BF=85=E9=A0=88=E3=81=AB=E3=81=AA=E3=81=A3=E3=81=A6=E3=81=84?= =?UTF-8?q?=E3=81=9F=E3=81=AE=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usbharu/hideout/activitypub/domain/model/Undo.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt index 178373fd..6f27026e 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt @@ -11,7 +11,7 @@ open class Undo( override val id: String, @JsonDeserialize(using = ObjectDeserializer::class) @JsonProperty("object") val apObject: Object, - val published: String + val published: String? ) : Object(add(type, "Undo")), HasId, HasActor { override fun equals(other: Any?): Boolean { @@ -21,20 +21,20 @@ open class Undo( other as Undo - if (apObject != other.apObject) return false - if (published != other.published) return false if (actor != other.actor) return false if (id != other.id) return false + if (apObject != other.apObject) return false + if (published != other.published) return false return true } override fun hashCode(): Int { var result = super.hashCode() - result = 31 * result + apObject.hashCode() - result = 31 * result + published.hashCode() result = 31 * result + actor.hashCode() result = 31 * result + id.hashCode() + result = 31 * result + apObject.hashCode() + result = 31 * result + (published?.hashCode() ?: 0) return result } @@ -43,7 +43,7 @@ open class Undo( "actor='$actor', " + "id='$id', " + "apObject=$apObject, " + - "published='$published'" + + "published=$published" + ")" + " ${super.toString()}" } From 0ecf6f7032015722bab11e72fb37a2e597c1e59a Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Mon, 29 Jan 2024 11:00:11 +0900 Subject: [PATCH 2/3] =?UTF-8?q?test:=20Undo=E3=81=ABMastodon=E3=81=AEJSON?= =?UTF-8?q?=E3=81=AE=E3=83=87=E3=82=B7=E3=83=AA=E3=82=A2=E3=83=A9=E3=82=A4?= =?UTF-8?q?=E3=82=BA=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activitypub/domain/model/UndoTest.kt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/UndoTest.kt b/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/UndoTest.kt index ea279694..ad111d27 100644 --- a/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/UndoTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/UndoTest.kt @@ -71,4 +71,25 @@ class UndoTest { val undo = ActivityPubConfig().objectMapper().readValue(json, Undo::class.java) println(undo) } + + @Test + fun MastodonのUndoのデシリアライズができる() { + //language=JSON + val json = """{ + "@context" : "https://www.w3.org/ns/activitystreams", + "id" : "https://kb.usbharu.dev/users/usbharu#follows/12/undo", + "type" : "Undo", + "actor" : "https://kb.usbharu.dev/users/usbharu", + "object" : { + "id" : "https://kb.usbharu.dev/0347b269-4dcb-4eb1-b8c4-b5f157bb6957", + "type" : "Follow", + "actor" : "https://kb.usbharu.dev/users/usbharu", + "object" : "https://test-hideout.usbharu.dev/users/testuser15" + } +}""".trimIndent() + + val undo = ActivityPubConfig().objectMapper().readValue(json, Undo::class.java) + + println(undo) + } } From 616cb8e6a7d7372ba0a670640846b0d487f3f4e6 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Mon, 29 Jan 2024 11:17:58 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20JSON=E3=81=AE=E3=83=87=E3=82=B7?= =?UTF-8?q?=E3=83=AA=E3=82=A2=E3=83=A9=E3=82=A4=E3=82=BA=E3=81=AB=E5=A4=B1?= =?UTF-8?q?=E6=95=97=E3=81=97=E3=81=9F=E3=81=A8=E3=81=8D=E3=83=AD=E3=82=B0?= =?UTF-8?q?=E3=82=92=E5=87=BA=E3=81=99=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activitypub/service/inbox/InboxJobProcessor.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/inbox/InboxJobProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/inbox/InboxJobProcessor.kt index fbe38266..48bbbfe1 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/inbox/InboxJobProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/inbox/InboxJobProcessor.kt @@ -1,5 +1,6 @@ package dev.usbharu.hideout.activitypub.service.inbox +import com.fasterxml.jackson.core.JsonParseException import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.module.kotlin.readValue import dev.usbharu.hideout.activitypub.domain.model.objects.Object @@ -119,7 +120,12 @@ class InboxJobProcessor( throw IllegalStateException("ActivityPubProcessor not found. type: ${param.type}") } - val value = objectMapper.treeToValue(jsonNode, activityPubProcessor.type()) + val value = try { + objectMapper.treeToValue(jsonNode, activityPubProcessor.type()) + } catch (e: JsonParseException) { + logger.warn("Invalid JSON\n\n{}\n\n", jsonNode.toPrettyString()) + throw e + } activityPubProcessor.process(ActivityPubProcessContext(value, jsonNode, httpRequest, signature, verify)) logger.info("SUCCESS Process inbox. type: {}", param.type)