From 4c62651da54b690d51129adb63b557e67d7978ee Mon Sep 17 00:00:00 2001 From: usbharu Date: Sat, 9 Nov 2024 07:01:31 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20ActivityPub=E3=81=AE=E3=83=87=E3=82=B7?= =?UTF-8?q?=E3=83=AA=E3=82=A2=E3=83=A9=E3=82=A4=E3=82=BA=E9=83=A8=E5=88=86?= =?UTF-8?q?=E3=81=AE=E6=97=A7=E3=83=90=E3=83=BC=E3=82=B8=E3=83=A7=E3=83=B3?= =?UTF-8?q?=E3=81=AE=E3=83=A2=E3=83=87=E3=83=AB=E3=82=92=E6=8C=81=E3=81=A3?= =?UTF-8?q?=E3=81=A6=E3=81=8D=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hideout-activitypub/build.gradle.kts | 2 + hideout-activitypub/src/main/kotlin/Main.kt | 5 - .../activitypub/domain/model/Accept.kt | 60 ++++++++++ .../activitypub/domain/model/Announce.kt | 75 ++++++++++++ .../hideout/activitypub/domain/model/Block.kt | 58 ++++++++++ .../activitypub/domain/model/Create.kt | 77 +++++++++++++ .../activitypub/domain/model/Delete.kt | 65 +++++++++++ .../activitypub/domain/model/Document.kt | 56 +++++++++ .../hideout/activitypub/domain/model/Emoji.kt | 64 ++++++++++ .../model/ExtendedActivityVocabulary.kt | 75 ++++++++++++ .../domain/model/ExtendedVocabulary.kt | 21 ++++ .../activitypub/domain/model/Follow.kt | 60 ++++++++++ .../activitypub/domain/model/HasActor.kt | 21 ++++ .../hideout/activitypub/domain/model/HasId.kt | 5 + .../activitypub/domain/model/HasName.kt | 21 ++++ .../hideout/activitypub/domain/model/Image.kt | 53 +++++++++ .../activitypub/domain/model/JsonLd.kt | 101 ++++++++++++++++ .../hideout/activitypub/domain/model/Key.kt | 51 ++++++++ .../hideout/activitypub/domain/model/Like.kt | 71 ++++++++++++ .../hideout/activitypub/domain/model/Note.kt | 108 +++++++++++++++++ .../activitypub/domain/model/Object.kt | 76 ++++++++++++ .../domain/model/ObjectDeserializer.kt | 109 ++++++++++++++++++ .../activitypub/domain/model/ObjectValue.kt | 43 +++++++ .../activitypub/domain/model/Person.kt | 100 ++++++++++++++++ .../activitypub/domain/model/Reject.kt | 57 +++++++++ .../activitypub/domain/model/Tombstone.kt | 39 +++++++ .../hideout/activitypub/domain/model/Undo.kt | 64 ++++++++++ 27 files changed, 1532 insertions(+), 5 deletions(-) delete mode 100644 hideout-activitypub/src/main/kotlin/Main.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Accept.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Announce.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Block.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Create.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Delete.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/ExtendedActivityVocabulary.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/ExtendedVocabulary.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasActor.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasId.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasName.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/JsonLd.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Key.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Like.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Object.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/ObjectDeserializer.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/ObjectValue.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Reject.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Tombstone.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt diff --git a/hideout-activitypub/build.gradle.kts b/hideout-activitypub/build.gradle.kts index 219cda28..60a18a8f 100644 --- a/hideout-activitypub/build.gradle.kts +++ b/hideout-activitypub/build.gradle.kts @@ -16,6 +16,8 @@ repositories { dependencies { testImplementation(kotlin("test")) detektPlugins(libs.detekt.formatting) + implementation("dev.usbharu:hideout-core:0.0.1") + implementation(libs.bundles.jackson) } tasks.test { diff --git a/hideout-activitypub/src/main/kotlin/Main.kt b/hideout-activitypub/src/main/kotlin/Main.kt deleted file mode 100644 index e4395ff8..00000000 --- a/hideout-activitypub/src/main/kotlin/Main.kt +++ /dev/null @@ -1,5 +0,0 @@ -package dev.usbharu - -fun main() { - println("Hello World!") -} diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Accept.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Accept.kt new file mode 100644 index 00000000..13dbc9c1 --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Accept.kt @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.activitypub.domain.model + +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.databind.annotation.JsonDeserialize + +open class Accept @JsonCreator constructor( + type: List = emptyList(), + @JsonDeserialize(using = ObjectDeserializer::class) + @JsonProperty("object") + val apObject: Object, + override val actor: String +) : Object( + type = add(type, "Accept") +), + HasActor { + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as Accept + + if (apObject != other.apObject) return false + if (actor != other.actor) return false + + return true + } + + override fun hashCode(): Int { + var result = super.hashCode() + result = 31 * result + apObject.hashCode() + result = 31 * result + actor.hashCode() + return result + } + + override fun toString(): String { + return "Accept(" + + "apObject=$apObject, " + + "actor='$actor'" + + ")" + + " ${super.toString()}" + } +} diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Announce.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Announce.kt new file mode 100644 index 00000000..4880220a --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Announce.kt @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.activitypub.domain.model + +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty + +open class Announce @JsonCreator constructor( + type: List = emptyList(), + @JsonProperty("object") + val apObject: String, + override val actor: String, + override val id: String, + val published: String, + val to: List = emptyList(), + val cc: List = emptyList() +) : Object( + type = add(type, "Announce") +), + HasActor, + HasId { + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as Announce + + if (apObject != other.apObject) return false + if (actor != other.actor) return false + if (id != other.id) return false + if (published != other.published) return false + if (to != other.to) return false + if (cc != other.cc) return false + + return true + } + + override fun hashCode(): Int { + var result = super.hashCode() + result = 31 * result + apObject.hashCode() + result = 31 * result + actor.hashCode() + result = 31 * result + id.hashCode() + result = 31 * result + published.hashCode() + result = 31 * result + to.hashCode() + result = 31 * result + cc.hashCode() + return result + } + + override fun toString(): String { + return "Announce(" + + "apObject='$apObject', " + + "actor='$actor', " + + "id='$id', " + + "published='$published', " + + "to=$to, " + + "cc=$cc" + + ")" + + " ${super.toString()}" + } +} diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Block.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Block.kt new file mode 100644 index 00000000..d0c8630c --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Block.kt @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.activitypub.domain.model + +import com.fasterxml.jackson.annotation.JsonProperty + +open class Block( + override val actor: String, + override val id: String, + @JsonProperty("object") val apObject: String +) : + Object(listOf("Block")), HasId, HasActor { + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as Block + + if (actor != other.actor) return false + if (id != other.id) return false + if (apObject != other.apObject) return false + + return true + } + + override fun hashCode(): Int { + var result = super.hashCode() + result = 31 * result + actor.hashCode() + result = 31 * result + id.hashCode() + result = 31 * result + apObject.hashCode() + return result + } + + override fun toString(): String { + return "Block(" + + "actor='$actor', " + + "id='$id', " + + "apObject='$apObject'" + + ")" + + " ${super.toString()}" + } +} diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Create.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Create.kt new file mode 100644 index 00000000..3f489407 --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Create.kt @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.activitypub.domain.model + +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.databind.annotation.JsonDeserialize + +open class Create( + type: List = emptyList(), + val name: String? = null, + @JsonDeserialize(using = ObjectDeserializer::class) + @JsonProperty("object") + val apObject: Object, + override val actor: String, + override val id: String, + val to: List = emptyList(), + val cc: List = emptyList() +) : Object( + type = add(type, "Create") +), + HasId, + HasActor { + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as Create + + if (name != other.name) return false + if (apObject != other.apObject) return false + if (actor != other.actor) return false + if (id != other.id) return false + if (to != other.to) return false + if (cc != other.cc) return false + + return true + } + + override fun hashCode(): Int { + var result = super.hashCode() + result = 31 * result + (name?.hashCode() ?: 0) + result = 31 * result + apObject.hashCode() + result = 31 * result + actor.hashCode() + result = 31 * result + id.hashCode() + result = 31 * result + to.hashCode() + result = 31 * result + cc.hashCode() + return result + } + + override fun toString(): String { + return "Create(" + + "name=$name, " + + "apObject=$apObject, " + + "actor='$actor', " + + "id='$id', " + + "to=$to, " + + "cc=$cc" + + ")" + + " ${super.toString()}" + } +} diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Delete.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Delete.kt new file mode 100644 index 00000000..a92ea672 --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Delete.kt @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.activitypub.domain.model + +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.databind.annotation.JsonDeserialize + +open class Delete( + type: List = emptyList(), + @JsonDeserialize(using = ObjectDeserializer::class) + @JsonProperty("object") + val apObject: Object, + val published: String, + override val actor: String, + override val id: String +) : Object(add(type, "Delete")), HasId, HasActor { + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as Delete + + if (apObject != other.apObject) return false + if (published != other.published) return false + if (actor != other.actor) return false + if (id != other.id) return false + + return true + } + + override fun hashCode(): Int { + var result = super.hashCode() + result = 31 * result + apObject.hashCode() + result = 31 * result + published.hashCode() + result = 31 * result + actor.hashCode() + result = 31 * result + id.hashCode() + return result + } + + override fun toString(): String { + return "Delete(" + + "apObject=$apObject, " + + "published='$published', " + + "actor='$actor', " + + "id='$id'" + + ")" + + " ${super.toString()}" + } +} diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt new file mode 100644 index 00000000..8c5632b5 --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.activitypub.domain.model + +import com.fasterxml.jackson.annotation.JsonSetter +import com.fasterxml.jackson.annotation.Nulls + +open class Document( + type: List = emptyList(), + @JsonSetter(nulls = Nulls.AS_EMPTY) + override val name: String = "", + val mediaType: String, + val url: String +) : Object( + type = add(type, "Document") +), + HasName { + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as Document + + if (mediaType != other.mediaType) return false + if (url != other.url) return false + if (name != other.name) return false + + return true + } + + override fun hashCode(): Int { + var result = super.hashCode() + result = 31 * result + mediaType.hashCode() + result = 31 * result + url.hashCode() + result = 31 * result + name.hashCode() + return result + } + + override fun toString(): String = "Document(mediaType=$mediaType, url=$url, name='$name') ${super.toString()}" +} diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt new file mode 100644 index 00000000..e0d05361 --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.activitypub.domain.model + +open class Emoji( + type: List, + override val name: String, + override val id: String, + val updated: String, + val icon: Image +) : Object( + type = add(type, "Emoji") +), + HasName, + HasId { + + override fun toString(): String { + return "Emoji(" + + "name='$name', " + + "id='$id', " + + "updated='$updated', " + + "icon=$icon" + + ")" + + " ${super.toString()}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as Emoji + + if (name != other.name) return false + if (id != other.id) return false + if (updated != other.updated) return false + if (icon != other.icon) return false + + return true + } + + override fun hashCode(): Int { + var result = super.hashCode() + result = 31 * result + name.hashCode() + result = 31 * result + id.hashCode() + result = 31 * result + updated.hashCode() + result = 31 * result + icon.hashCode() + return result + } +} diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/ExtendedActivityVocabulary.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/ExtendedActivityVocabulary.kt new file mode 100644 index 00000000..718a1107 --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/ExtendedActivityVocabulary.kt @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.activitypub.domain.model + +enum class ExtendedActivityVocabulary { + 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, + Emoji +} diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/ExtendedVocabulary.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/ExtendedVocabulary.kt new file mode 100644 index 00000000..8a4eaee6 --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/ExtendedVocabulary.kt @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.activitypub.domain.model + +enum class ExtendedVocabulary { + Emoji +} diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt new file mode 100644 index 00000000..5b641d94 --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.activitypub.domain.model + +import com.fasterxml.jackson.annotation.JsonProperty + +open class Follow( + type: List = emptyList(), + @JsonProperty("object") val apObject: String, + override val actor: String, + val id: String? = null +) : Object( + type = add(type, "Follow") +), + HasActor { + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as Follow + + if (apObject != other.apObject) return false + if (actor != other.actor) return false + if (id != other.id) return false + + return true + } + + override fun hashCode(): Int { + var result = super.hashCode() + result = 31 * result + apObject.hashCode() + result = 31 * result + actor.hashCode() + result = 31 * result + (id?.hashCode() ?: 0) + return result + } + + override fun toString(): String { + return "Follow(" + + "apObject='$apObject', " + + "actor='$actor', " + + "id=$id" + + ")" + + " ${super.toString()}" + } +} diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasActor.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasActor.kt new file mode 100644 index 00000000..d04a3a7c --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasActor.kt @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.activitypub.domain.model + +interface HasActor { + val actor: String +} diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasId.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasId.kt new file mode 100644 index 00000000..774032c8 --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasId.kt @@ -0,0 +1,5 @@ +package dev.usbharu.hideout.activitypub.domain.model + +interface HasId { + val id: String +} diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasName.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasName.kt new file mode 100644 index 00000000..14abb53e --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasName.kt @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.activitypub.domain.model + +interface HasName { + val name: String +} diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt new file mode 100644 index 00000000..fe3665d6 --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.activitypub.domain.model + +open class Image( + type: List = emptyList(), + val mediaType: String? = null, + val url: String +) : Object( + add(type, "Image") +) { + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as Image + + if (mediaType != other.mediaType) return false + if (url != other.url) return false + + return true + } + + override fun hashCode(): Int { + var result = super.hashCode() + result = 31 * result + (mediaType?.hashCode() ?: 0) + result = 31 * result + url.hashCode() + return result + } + + override fun toString(): String { + return "Image(" + + "mediaType=$mediaType, " + + "url='$url'" + + ")" + + " ${super.toString()}" + } +} diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/JsonLd.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/JsonLd.kt new file mode 100644 index 00000000..0e1a3d79 --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/JsonLd.kt @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.activitypub.domain.model + +import com.fasterxml.jackson.annotation.JsonAutoDetect +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonInclude +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.databind.JsonDeserializer +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.JsonSerializer +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize + +@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) +open class JsonLd { + @JsonProperty("@context") + @JsonDeserialize(contentUsing = ContextDeserializer::class) + @JsonSerialize(include = JsonSerialize.Inclusion.NON_EMPTY, using = ContextSerializer::class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + var context: List = emptyList() + set(value) { + field = value.filterNotNull().filter { it.isNotBlank() } + } + + @JsonCreator + constructor(context: List?) { + if (context != null) { + this.context = context.filterNotNull().filter { it.isNotBlank() } + } else { + this.context = emptyList() + } + } + + protected constructor() + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is JsonLd) return false + + return context == other.context + } + + override fun hashCode(): Int = context.hashCode() + + override fun toString(): String = "JsonLd(context=$context)" +} + +class ContextDeserializer : JsonDeserializer() { + + override fun deserialize( + p0: com.fasterxml.jackson.core.JsonParser?, + p1: com.fasterxml.jackson.databind.DeserializationContext? + ): String { + val readTree: JsonNode = p0?.codec?.readTree(p0) ?: return "" + if (readTree.isValueNode) { + return readTree.textValue() + } + return "" + } +} + +class ContextSerializer : JsonSerializer>() { + + @Deprecated("Deprecated in Java") + override fun isEmpty(value: List?): Boolean = value.isNullOrEmpty() + + override fun isEmpty(provider: SerializerProvider?, value: List?): Boolean = value.isNullOrEmpty() + + override fun serialize(value: List?, gen: JsonGenerator?, serializers: SerializerProvider) { + if (value.isNullOrEmpty()) { + serializers.defaultSerializeNull(gen) + return + } + if (value.size == 1) { + gen?.writeString(value[0]) + } else { + gen?.writeStartArray() + value.forEach { + gen?.writeString(it) + } + gen?.writeEndArray() + } + } +} diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Key.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Key.kt new file mode 100644 index 00000000..e9f47645 --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Key.kt @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.activitypub.domain.model + +open class Key( + override val id: String, + val owner: String, + val publicKeyPem: String +) : Object( + type = add(list = emptyList(), type = "Key") +), + HasId { + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as Key + + if (owner != other.owner) return false + if (publicKeyPem != other.publicKeyPem) return false + if (id != other.id) return false + + return true + } + + override fun hashCode(): Int { + var result = super.hashCode() + result = 31 * result + owner.hashCode() + result = 31 * result + publicKeyPem.hashCode() + result = 31 * result + id.hashCode() + return result + } + + override fun toString(): String = "Key(owner=$owner, publicKeyPem=$publicKeyPem, id='$id') ${super.toString()}" +} diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Like.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Like.kt new file mode 100644 index 00000000..9c8d8b9a --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Like.kt @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.activitypub.domain.model + +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.databind.annotation.JsonDeserialize + +open class Like( + type: List = emptyList(), + override val actor: String, + override val id: String, + @JsonProperty("object") val apObject: String, + val content: String, + @JsonDeserialize(contentUsing = ObjectDeserializer::class) val tag: List = emptyList() +) : Object( + type = add(type, "Like") +), + HasId, + HasActor { + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as Like + + if (actor != other.actor) return false + if (id != other.id) return false + if (apObject != other.apObject) return false + if (content != other.content) return false + if (tag != other.tag) return false + + return true + } + + override fun hashCode(): Int { + var result = super.hashCode() + result = 31 * result + actor.hashCode() + result = 31 * result + id.hashCode() + result = 31 * result + apObject.hashCode() + result = 31 * result + content.hashCode() + result = 31 * result + tag.hashCode() + return result + } + + override fun toString(): String { + return "Like(" + + "actor='$actor', " + + "id='$id', " + + "apObject='$apObject', " + + "content='$content', " + + "tag=$tag" + + ")" + + " ${super.toString()}" + } +} diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt new file mode 100644 index 00000000..128b1b4d --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.activitypub.domain.model + +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.databind.annotation.JsonDeserialize + +open class Note +@Suppress("LongParameterList", "CyclomaticComplexMethod") +constructor( + type: List = emptyList(), + override val id: String, + val attributedTo: String, + val content: String, + val published: String, + val to: List = emptyList(), + val cc: List = emptyList(), + val sensitive: Boolean = false, + val inReplyTo: String? = null, + val attachment: List = emptyList(), + @JsonDeserialize(contentUsing = ObjectDeserializer::class) + val tag: List = emptyList(), + val quoteUri: String? = null, + val quoteUrl: String? = null, + @JsonProperty("_misskey_quote") + val misskeyQuote: String? = null +) : Object( + type = add(type, "Note") +), + HasId { + + @Suppress("CyclomaticComplexMethod", "CognitiveComplexMethod") + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as Note + + if (id != other.id) return false + if (attributedTo != other.attributedTo) return false + if (content != other.content) return false + if (published != other.published) return false + if (to != other.to) return false + if (cc != other.cc) return false + if (sensitive != other.sensitive) return false + if (inReplyTo != other.inReplyTo) return false + if (attachment != other.attachment) return false + if (tag != other.tag) return false + if (quoteUri != other.quoteUri) return false + if (quoteUrl != other.quoteUrl) return false + if (misskeyQuote != other.misskeyQuote) return false + + return true + } + + @Suppress("CyclomaticComplexMethod") + override fun hashCode(): Int { + var result = super.hashCode() + result = 31 * result + id.hashCode() + result = 31 * result + attributedTo.hashCode() + result = 31 * result + content.hashCode() + result = 31 * result + published.hashCode() + result = 31 * result + to.hashCode() + result = 31 * result + cc.hashCode() + result = 31 * result + sensitive.hashCode() + result = 31 * result + (inReplyTo?.hashCode() ?: 0) + result = 31 * result + attachment.hashCode() + result = 31 * result + tag.hashCode() + result = 31 * result + (quoteUri?.hashCode() ?: 0) + result = 31 * result + (quoteUrl?.hashCode() ?: 0) + result = 31 * result + (misskeyQuote?.hashCode() ?: 0) + return result + } + + override fun toString(): String { + return "Note(" + + "id='$id', " + + "attributedTo='$attributedTo', " + + "content='$content', " + + "published='$published', " + + "to=$to, " + + "cc=$cc, " + + "sensitive=$sensitive, " + + "inReplyTo=$inReplyTo, " + + "attachment=$attachment, " + + "tag=$tag, " + + "quoteUri=$quoteUri, " + + "quoteUrl=$quoteUrl, " + + "misskeyQuote=$misskeyQuote" + + ")" + + " ${super.toString()}" + } +} diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Object.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Object.kt new file mode 100644 index 00000000..8c5b1958 --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Object.kt @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.activitypub.domain.model + +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.databind.JsonSerializer +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonSerialize + +open class Object : JsonLd { + @JsonSerialize(using = TypeSerializer::class) + var type: List = emptyList() + set(value) { + field = value.filter { it.isNotBlank() } + } + + protected constructor() + constructor(type: List) : super() { + this.type = type.filter { it.isNotBlank() } + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as Object + + return type == other.type + } + + override fun hashCode(): Int { + var result = super.hashCode() + result = 31 * result + type.hashCode() + return result + } + + override fun toString(): String = "Object(type=$type) ${super.toString()}" + + companion object { + @JvmStatic + protected fun add(list: List, type: String): List { + val toMutableList = list.toMutableList() + toMutableList.add(type) + return toMutableList.distinct() + } + } +} + +class TypeSerializer : JsonSerializer>() { + override fun serialize(value: List?, gen: JsonGenerator?, serializers: SerializerProvider?) { + if (value?.size == 1) { + gen?.writeString(value[0]) + } else { + gen?.writeStartArray() + value?.forEach { + gen?.writeString(it) + } + gen?.writeEndArray() + } + } +} diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/ObjectDeserializer.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/ObjectDeserializer.kt new file mode 100644 index 00000000..003e1e46 --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/ObjectDeserializer.kt @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.activitypub.domain.model + +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.activitypub.domain.model.* + +class ObjectDeserializer : JsonDeserializer() { + @Suppress("LongMethod", "CyclomaticComplexMethod") + override fun deserialize(p: JsonParser?, ctxt: DeserializationContext?): Object? { + requireNotNull(p) + val treeNode: JsonNode = requireNotNull(p.codec?.readTree(p)) + if (treeNode.isValueNode) { + return ObjectValue( + emptyList(), + treeNode.asText() + ) + } else if (treeNode.isObject) { + val type = treeNode["type"] + val activityType = if (type.isArray) { + type.firstNotNullOf { jsonNode: JsonNode -> + ExtendedActivityVocabulary.entries.firstOrNull { it.name.equals(jsonNode.asText(), true) } + } + } else if (type.isValueNode) { + ExtendedActivityVocabulary.entries.firstOrNull { it.name.equals(type.asText(), true) } + } else { + null + } + + return when (activityType) { + ExtendedActivityVocabulary.Follow -> p.codec.treeToValue(treeNode, Follow::class.java) + ExtendedActivityVocabulary.Note -> p.codec.treeToValue(treeNode, Note::class.java) + ExtendedActivityVocabulary.Object -> p.codec.treeToValue(treeNode, Object::class.java) + ExtendedActivityVocabulary.Link -> null + ExtendedActivityVocabulary.Activity -> null + ExtendedActivityVocabulary.IntransitiveActivity -> null + ExtendedActivityVocabulary.Collection -> null + ExtendedActivityVocabulary.OrderedCollection -> null + ExtendedActivityVocabulary.CollectionPage -> null + ExtendedActivityVocabulary.OrderedCollectionPage -> null + ExtendedActivityVocabulary.Accept -> p.codec.treeToValue(treeNode, Accept::class.java) + ExtendedActivityVocabulary.Add -> null + ExtendedActivityVocabulary.Announce -> p.codec.treeToValue(treeNode, Announce::class.java) + ExtendedActivityVocabulary.Arrive -> null + ExtendedActivityVocabulary.Block -> p.codec.treeToValue(treeNode, Block::class.java) + ExtendedActivityVocabulary.Create -> p.codec.treeToValue(treeNode, Create::class.java) + ExtendedActivityVocabulary.Delete -> p.codec.treeToValue(treeNode, Delete::class.java) + ExtendedActivityVocabulary.Dislike -> null + ExtendedActivityVocabulary.Flag -> null + ExtendedActivityVocabulary.Ignore -> null + ExtendedActivityVocabulary.Invite -> null + ExtendedActivityVocabulary.Join -> null + ExtendedActivityVocabulary.Leave -> null + ExtendedActivityVocabulary.Like -> p.codec.treeToValue(treeNode, Like::class.java) + ExtendedActivityVocabulary.Listen -> null + ExtendedActivityVocabulary.Move -> null + ExtendedActivityVocabulary.Offer -> null + ExtendedActivityVocabulary.Question -> null + ExtendedActivityVocabulary.Reject -> p.codec.treeToValue(treeNode, Reject::class.java) + ExtendedActivityVocabulary.Read -> null + ExtendedActivityVocabulary.Remove -> null + ExtendedActivityVocabulary.TentativeReject -> null + ExtendedActivityVocabulary.TentativeAccept -> null + ExtendedActivityVocabulary.Travel -> null + ExtendedActivityVocabulary.Undo -> p.codec.treeToValue(treeNode, Undo::class.java) + ExtendedActivityVocabulary.Update -> null + ExtendedActivityVocabulary.View -> null + ExtendedActivityVocabulary.Application -> null + ExtendedActivityVocabulary.Group -> null + ExtendedActivityVocabulary.Organization -> null + ExtendedActivityVocabulary.Person -> p.codec.treeToValue(treeNode, Person::class.java) + ExtendedActivityVocabulary.Service -> null + ExtendedActivityVocabulary.Article -> null + ExtendedActivityVocabulary.Audio -> null + ExtendedActivityVocabulary.Document -> p.codec.treeToValue(treeNode, Document::class.java) + ExtendedActivityVocabulary.Event -> null + ExtendedActivityVocabulary.Image -> p.codec.treeToValue(treeNode, Image::class.java) + ExtendedActivityVocabulary.Page -> null + ExtendedActivityVocabulary.Place -> null + ExtendedActivityVocabulary.Profile -> null + ExtendedActivityVocabulary.Relationship -> null + ExtendedActivityVocabulary.Tombstone -> p.codec.treeToValue(treeNode, Tombstone::class.java) + ExtendedActivityVocabulary.Video -> null + ExtendedActivityVocabulary.Mention -> null + ExtendedActivityVocabulary.Emoji -> p.codec.treeToValue(treeNode, Emoji::class.java) + null -> null + } + } else { + return null + } + } +} diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/ObjectValue.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/ObjectValue.kt new file mode 100644 index 00000000..ff3e0d9c --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/ObjectValue.kt @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.activitypub.domain.model + +import com.fasterxml.jackson.annotation.JsonCreator + +@Suppress("VariableNaming") +open class ObjectValue @JsonCreator constructor(type: List, var `object`: String) : Object( + type +) { + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as ObjectValue + + return `object` == other.`object` + } + + override fun hashCode(): Int { + var result = super.hashCode() + result = 31 * result + `object`.hashCode() + return result + } + + override fun toString(): String = "ObjectValue(`object`='$`object`') ${super.toString()}" +} diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt new file mode 100644 index 00000000..db0e2d9d --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.activitypub.domain.model + +open class Person +@Suppress("LongParameterList") +constructor( + type: List = emptyList(), + val name: String?, + override val id: String, + var preferredUsername: String, + var summary: String?, + var inbox: String, + var outbox: String, + var url: String, + private var icon: Image?, + var publicKey: Key, + var endpoints: Map = emptyMap(), + var followers: String?, + var following: String?, + val manuallyApprovesFollowers: Boolean? = false +) : Object(add(type, "Person")), HasId { + + @Suppress("CyclomaticComplexMethod", "CognitiveComplexMethod") + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as Person + + if (name != other.name) return false + if (id != other.id) return false + if (preferredUsername != other.preferredUsername) return false + if (summary != other.summary) return false + if (inbox != other.inbox) return false + if (outbox != other.outbox) return false + if (url != other.url) return false + if (icon != other.icon) return false + if (publicKey != other.publicKey) return false + if (endpoints != other.endpoints) return false + if (followers != other.followers) return false + if (following != other.following) return false + if (manuallyApprovesFollowers != other.manuallyApprovesFollowers) return false + + return true + } + + @Suppress("CyclomaticComplexMethod") + override fun hashCode(): Int { + var result = super.hashCode() + result = 31 * result + (name?.hashCode() ?: 0) + result = 31 * result + id.hashCode() + result = 31 * result + preferredUsername.hashCode() + result = 31 * result + (summary?.hashCode() ?: 0) + result = 31 * result + inbox.hashCode() + result = 31 * result + outbox.hashCode() + result = 31 * result + url.hashCode() + result = 31 * result + (icon?.hashCode() ?: 0) + result = 31 * result + publicKey.hashCode() + result = 31 * result + endpoints.hashCode() + result = 31 * result + (followers?.hashCode() ?: 0) + result = 31 * result + (following?.hashCode() ?: 0) + result = 31 * result + (manuallyApprovesFollowers?.hashCode() ?: 0) + return result + } + + override fun toString(): String { + return "Person(" + + "name=$name, " + + "id='$id', " + + "preferredUsername='$preferredUsername', " + + "summary=$summary, " + + "inbox='$inbox', " + + "outbox='$outbox', " + + "url='$url', " + + "icon=$icon, " + + "publicKey=$publicKey, " + + "endpoints=$endpoints, " + + "followers=$followers, " + + "following=$following, " + + "manuallyApprovesFollowers=$manuallyApprovesFollowers" + + ")" + + " ${super.toString()}" + } +} diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Reject.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Reject.kt new file mode 100644 index 00000000..304d9b95 --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Reject.kt @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.activitypub.domain.model + +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.databind.annotation.JsonDeserialize + +open class Reject( + override val actor: String, + override val id: String, + @JsonDeserialize(using = ObjectDeserializer::class) @JsonProperty("object") val apObject: Object +) : Object(listOf("Reject")), HasId, HasActor { + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as Reject + + if (actor != other.actor) return false + if (id != other.id) return false + if (apObject != other.apObject) return false + + return true + } + + override fun hashCode(): Int { + var result = super.hashCode() + result = 31 * result + actor.hashCode() + result = 31 * result + id.hashCode() + result = 31 * result + apObject.hashCode() + return result + } + + override fun toString(): String { + return "Reject(" + + "actor='$actor', " + + "id='$id', " + + "apObject=$apObject" + + ")" + + " ${super.toString()}" + } +} diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Tombstone.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Tombstone.kt new file mode 100644 index 00000000..187fc7dc --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Tombstone.kt @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.activitypub.domain.model + +open class Tombstone(type: List = emptyList(), override val id: String) : + Object(add(type, "Tombstone")), + HasId { + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as Tombstone + + return id == other.id + } + + override fun hashCode(): Int { + var result = super.hashCode() + result = 31 * result + id.hashCode() + return result + } + + override fun toString(): String = "Tombstone(id='$id') ${super.toString()}" +} diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt new file mode 100644 index 00000000..f957db20 --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.activitypub.domain.model + +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.databind.annotation.JsonDeserialize + +open class Undo( + type: List = emptyList(), + override val actor: String, + override val id: String, + @JsonDeserialize(using = ObjectDeserializer::class) + @JsonProperty("object") val apObject: Object, + val published: String? +) : Object(add(type, "Undo")), HasId, HasActor { + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as Undo + + if (actor != other.actor) return false + if (id != other.id) return false + if (apObject != other.apObject) return false + if (published != other.published) return false + + return true + } + + override fun hashCode(): Int { + var result = super.hashCode() + result = 31 * result + actor.hashCode() + result = 31 * result + id.hashCode() + result = 31 * result + apObject.hashCode() + result = 31 * result + (published?.hashCode() ?: 0) + return result + } + + override fun toString(): String { + return "Undo(" + + "actor='$actor', " + + "id='$id', " + + "apObject=$apObject, " + + "published=$published" + + ")" + + " ${super.toString()}" + } +}