mirror of https://github.com/usbharu/Hideout.git
feat: ActivityPubのTypeパーサを作成
This commit is contained in:
parent
a0ad41c5e9
commit
2e7cecdd13
|
@ -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)
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
package dev.usbharu.hideout.service.activitypub
|
package dev.usbharu.hideout.service.activitypub
|
||||||
|
|
||||||
interface ActivityPubService {
|
interface ActivityPubService {
|
||||||
fun parseActivity(json:String): ActivityType
|
fun parseActivity(json:String): List<ActivityType>
|
||||||
|
|
||||||
fun processActivity(json:String, type: ActivityType)
|
fun processActivity(json:String, type: ActivityType)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<ActivityType> {
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue