From b0e57764d3b124fd5e88f1df7d32233b002ad762 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Tue, 23 May 2023 23:51:53 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20Create=E3=82=92=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E3=81=AB=E5=87=A6=E7=90=86=E3=81=A7=E3=81=8D=E3=81=A6=E3=81=84?= =?UTF-8?q?=E3=81=AA=E3=81=8B=E3=81=A3=E3=81=9F=E3=81=AE=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/model/ap/ObjectDeserializer.kt | 12 ++-- .../ActivityPubCreateServiceImpl.kt | 2 +- .../service/activitypub/ActivityPubService.kt | 57 +++++++++++++++++++ 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/ObjectDeserializer.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/ObjectDeserializer.kt index 70bcee3b..501682ce 100644 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/ObjectDeserializer.kt +++ b/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/ObjectDeserializer.kt @@ -4,7 +4,7 @@ import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.databind.DeserializationContext import com.fasterxml.jackson.databind.JsonDeserializer import com.fasterxml.jackson.databind.JsonNode -import dev.usbharu.hideout.service.activitypub.ActivityType +import dev.usbharu.hideout.service.activitypub.ActivityVocabulary class ObjectDeserializer : JsonDeserializer() { override fun deserialize(p: JsonParser?, ctxt: DeserializationContext?): Object { @@ -22,21 +22,25 @@ class ObjectDeserializer : JsonDeserializer() { val type = treeNode["type"] val activityType = if (type.isArray) { type.firstNotNullOf { jsonNode: JsonNode -> - ActivityType.values().firstOrNull { it.name.equals(jsonNode.asText(), true) } + ActivityVocabulary.values().firstOrNull { it.name.equals(jsonNode.asText(), true) } } } else if (type.isValueNode) { - ActivityType.values().first { it.name.equals(type.asText(), true) } + ActivityVocabulary.values().first { it.name.equals(type.asText(), true) } } else { TODO() } return when (activityType) { - ActivityType.Follow -> { + ActivityVocabulary.Follow -> { val readValue = p.codec.treeToValue(treeNode, Follow::class.java) println(readValue) readValue } + ActivityVocabulary.Note -> { + p.codec.treeToValue(treeNode, Note::class.java) + } + else -> { TODO() } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubCreateServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubCreateServiceImpl.kt index 59a6b485..b73e3747 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubCreateServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubCreateServiceImpl.kt @@ -20,6 +20,6 @@ class ActivityPubCreateServiceImpl( val note = value as Note activityPubNoteService.fetchNote(note) - return ActivityPubStringResponse(HttpStatusCode.Created, "Created") + return ActivityPubStringResponse(HttpStatusCode.OK, "Created") } } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubService.kt b/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubService.kt index df6f24ac..f61e825d 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubService.kt @@ -43,3 +43,60 @@ enum class ActivityType { View, Other } + +enum class ActivityVocabulary { + Object, + Link, + Activity, + IntransitiveActivity, + Collection, + OrderedCollection, + CollectionPage, + OrderedCollectionPage, + Accept, + Add, + Announce, + Arrive, + Block, + Create, + Delete, + Dislike, + Flag, + Follow, + Ignore, + Invite, + Join, + Leave, + Like, + Listen, + Move, + Offer, + Question, + Reject, + Read, + Remove, + TentativeReject, + TentativeAccept, + Travel, + Undo, + Update, + View, + Application, + Group, + Organization, + Person, + Service, + Article, + Audio, + Document, + Event, + Image, + Note, + Page, + Place, + Profile, + Relationship, + Tombstone, + Video, + Mention, +}