Merge pull request #264 from usbharu/bugfix/undo-published

Bugfix/undo published
This commit is contained in:
usbharu 2024-01-29 11:25:15 +09:00 committed by GitHub
commit 98e47cbfe0
3 changed files with 34 additions and 7 deletions

View File

@ -11,7 +11,7 @@ open class Undo(
override val id: String, override val id: String,
@JsonDeserialize(using = ObjectDeserializer::class) @JsonDeserialize(using = ObjectDeserializer::class)
@JsonProperty("object") val apObject: Object, @JsonProperty("object") val apObject: Object,
val published: String val published: String?
) : Object(add(type, "Undo")), HasId, HasActor { ) : Object(add(type, "Undo")), HasId, HasActor {
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
@ -21,20 +21,20 @@ open class Undo(
other as Undo other as Undo
if (apObject != other.apObject) return false
if (published != other.published) return false
if (actor != other.actor) return false if (actor != other.actor) return false
if (id != other.id) return false if (id != other.id) return false
if (apObject != other.apObject) return false
if (published != other.published) return false
return true return true
} }
override fun hashCode(): Int { override fun hashCode(): Int {
var result = super.hashCode() var result = super.hashCode()
result = 31 * result + apObject.hashCode()
result = 31 * result + published.hashCode()
result = 31 * result + actor.hashCode() result = 31 * result + actor.hashCode()
result = 31 * result + id.hashCode() result = 31 * result + id.hashCode()
result = 31 * result + apObject.hashCode()
result = 31 * result + (published?.hashCode() ?: 0)
return result return result
} }
@ -43,7 +43,7 @@ open class Undo(
"actor='$actor', " + "actor='$actor', " +
"id='$id', " + "id='$id', " +
"apObject=$apObject, " + "apObject=$apObject, " +
"published='$published'" + "published=$published" +
")" + ")" +
" ${super.toString()}" " ${super.toString()}"
} }

View File

@ -1,5 +1,6 @@
package dev.usbharu.hideout.activitypub.service.inbox package dev.usbharu.hideout.activitypub.service.inbox
import com.fasterxml.jackson.core.JsonParseException
import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue import com.fasterxml.jackson.module.kotlin.readValue
import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.Object
@ -119,7 +120,12 @@ class InboxJobProcessor(
throw IllegalStateException("ActivityPubProcessor not found. type: ${param.type}") 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)) activityPubProcessor.process(ActivityPubProcessContext(value, jsonNode, httpRequest, signature, verify))
logger.info("SUCCESS Process inbox. type: {}", param.type) logger.info("SUCCESS Process inbox. type: {}", param.type)

View File

@ -71,4 +71,25 @@ class UndoTest {
val undo = ActivityPubConfig().objectMapper().readValue(json, Undo::class.java) val undo = ActivityPubConfig().objectMapper().readValue(json, Undo::class.java)
println(undo) 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<Undo>(json, Undo::class.java)
println(undo)
}
} }