From 997fb8dce3015be1a3ee4bedc6426483298f3d72 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Wed, 5 Apr 2023 17:54:00 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20ActivityPub=E3=81=AEType=E3=83=91?= =?UTF-8?q?=E3=83=BC=E3=82=B5=E3=82=92=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/ap/JsonParseException.kt | 8 +++ .../service/activitypub/ActivityPubService.kt | 2 +- .../activitypub/ActivityPubServiceImpl.kt | 55 +++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/dev/usbharu/hideout/exception/ap/JsonParseException.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubServiceImpl.kt diff --git a/src/main/kotlin/dev/usbharu/hideout/exception/ap/JsonParseException.kt b/src/main/kotlin/dev/usbharu/hideout/exception/ap/JsonParseException.kt new file mode 100644 index 00000000..61208029 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/exception/ap/JsonParseException.kt @@ -0,0 +1,8 @@ +package dev.usbharu.hideout.exception.ap + +class JsonParseException : IllegalArgumentException { + constructor() : super() + constructor(s: String?) : super(s) + constructor(message: String?, cause: Throwable?) : super(message, cause) + constructor(cause: Throwable?) : super(cause) +} 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 070046a3..55d3eec4 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubService.kt @@ -1,7 +1,7 @@ package dev.usbharu.hideout.service.activitypub interface ActivityPubService { - fun parseActivity(json:String): ActivityType + fun parseActivity(json:String): List fun processActivity(json:String, type: ActivityType) } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubServiceImpl.kt new file mode 100644 index 00000000..6e407bb3 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubServiceImpl.kt @@ -0,0 +1,55 @@ +package dev.usbharu.hideout.service.activitypub + +import com.fasterxml.jackson.databind.JsonNode +import dev.usbharu.hideout.config.Config +import dev.usbharu.hideout.exception.ap.JsonParseException + +class ActivityPubServiceImpl : ActivityPubService { + override fun parseActivity(json: String): List { + val readTree = Config.configData.objectMapper.readTree(json) + if (readTree.isObject.not()) { + throw JsonParseException("Json is not object.") + } + val type = readTree["type"] + if (type.isArray) { + return type.mapNotNull { jsonNode: JsonNode -> + ActivityType.values().filter { it.name.equals(jsonNode.toPrettyString(), true) } + }.flatten() + } + return ActivityType.values().filter { it.name.equals(type.toPrettyString(), true) } + } + + override fun processActivity(json: String, type: ActivityType) { + when (type) { + ActivityType.Accept -> TODO() + ActivityType.Add -> TODO() + ActivityType.Announce -> TODO() + ActivityType.Arrive -> TODO() + ActivityType.Block -> TODO() + ActivityType.Create -> TODO() + ActivityType.Delete -> TODO() + ActivityType.Dislike -> TODO() + ActivityType.Flag -> TODO() + ActivityType.Follow -> TODO() + ActivityType.Ignore -> TODO() + ActivityType.Invite -> TODO() + ActivityType.Join -> TODO() + ActivityType.Leave -> TODO() + ActivityType.Like -> TODO() + ActivityType.Listen -> TODO() + ActivityType.Move -> TODO() + ActivityType.Offer -> TODO() + ActivityType.Question -> TODO() + ActivityType.Reject -> TODO() + ActivityType.Read -> TODO() + ActivityType.Remove -> TODO() + ActivityType.TentativeReject -> TODO() + ActivityType.TentativeAccept -> TODO() + ActivityType.Travel -> TODO() + ActivityType.Undo -> TODO() + ActivityType.Update -> TODO() + ActivityType.View -> TODO() + ActivityType.Other -> TODO() + } + } +}