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() + } + } +}