From 6c2d5dae94a52306f2212e3b4258b4177c820981 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Tue, 28 Nov 2023 10:44:54 +0900 Subject: [PATCH 1/7] =?UTF-8?q?refactor:=20=E4=B8=80=E9=83=A8=E3=81=AEAP?= =?UTF-8?q?=E3=81=AEJSON=E3=83=9E=E3=83=83=E3=83=94=E3=83=B3=E3=82=B0?= =?UTF-8?q?=E7=94=A8=E3=81=AEPOJO=E3=82=92Null-safe=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usbharu/hideout/activitypub/domain/model/Note.kt | 12 ++++++------ .../service/objects/note/APNoteService.kt | 5 ++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt index ddca1d67..cc891c08 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt @@ -3,10 +3,10 @@ package dev.usbharu.hideout.activitypub.domain.model import dev.usbharu.hideout.activitypub.domain.model.objects.Object open class Note : Object { - var attributedTo: String? = null + lateinit var attributedTo: String var attachment: List = emptyList() - var content: String? = null - var published: String? = null + lateinit var content: String + lateinit var published: String var to: List = emptyList() var cc: List = emptyList() var sensitive: Boolean = false @@ -19,9 +19,9 @@ open class Note : Object { type: List = emptyList(), name: String, id: String?, - attributedTo: String?, - content: String?, - published: String?, + attributedTo: String, + content: String, + published: String, to: List = emptyList(), cc: List = emptyList(), sensitive: Boolean = false, diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/APNoteService.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/APNoteService.kt index f7300314..28bf7c01 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/APNoteService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/APNoteService.kt @@ -1,7 +1,6 @@ package dev.usbharu.hideout.activitypub.service.objects.note import dev.usbharu.hideout.activitypub.domain.exception.FailedToGetActivityPubResourceException -import dev.usbharu.hideout.activitypub.domain.exception.IllegalActivityPubObjectException import dev.usbharu.hideout.activitypub.domain.model.Note import dev.usbharu.hideout.activitypub.query.NoteQueryService import dev.usbharu.hideout.activitypub.service.common.APResourceResolveService @@ -99,7 +98,7 @@ class APNoteServiceImpl( private suspend fun saveNote(note: Note, targetActor: String?, url: String): Note { val person = apUserService.fetchPersonWithEntity( - note.attributedTo ?: throw IllegalActivityPubObjectException("note.attributedTo is null"), + note.attributedTo, targetActor ) @@ -142,7 +141,7 @@ class APNoteServiceImpl( postBuilder.of( id = postRepository.generateId(), userId = person.second.id, - text = note.content.orEmpty(), + text = note.content, createdAt = Instant.parse(note.published).toEpochMilli(), visibility = visibility, url = note.id ?: url, From 7a34b11147a18974422c3919f41371fc52d52fdc Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Tue, 28 Nov 2023 11:19:27 +0900 Subject: [PATCH 2/7] =?UTF-8?q?refactor:=20Object=E3=82=92=E7=B6=99?= =?UTF-8?q?=E6=89=BF=E3=81=99=E3=82=8BJSON=E3=83=9E=E3=83=83=E3=83=94?= =?UTF-8?q?=E3=83=B3=E3=82=B0=E7=94=A8=E3=81=AEPOJO=E3=82=92Null-safe?= =?UTF-8?q?=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activitypub/domain/model/Accept.kt | 45 ++++++----- .../activitypub/domain/model/Create.kt | 57 +++++++------- .../activitypub/domain/model/Delete.kt | 27 +++++-- .../activitypub/domain/model/Document.kt | 20 ++--- .../hideout/activitypub/domain/model/Emoji.kt | 5 +- .../activitypub/domain/model/Follow.kt | 25 +++--- .../activitypub/domain/model/HasActor.kt | 5 ++ .../hideout/activitypub/domain/model/HasId.kt | 5 ++ .../activitypub/domain/model/HasName.kt | 5 ++ .../hideout/activitypub/domain/model/Image.kt | 15 ++-- .../hideout/activitypub/domain/model/Key.kt | 22 +++--- .../hideout/activitypub/domain/model/Like.kt | 33 +++++--- .../hideout/activitypub/domain/model/Note.kt | 77 +++++++------------ .../activitypub/domain/model/Person.kt | 58 ++++---------- .../activitypub/domain/model/Tombstone.kt | 27 +++++-- .../hideout/activitypub/domain/model/Undo.kt | 28 +++++-- .../domain/model/objects/Object.kt | 22 ++---- .../domain/model/objects/ObjectValue.kt | 13 ++-- 18 files changed, 258 insertions(+), 231 deletions(-) create mode 100644 src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasActor.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasId.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasName.kt diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Accept.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Accept.kt index c249afb4..d1b0936b 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Accept.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Accept.kt @@ -1,41 +1,46 @@ package dev.usbharu.hideout.activitypub.domain.model +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.databind.annotation.JsonDeserialize import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer -open class Accept : Object { +open class Accept @JsonCreator constructor( + type: List = emptyList(), + override val name: String, @JsonDeserialize(using = ObjectDeserializer::class) @Suppress("VariableNaming") - var `object`: Object? = null - - protected constructor() - constructor( - type: List = emptyList(), - name: String, - `object`: Object?, - actor: String? - ) : super( - type = add(type, "Accept"), - name = name, - actor = actor - ) { - this.`object` = `object` - } - - override fun toString(): String = "Accept(`object`=$`object`) ${super.toString()}" + var `object`: Object?, + override val actor: String +) : Object( + type = add(type, "Accept") +), + HasActor, + HasName { override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is Accept) return false + if (javaClass != other?.javaClass) return false if (!super.equals(other)) return false - return `object` == other.`object` + other as Accept + + if (`object` != other.`object`) return false + if (actor != other.actor) return false + if (name != other.name) return false + + return true } override fun hashCode(): Int { var result = super.hashCode() result = 31 * result + (`object`?.hashCode() ?: 0) + result = 31 * result + actor.hashCode() + result = 31 * result + name.hashCode() return result } + + override fun toString(): String { + return "Accept(" + "`object`=$`object`, " + "actor='$actor', " + "name='$name'" + ")" + " ${super.toString()}" + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Create.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Create.kt index 6b19ab5b..df22045c 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Create.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Create.kt @@ -4,46 +4,51 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer -open class Create : Object { +open class Create( + type: List = emptyList(), + override val name: String, @JsonDeserialize(using = ObjectDeserializer::class) @Suppress("VariableNaming") - var `object`: Object? = null - var to: List = emptyList() + var `object`: Object?, + override val actor: String, + override val id: String, + var to: List = emptyList(), var cc: List = emptyList() - - protected constructor() : super() - constructor( - type: List = emptyList(), - name: String? = null, - `object`: Object?, - actor: String? = null, - id: String? = null, - to: List = emptyList(), - cc: List = emptyList() - ) : super( - type = add(type, "Create"), - name = name, - actor = actor, - id = id - ) { - this.`object` = `object` - this.to = to - this.cc = cc - } +) : Object( + type = add(type, "Create") +), + HasId, + HasName, + HasActor { override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is Create) return false + if (javaClass != other?.javaClass) return false if (!super.equals(other)) return false - return `object` == other.`object` + other as Create + + if (`object` != other.`object`) return false + if (to != other.to) return false + if (cc != other.cc) return false + if (name != other.name) 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 + (`object`?.hashCode() ?: 0) + result = 31 * result + to.hashCode() + result = 31 * result + cc.hashCode() + result = 31 * result + name.hashCode() + result = 31 * result + actor.hashCode() + result = 31 * result + id.hashCode() return result } - override fun toString(): String = "Create(`object`=$`object`) ${super.toString()}" + override fun toString(): String = + "Create(`object`=$`object`, to=$to, cc=$cc, name='$name', actor='$actor', id='$id') ${super.toString()}" } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Delete.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Delete.kt index e29e9a93..5b867818 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Delete.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Delete.kt @@ -4,33 +4,42 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer -open class Delete : Object { +open class Delete : Object, HasId, HasActor, HasName { @JsonDeserialize(using = ObjectDeserializer::class) @Suppress("VariableNaming") var `object`: Object? = null var published: String? = null + override val actor: String + override val id: String + override val name: String constructor( type: List = emptyList(), - name: String? = "Delete", + name: String = "Delete", actor: String, id: String, `object`: Object, published: String? - ) : super(add(type, "Delete"), name, actor, id) { + ) : super(add(type, "Delete")) { this.`object` = `object` this.published = published + this.name = name + this.actor = actor + this.id = id } - protected constructor() : super() - override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is Delete) return false + if (javaClass != other?.javaClass) return false if (!super.equals(other)) return false + other as Delete + if (`object` != other.`object`) return false if (published != other.published) return false + if (actor != other.actor) return false + if (id != other.id) return false + if (name != other.name) return false return true } @@ -39,8 +48,12 @@ open class Delete : Object { var result = super.hashCode() result = 31 * result + (`object`?.hashCode() ?: 0) result = 31 * result + (published?.hashCode() ?: 0) + result = 31 * result + actor.hashCode() + result = 31 * result + id.hashCode() + result = 31 * result + name.hashCode() return result } - override fun toString(): String = "Delete(`object`=$`object`, published=$published) ${super.toString()}" + override fun toString(): String = + "Delete(`object`=$`object`, published=$published, actor='$actor', id='$id', name='$name') ${super.toString()}" } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt index d4f70180..489029d0 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt @@ -2,34 +2,35 @@ package dev.usbharu.hideout.activitypub.domain.model import dev.usbharu.hideout.activitypub.domain.model.objects.Object -open class Document : Object { +open class Document : Object, HasName { var mediaType: String? = null var url: String? = null + override val name: String - protected constructor() : super() constructor( type: List = emptyList(), - name: String? = null, + name: String, mediaType: String, url: String ) : super( - type = add(type, "Document"), - name = name, - actor = null, - id = null + type = add(type, "Document") ) { this.mediaType = mediaType this.url = url + this.name = name } override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is Document) return false + 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 } @@ -38,8 +39,9 @@ open class Document : Object { var result = super.hashCode() result = 31 * result + (mediaType?.hashCode() ?: 0) result = 31 * result + (url?.hashCode() ?: 0) + result = 31 * result + name.hashCode() return result } - override fun toString(): String = "Document(mediaType=$mediaType, url=$url) ${super.toString()}" + override fun toString(): String = "Document(mediaType=$mediaType, url=$url, name='$name') ${super.toString()}" } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt index cce3ee87..c270be48 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt @@ -15,10 +15,7 @@ open class Emoji : Object { updated: String?, icon: Image? ) : super( - type = add(type, "Emoji"), - name = name, - actor = actor, - id = id + type = add(type, "Emoji") ) { this.updated = updated this.icon = icon diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt index 00e3eec0..73ff75f3 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt @@ -2,37 +2,42 @@ package dev.usbharu.hideout.activitypub.domain.model import dev.usbharu.hideout.activitypub.domain.model.objects.Object -open class Follow : Object { +open class Follow : Object, HasActor { @Suppress("VariableNaming") var `object`: String? = null - protected constructor() : super() + override val actor: String + constructor( type: List = emptyList(), - name: String?, `object`: String?, - actor: String? + actor: String ) : super( - type = add(type, "Follow"), - name = name, - actor = actor + type = add(type, "Follow") ) { this.`object` = `object` + this.actor = actor } override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is Follow) return false + if (javaClass != other?.javaClass) return false if (!super.equals(other)) return false - return `object` == other.`object` + other as Follow + + if (`object` != other.`object`) return false + if (actor != other.actor) return false + + return true } override fun hashCode(): Int { var result = super.hashCode() result = 31 * result + (`object`?.hashCode() ?: 0) + result = 31 * result + actor.hashCode() return result } - override fun toString(): String = "Follow(`object`=$`object`) ${super.toString()}" + override fun toString(): String = "Follow(`object`=$`object`, actor='$actor') ${super.toString()}" } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasActor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasActor.kt new file mode 100644 index 00000000..c9bc4f91 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasActor.kt @@ -0,0 +1,5 @@ +package dev.usbharu.hideout.activitypub.domain.model + +interface HasActor { + val actor: String +} diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasId.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasId.kt new file mode 100644 index 00000000..774032c8 --- /dev/null +++ b/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/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasName.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasName.kt new file mode 100644 index 00000000..b8e4de76 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasName.kt @@ -0,0 +1,5 @@ +package dev.usbharu.hideout.activitypub.domain.model + +interface HasName { + val name: String +} diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt index f177c8a0..60b0c8ac 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt @@ -7,9 +7,8 @@ open class Image : Object { private var url: String? = null protected constructor() : super() - constructor(type: List = emptyList(), name: String, mediaType: String?, url: String?) : super( - add(type, "Image"), - name + constructor(type: List = emptyList(), mediaType: String?, url: String?) : super( + add(type, "Image") ) { this.mediaType = mediaType this.url = url @@ -17,11 +16,15 @@ open class Image : Object { override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is Image) return false + if (javaClass != other?.javaClass) return false if (!super.equals(other)) return false + other as Image + if (mediaType != other.mediaType) return false - return url == other.url + if (url != other.url) return false + + return true } override fun hashCode(): Int { @@ -30,4 +33,6 @@ open class Image : Object { result = 31 * result + (url?.hashCode() ?: 0) return result } + + override fun toString(): String = "Image(mediaType=$mediaType, url=$url) ${super.toString()}" } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Key.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Key.kt index 5cc33766..993d4af9 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Key.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Key.kt @@ -2,41 +2,45 @@ package dev.usbharu.hideout.activitypub.domain.model import dev.usbharu.hideout.activitypub.domain.model.objects.Object -open class Key : Object { +open class Key : Object, HasId { var owner: String? = null var publicKeyPem: String? = null + override val id: String - protected constructor() : super() constructor( type: List, - name: String, id: String, owner: String?, publicKeyPem: String? ) : super( - type = add(list = type, type = "Key"), - name = name, - id = id + type = add(list = type, type = "Key") ) { this.owner = owner this.publicKeyPem = publicKeyPem + this.id = id } override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is Key) return false + if (javaClass != other?.javaClass) return false if (!super.equals(other)) return false + other as Key + if (owner != other.owner) return false - return publicKeyPem == other.publicKeyPem + 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() ?: 0) result = 31 * result + (publicKeyPem?.hashCode() ?: 0) + result = 31 * result + id.hashCode() return result } - override fun toString(): String = "Key(owner=$owner, publicKeyPem=$publicKeyPem) ${super.toString()}" + override fun toString(): String = "Key(owner=$owner, publicKeyPem=$publicKeyPem, id='$id') ${super.toString()}" } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Like.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Like.kt index c916f566..2400eeff 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Like.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Like.kt @@ -4,42 +4,47 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer -open class Like : Object { +open class Like : Object, HasId, HasActor { @Suppress("VariableNaming") var `object`: String? = null var content: String? = null @JsonDeserialize(contentUsing = ObjectDeserializer::class) var tag: List = emptyList() + override val actor: String + override val id: String - protected constructor() : super() constructor( type: List = emptyList(), - name: String?, - actor: String?, - id: String?, + actor: String, + id: String, `object`: String?, content: String?, tag: List = emptyList() ) : super( - type = add(type, "Like"), - name = name, - actor = actor, - id = id + type = add(type, "Like") ) { this.`object` = `object` this.content = content this.tag = tag + this.actor = actor + this.id = id } override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is Like) return false + if (javaClass != other?.javaClass) return false if (!super.equals(other)) return false + other as Like + if (`object` != other.`object`) return false if (content != other.content) return false - return tag == other.tag + if (tag != other.tag) return false + if (actor != other.actor) return false + if (id != other.id) return false + + return true } override fun hashCode(): Int { @@ -47,8 +52,12 @@ open class Like : Object { result = 31 * result + (`object`?.hashCode() ?: 0) result = 31 * result + (content?.hashCode() ?: 0) result = 31 * result + tag.hashCode() + result = 31 * result + actor.hashCode() + result = 31 * result + id.hashCode() return result } - override fun toString(): String = "Like(`object`=$`object`, content=$content, tag=$tag) ${super.toString()}" + override fun toString(): String { + return "Like(`object`=$`object`, content=$content, tag=$tag, actor='$actor', id='$id') ${super.toString()}" + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt index cc891c08..74d5ce7a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt @@ -2,79 +2,58 @@ package dev.usbharu.hideout.activitypub.domain.model import dev.usbharu.hideout.activitypub.domain.model.objects.Object -open class Note : Object { - lateinit var attributedTo: String +open class Note +@Suppress("LongParameterList") +constructor( + type: List = emptyList(), + override val id: String, + var attributedTo: String, + var content: String, + var published: String, + var to: List = emptyList(), + var cc: List = emptyList(), + var sensitive: Boolean = false, + var inReplyTo: String? = null, var attachment: List = emptyList() - lateinit var content: String - lateinit var published: String - var to: List = emptyList() - var cc: List = emptyList() - var sensitive: Boolean = false - var inReplyTo: String? = null - - protected constructor() : super() - - @Suppress("LongParameterList") - constructor( - type: List = emptyList(), - name: String, - id: String?, - attributedTo: String, - content: String, - published: String, - to: List = emptyList(), - cc: List = emptyList(), - sensitive: Boolean = false, - inReplyTo: String? = null, - attachment: List = emptyList() - ) : super( - type = add(type, "Note"), - name = name, - id = id - ) { - this.attributedTo = attributedTo - this.content = content - this.published = published - this.to = to - this.cc = cc - this.sensitive = sensitive - this.inReplyTo = inReplyTo - this.attachment = attachment - } +) : Object( + type = add(type, "Note") +), + HasId { override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is Note) return false + 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 (attachment != other.attachment) 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 return true } override fun hashCode(): Int { var result = super.hashCode() - result = 31 * result + (attributedTo?.hashCode() ?: 0) - result = 31 * result + attachment.hashCode() - result = 31 * result + (content?.hashCode() ?: 0) - result = 31 * result + (published?.hashCode() ?: 0) + 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() return result } - override fun toString(): String { - return "Note(attributedTo=$attributedTo, attachment=$attachment, " + - "content=$content, published=$published, to=$to, cc=$cc, sensitive=$sensitive," + - " inReplyTo=$inReplyTo) ${super.toString()}" - } + override fun toString(): String = + "Note(id='$id', attributedTo='$attributedTo', content='$content', published='$published', to=$to, cc=$cc, sensitive=$sensitive, inReplyTo=$inReplyTo, attachment=$attachment) ${super.toString()}" } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt index 7ee0075e..e94cc9b1 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt @@ -2,47 +2,23 @@ package dev.usbharu.hideout.activitypub.domain.model import dev.usbharu.hideout.activitypub.domain.model.objects.Object -open class Person : Object { - var preferredUsername: String? = null - var summary: String? = null - var inbox: String? = null - var outbox: String? = null - var url: String? = null - private var icon: Image? = null - var publicKey: Key? = null - var endpoints: Map = emptyMap() - var following: String? = null - var followers: String? = null - - protected constructor() : super() - - @Suppress("LongParameterList") - constructor( - type: List = emptyList(), - name: String, - id: String?, - preferredUsername: String?, - summary: String?, - inbox: String?, - outbox: String?, - url: String?, - icon: Image?, - publicKey: Key?, - endpoints: Map = emptyMap(), - followers: String?, - following: String? - ) : super(add(type, "Person"), name, id = id) { - this.preferredUsername = preferredUsername - this.summary = summary - this.inbox = inbox - this.outbox = outbox - this.url = url - this.icon = icon - this.publicKey = publicKey - this.endpoints = endpoints - this.followers = followers - this.following = following - } +open class Person +@Suppress("LongParameterList") +constructor( + type: List = emptyList(), + override 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? +) : Object(add(type, "Person")), HasId, HasName { override fun equals(other: Any?): Boolean { if (this === other) return true diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Tombstone.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Tombstone.kt index 0017eac4..201eba32 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Tombstone.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Tombstone.kt @@ -2,11 +2,24 @@ package dev.usbharu.hideout.activitypub.domain.model import dev.usbharu.hideout.activitypub.domain.model.objects.Object -open class Tombstone : Object { - constructor( - type: List = emptyList(), - name: String = "Tombstone", - actor: String? = null, - id: String - ) : super(add(type, "Tombstone"), name, actor, id) +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/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt index a8fbb65a..f1a0d9d6 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt @@ -5,41 +5,53 @@ import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer import java.time.Instant -open class Undo : Object { +open class Undo : Object, HasId, HasActor { @JsonDeserialize(using = ObjectDeserializer::class) @Suppress("VariableNaming") var `object`: Object? = null var published: String? = null + override val actor: String + override val id: String - protected constructor() : super() constructor( type: List = emptyList(), - name: String, actor: String, - id: String?, + id: String, `object`: Object, published: Instant - ) : super(add(type, "Undo"), name, actor, id) { + ) : super(add(type, "Undo")) { this.`object` = `object` this.published = published.toString() + this.id = id + this.actor = actor } override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is Undo) return false + if (javaClass != other?.javaClass) return false if (!super.equals(other)) return false + other as Undo + if (`object` != other.`object`) return false - return published == other.published + 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 + (`object`?.hashCode() ?: 0) result = 31 * result + (published?.hashCode() ?: 0) + result = 31 * result + actor.hashCode() + result = 31 * result + id.hashCode() return result } - override fun toString(): String = "Undo(`object`=$`object`, published=$published) ${super.toString()}" + override fun toString(): String { + return "Undo(`object`=$`object`, published=$published, actor='$actor', id='$id') ${super.toString()}" + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/Object.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/Object.kt index 23f26eac..cafdb44d 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/Object.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/Object.kt @@ -12,41 +12,29 @@ open class Object : JsonLd { set(value) { field = value.filter { it.isNotBlank() } } - var name: String? = null - var actor: String? = null - var id: String? = null protected constructor() - constructor(type: List, name: String? = null, actor: String? = null, id: String? = null) : super() { + constructor(type: List) : super() { this.type = type.filter { it.isNotBlank() } - this.name = name - this.actor = actor - this.id = id } override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is Object) return false + if (javaClass != other?.javaClass) return false if (!super.equals(other)) return false - if (type != other.type) return false - if (name != other.name) return false - if (actor != other.actor) return false - if (id != other.id) return false + other as Object - return true + return type == other.type } override fun hashCode(): Int { var result = super.hashCode() result = 31 * result + type.hashCode() - result = 31 * result + (name?.hashCode() ?: 0) - result = 31 * result + (actor?.hashCode() ?: 0) - result = 31 * result + (id?.hashCode() ?: 0) return result } - override fun toString(): String = "Object(type=$type, name=$name, actor=$actor, id=$id) ${super.toString()}" + override fun toString(): String = "Object(type=$type) ${super.toString()}" companion object { @JvmStatic diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectValue.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectValue.kt index b97b2541..2a9c8eef 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectValue.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectValue.kt @@ -1,16 +1,15 @@ package dev.usbharu.hideout.activitypub.domain.model.objects +import com.fasterxml.jackson.annotation.JsonCreator + @Suppress("VariableNaming") open class ObjectValue : Object { - var `object`: String? = null + lateinit var `object`: String - protected constructor() : super() - constructor(type: List, name: String?, actor: String?, id: String?, `object`: String?) : super( - type, - name, - actor, - id + @JsonCreator + constructor(type: List) : super( + type ) { this.`object` = `object` } From 2e1cee4e1af23a8fd9775878c49241f6ce646993 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Tue, 28 Nov 2023 11:58:30 +0900 Subject: [PATCH 3/7] =?UTF-8?q?refactor:=20POJO=E3=81=AE=E5=A4=89=E6=9B=B4?= =?UTF-8?q?=E3=82=92=E5=8F=8D=E6=98=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activitypub/domain/model/Delete.kt | 9 ++---- .../activitypub/domain/model/Document.kt | 28 +++++++----------- .../hideout/activitypub/domain/model/Emoji.kt | 29 +++++++------------ .../hideout/activitypub/domain/model/Undo.kt | 5 ++-- .../model/objects/ObjectDeserializer.kt | 3 -- .../domain/model/objects/ObjectValue.kt | 21 +++++--------- .../exposedquery/NoteQueryServiceImpl.kt | 1 - .../activity/delete/APDeleteProcessor.kt | 7 ++++- .../activity/follow/APSendFollowService.kt | 1 - .../activity/like/ApReactionJobProcessor.kt | 1 - .../like/ApRemoveReactionJobProcessor.kt | 3 +- .../service/objects/user/APUserService.kt | 4 --- .../application/config/ActivityPubConfig.kt | 1 + .../domain/model/DeleteSerializeTest.kt | 4 +-- .../domain/model/NoteSerializeTest.kt | 5 +--- .../activitypub/domain/model/UndoTest.kt | 10 +++---- .../model/objects/ObjectSerializeTest.kt | 15 ++-------- .../api/actor/UserAPControllerImplTest.kt | 2 -- .../api/note/NoteApControllerImplTest.kt | 2 -- .../create/ApSendCreateServiceImplTest.kt | 1 - .../follow/APSendFollowServiceImplTest.kt | 1 - .../common/APRequestServiceImplTest.kt | 14 ++------- .../objects/note/APNoteServiceImplTest.kt | 11 ++----- .../hideout/ap/ContextSerializerTest.kt | 1 - 24 files changed, 56 insertions(+), 123 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Delete.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Delete.kt index 5b867818..10b919c5 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Delete.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Delete.kt @@ -4,18 +4,16 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer -open class Delete : Object, HasId, HasActor, HasName { +open class Delete : Object, HasId, HasActor { @JsonDeserialize(using = ObjectDeserializer::class) @Suppress("VariableNaming") var `object`: Object? = null var published: String? = null override val actor: String override val id: String - override val name: String constructor( type: List = emptyList(), - name: String = "Delete", actor: String, id: String, `object`: Object, @@ -23,7 +21,6 @@ open class Delete : Object, HasId, HasActor, HasName { ) : super(add(type, "Delete")) { this.`object` = `object` this.published = published - this.name = name this.actor = actor this.id = id } @@ -39,7 +36,6 @@ open class Delete : Object, HasId, HasActor, HasName { if (published != other.published) return false if (actor != other.actor) return false if (id != other.id) return false - if (name != other.name) return false return true } @@ -50,10 +46,9 @@ open class Delete : Object, HasId, HasActor, HasName { result = 31 * result + (published?.hashCode() ?: 0) result = 31 * result + actor.hashCode() result = 31 * result + id.hashCode() - result = 31 * result + name.hashCode() return result } override fun toString(): String = - "Delete(`object`=$`object`, published=$published, actor='$actor', id='$id', name='$name') ${super.toString()}" + "Delete(`object`=$`object`, published=$published, actor='$actor', id='$id') ${super.toString()}" } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt index 489029d0..480c6011 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt @@ -2,24 +2,18 @@ package dev.usbharu.hideout.activitypub.domain.model import dev.usbharu.hideout.activitypub.domain.model.objects.Object -open class Document : Object, HasName { +open class Document( + type: List = emptyList(), + override val name: String = "", + mediaType: String, + url: String +) : Object( + type = add(type, "Document") +), + HasName { - var mediaType: String? = null - var url: String? = null - override val name: String - - constructor( - type: List = emptyList(), - name: String, - mediaType: String, - url: String - ) : super( - type = add(type, "Document") - ) { - this.mediaType = mediaType - this.url = url - this.name = name - } + var mediaType: String? = mediaType + var url: String? = url override fun equals(other: Any?): Boolean { if (this === other) return true diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt index c270be48..0a91be60 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt @@ -2,24 +2,17 @@ package dev.usbharu.hideout.activitypub.domain.model import dev.usbharu.hideout.activitypub.domain.model.objects.Object -open class Emoji : Object { - var updated: String? = null - var icon: Image? = null - - protected constructor() : super() - constructor( - type: List, - name: String?, - actor: String?, - id: String?, - updated: String?, - icon: Image? - ) : super( - type = add(type, "Emoji") - ) { - this.updated = updated - this.icon = icon - } +open class Emoji( + type: List, + override val name: String, + override val id: String, + var updated: String?, + var icon: Image? +) : Object( + type = add(type, "Emoji") +), + HasName, + HasId { override fun equals(other: Any?): Boolean { if (this === other) return true diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt index f1a0d9d6..857416ef 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt @@ -3,7 +3,6 @@ package dev.usbharu.hideout.activitypub.domain.model import com.fasterxml.jackson.databind.annotation.JsonDeserialize import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer -import java.time.Instant open class Undo : Object, HasId, HasActor { @@ -19,10 +18,10 @@ open class Undo : Object, HasId, HasActor { actor: String, id: String, `object`: Object, - published: Instant + published: String ) : super(add(type, "Undo")) { this.`object` = `object` - this.published = published.toString() + this.published = published this.id = id this.actor = actor } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectDeserializer.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectDeserializer.kt index acbf32e5..f28070e6 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectDeserializer.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectDeserializer.kt @@ -15,9 +15,6 @@ class ObjectDeserializer : JsonDeserializer() { if (treeNode.isValueNode) { return ObjectValue( emptyList(), - null, - null, - null, treeNode.asText() ) } else if (treeNode.isObject) { diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectValue.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectValue.kt index 2a9c8eef..62ed4344 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectValue.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectValue.kt @@ -3,30 +3,25 @@ package dev.usbharu.hideout.activitypub.domain.model.objects import com.fasterxml.jackson.annotation.JsonCreator @Suppress("VariableNaming") -open class ObjectValue : Object { - - lateinit var `object`: String - - @JsonCreator - constructor(type: List) : super( - type - ) { - this.`object` = `object` - } +open class ObjectValue @JsonCreator constructor(type: List, var `object`: String) : Object( + type +) { override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is ObjectValue) return false + 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() ?: 0) + result = 31 * result + `object`.hashCode() return result } - override fun toString(): String = "ObjectValue(`object`=$`object`) ${super.toString()}" + override fun toString(): String = "ObjectValue(`object`='$`object`') ${super.toString()}" } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/infrastructure/exposedquery/NoteQueryServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/infrastructure/exposedquery/NoteQueryServiceImpl.kt index 3348f832..561b8de2 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/infrastructure/exposedquery/NoteQueryServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/infrastructure/exposedquery/NoteQueryServiceImpl.kt @@ -64,7 +64,6 @@ class NoteQueryServiceImpl(private val postRepository: PostRepository, private v this[Users.followers] ) return Note( - name = "Post", id = this[Posts.apId], attributedTo = this[Users.url], content = this[Posts.text], diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/delete/APDeleteProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/delete/APDeleteProcessor.kt index 060dc713..f6f136fa 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/delete/APDeleteProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/delete/APDeleteProcessor.kt @@ -2,6 +2,7 @@ package dev.usbharu.hideout.activitypub.service.activity.delete import dev.usbharu.hideout.activitypub.domain.exception.IllegalActivityPubObjectException import dev.usbharu.hideout.activitypub.domain.model.Delete +import dev.usbharu.hideout.activitypub.domain.model.HasId import dev.usbharu.hideout.activitypub.service.common.AbstractActivityPubProcessor import dev.usbharu.hideout.activitypub.service.common.ActivityPubProcessContext import dev.usbharu.hideout.activitypub.service.common.ActivityType @@ -17,7 +18,11 @@ class APDeleteProcessor( ) : AbstractActivityPubProcessor(transaction) { override suspend fun internalProcess(activity: ActivityPubProcessContext) { - val deleteId = activity.activity.`object`?.id ?: throw IllegalActivityPubObjectException("object.id is null") + val value = activity.activity.`object` + if (value !is HasId) { + throw IllegalActivityPubObjectException("object hasn't id") + } + val deleteId = value.id val post = try { postQueryService.findByApId(deleteId) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APSendFollowService.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APSendFollowService.kt index e71e7c79..554fa571 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APSendFollowService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APSendFollowService.kt @@ -15,7 +15,6 @@ class APSendFollowServiceImpl( ) : APSendFollowService { override suspend fun sendFollow(sendFollowDto: SendFollowDto) { val follow = Follow( - name = "Follow", `object` = sendFollowDto.followTargetUserId.url, actor = sendFollowDto.userId.url ) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApReactionJobProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApReactionJobProcessor.kt index af3f2f09..3f73bb2e 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApReactionJobProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApReactionJobProcessor.kt @@ -21,7 +21,6 @@ class ApReactionJobProcessor( apRequestService.apPost( param.inbox, Like( - name = "Like", actor = param.actor, `object` = param.postUrl, id = "${applicationConfig.url}/liek/note/${param.id}", diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApRemoveReactionJobProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApRemoveReactionJobProcessor.kt index 307f0c16..6a873aca 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApRemoveReactionJobProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApRemoveReactionJobProcessor.kt @@ -28,11 +28,10 @@ class ApRemoveReactionJobProcessor( apRequestService.apPost( param.inbox, Undo( - name = "Undo Reaction", actor = param.actor, `object` = like, id = "${applicationConfig.url}/undo/like/${param.id}", - published = Instant.now() + published = Instant.now().toString() ), signer ) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/user/APUserService.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/user/APUserService.kt index d69eb9d6..31a2b505 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/user/APUserService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/user/APUserService.kt @@ -57,13 +57,11 @@ class APUserServiceImpl( url = userUrl, icon = Image( type = emptyList(), - name = "$userUrl/icon.png", mediaType = "image/png", url = "$userUrl/icon.png" ), publicKey = Key( type = emptyList(), - name = "Public Key", id = userEntity.keyId, owner = userUrl, publicKeyPem = userEntity.publicKey @@ -127,13 +125,11 @@ class APUserServiceImpl( url = id, icon = Image( type = emptyList(), - name = "$id/icon.png", mediaType = "image/png", url = "$id/icon.png" ), publicKey = Key( type = emptyList(), - name = "Public Key", id = userEntity.keyId, owner = id, publicKeyPem = userEntity.publicKey diff --git a/src/main/kotlin/dev/usbharu/hideout/application/config/ActivityPubConfig.kt b/src/main/kotlin/dev/usbharu/hideout/application/config/ActivityPubConfig.kt index d6bdf301..d661a30a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/application/config/ActivityPubConfig.kt +++ b/src/main/kotlin/dev/usbharu/hideout/application/config/ActivityPubConfig.kt @@ -25,6 +25,7 @@ class ActivityPubConfig { .enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY) .setSerializationInclusion(JsonInclude.Include.NON_EMPTY) .setDefaultSetterInfo(JsonSetter.Value.forContentNulls(Nulls.AS_EMPTY)) + .setDefaultSetterInfo(JsonSetter.Value.forValueNulls(Nulls.AS_EMPTY)) .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) .configure(JsonParser.Feature.ALLOW_COMMENTS, true) .configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true) diff --git a/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/DeleteSerializeTest.kt b/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/DeleteSerializeTest.kt index 4f190250..21de8c61 100644 --- a/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/DeleteSerializeTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/DeleteSerializeTest.kt @@ -46,7 +46,6 @@ class DeleteSerializeTest { val readValue = objectMapper.readValue(json) val expected = Delete( - name = null, actor = "https://misskey.usbharu.dev/users/97ws8y3rj6", id = "https://misskey.usbharu.dev/4b5b6ed5-9269-45f3-8403-cba1e74b4b69", `object` = Tombstone( @@ -61,7 +60,6 @@ class DeleteSerializeTest { @Test fun シリアライズできる() { val delete = Delete( - name = null, actor = "https://misskey.usbharu.dev/users/97ws8y3rj6", id = "https://misskey.usbharu.dev/4b5b6ed5-9269-45f3-8403-cba1e74b4b69", `object` = Tombstone( @@ -75,7 +73,7 @@ class DeleteSerializeTest { val actual = objectMapper.writeValueAsString(delete) val expected = - """{"type":"Delete","actor":"https://misskey.usbharu.dev/users/97ws8y3rj6","id":"https://misskey.usbharu.dev/4b5b6ed5-9269-45f3-8403-cba1e74b4b69","object":{"type":"Tombstone","name":"Tombstone","id":"https://misskey.usbharu.dev/notes/9lkwqnwqk9"},"published":"2023-11-02T15:30:34.160Z"}""" + """{"type":"Delete","actor":"https://misskey.usbharu.dev/users/97ws8y3rj6","id":"https://misskey.usbharu.dev/4b5b6ed5-9269-45f3-8403-cba1e74b4b69","object":{"type":"Tombstone","id":"https://misskey.usbharu.dev/notes/9lkwqnwqk9"},"published":"2023-11-02T15:30:34.160Z"}""" assertEquals(expected, actual) } } diff --git a/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/NoteSerializeTest.kt b/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/NoteSerializeTest.kt index 1b05eef1..9e1397a9 100644 --- a/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/NoteSerializeTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/NoteSerializeTest.kt @@ -10,7 +10,6 @@ class NoteSerializeTest { @Test fun Noteのシリアライズができる() { val note = Note( - name = "Note", id = "https://example.com", attributedTo = "https://example.com/actor", content = "Hello", @@ -22,7 +21,7 @@ class NoteSerializeTest { val writeValueAsString = objectMapper.writeValueAsString(note) assertEquals( - "{\"type\":\"Note\",\"name\":\"Note\",\"id\":\"https://example.com\",\"attributedTo\":\"https://example.com/actor\",\"content\":\"Hello\",\"published\":\"2023-05-20T10:28:17.308Z\",\"sensitive\":false}", + """{"type":"Note","id":"https://example.com","attributedTo":"https://example.com/actor","content":"Hello","published":"2023-05-20T10:28:17.308Z","sensitive":false}""", writeValueAsString ) } @@ -65,7 +64,6 @@ class NoteSerializeTest { val readValue = objectMapper.readValue(json) val note = Note( - name = "", id = "https://misskey.usbharu.dev/notes/9f2i9cm88e", type = listOf("Note"), attributedTo = "https://misskey.usbharu.dev/users/97ws8y3rj6", @@ -77,7 +75,6 @@ class NoteSerializeTest { inReplyTo = "https://calckey.jp/notes/9f2i7ymf1d", attachment = emptyList() ) - note.name = null assertEquals(note, readValue) } } diff --git a/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/UndoTest.kt b/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/UndoTest.kt index 97ba9bc4..ea279694 100644 --- a/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/UndoTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/UndoTest.kt @@ -1,8 +1,8 @@ package dev.usbharu.hideout.activitypub.domain.model +import dev.usbharu.hideout.application.config.ActivityPubConfig import org.intellij.lang.annotations.Language import org.junit.jupiter.api.Test -import utils.JsonObjectMapper import java.time.Clock import java.time.Instant import java.time.ZoneId @@ -12,18 +12,16 @@ class UndoTest { fun Undoのシリアライズができる() { val undo = Undo( emptyList(), - "Undo Follow", "https://follower.example.com/", "https://follower.example.com/undo/1", Follow( emptyList(), - null, "https://follower.example.com/users/", actor = "https://follower.exaple.com/users/1" ), - Instant.now(Clock.tickMillis(ZoneId.systemDefault())) + Instant.now(Clock.tickMillis(ZoneId.systemDefault())).toString() ) - val writeValueAsString = JsonObjectMapper.objectMapper.writeValueAsString(undo) + val writeValueAsString = ActivityPubConfig().objectMapper().writeValueAsString(undo) println(writeValueAsString) } @@ -70,7 +68,7 @@ class UndoTest { """.trimIndent() - val undo = JsonObjectMapper.objectMapper.readValue(json, Undo::class.java) + val undo = ActivityPubConfig().objectMapper().readValue(json, Undo::class.java) println(undo) } } diff --git a/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectSerializeTest.kt b/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectSerializeTest.kt index 77f2579b..41bc114e 100644 --- a/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectSerializeTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectSerializeTest.kt @@ -16,10 +16,7 @@ class ObjectSerializeTest { val readValue = objectMapper.readValue(json) val expected = Object( - listOf("Object"), - null, - null, - null + listOf("Object") ) assertEquals(expected, readValue) } @@ -34,10 +31,7 @@ class ObjectSerializeTest { val readValue = objectMapper.readValue(json) val expected = Object( - listOf("Hoge", "Object"), - null, - null, - null + listOf("Hoge", "Object") ) assertEquals(expected, readValue) @@ -53,10 +47,7 @@ class ObjectSerializeTest { val readValue = objectMapper.readValue(json) val expected = Object( - emptyList(), - null, - null, - null + emptyList() ) assertEquals(expected, readValue) diff --git a/src/test/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/actor/UserAPControllerImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/actor/UserAPControllerImplTest.kt index 9520eac2..42f44e27 100644 --- a/src/test/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/actor/UserAPControllerImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/actor/UserAPControllerImplTest.kt @@ -49,12 +49,10 @@ class UserAPControllerImplTest { outbox = "https://example.com/users/hoge/outbox", url = "https://example.com/users/hoge", icon = Image( - name = "icon", mediaType = "image/jpeg", url = "https://example.com/users/hoge/icon.jpg" ), publicKey = Key( - name = "Public Key", id = "https://example.com/users/hoge#pubkey", owner = "https://example.com/users/hoge", publicKeyPem = "-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----", diff --git a/src/test/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/note/NoteApControllerImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/note/NoteApControllerImplTest.kt index c337e770..bfa7168e 100644 --- a/src/test/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/note/NoteApControllerImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/note/NoteApControllerImplTest.kt @@ -53,7 +53,6 @@ class NoteApControllerImplTest { fun `postAP 匿名で取得できる`() = runTest { SecurityContextHolder.clearContext() val note = Note( - name = "Note", id = "https://example.com/users/hoge/posts/1234", attributedTo = "https://example.com/users/hoge", content = "Hello", @@ -90,7 +89,6 @@ class NoteApControllerImplTest { @Test fun `postAP 認証に成功している場合userIdがnullでない`() = runTest { val note = Note( - name = "Note", id = "https://example.com/users/hoge/posts/1234", attributedTo = "https://example.com/users/hoge", content = "Hello", diff --git a/src/test/kotlin/dev/usbharu/hideout/activitypub/service/activity/create/ApSendCreateServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/activitypub/service/activity/create/ApSendCreateServiceImplTest.kt index 47b5671e..01975882 100644 --- a/src/test/kotlin/dev/usbharu/hideout/activitypub/service/activity/create/ApSendCreateServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/activitypub/service/activity/create/ApSendCreateServiceImplTest.kt @@ -52,7 +52,6 @@ class ApSendCreateServiceImplTest { val post = PostBuilder.of() val user = UserBuilder.localUserOf(id = post.userId) val note = Note( - name = "Post", id = post.apId, attributedTo = user.url, content = post.text, diff --git a/src/test/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APSendFollowServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APSendFollowServiceImplTest.kt index 6ce3a084..93e1d76d 100644 --- a/src/test/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APSendFollowServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APSendFollowServiceImplTest.kt @@ -24,7 +24,6 @@ class APSendFollowServiceImplTest { apSendFollowServiceImpl.sendFollow(sendFollowDto) val value = Follow( - name = "Follow", `object` = sendFollowDto.followTargetUserId.url, actor = sendFollowDto.userId.url ) diff --git a/src/test/kotlin/dev/usbharu/hideout/activitypub/service/common/APRequestServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/activitypub/service/common/APRequestServiceImplTest.kt index ec36d233..2c609183 100644 --- a/src/test/kotlin/dev/usbharu/hideout/activitypub/service/common/APRequestServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/activitypub/service/common/APRequestServiceImplTest.kt @@ -39,7 +39,7 @@ class APRequestServiceImplTest { assertDoesNotThrow { dateTimeFormatter.parse(it.headers["Date"]) } - respond("{}") + respond("""{"type":"Follow","object": "https://example.com","actor": "https://example.com"}""") }), objectMapper, mock(), @@ -47,7 +47,6 @@ class APRequestServiceImplTest { ) val responseClass = Follow( - name = "Follow", `object` = "https://example.com", actor = "https://example.com" ) @@ -65,7 +64,7 @@ class APRequestServiceImplTest { assertDoesNotThrow { dateTimeFormatter.parse(it.headers["Date"]) } - respond("{}") + respond("""{"type":"Follow","object": "https://example.com","actor": "https://example.com"}""") }), objectMapper, mock(), @@ -73,7 +72,6 @@ class APRequestServiceImplTest { ) val responseClass = Follow( - name = "Follow", `object` = "https://example.com", actor = "https://example.com" ) @@ -106,7 +104,7 @@ class APRequestServiceImplTest { assertDoesNotThrow { dateTimeFormatter.parse(it.headers["Date"]) } - respond("{}") + respond("""{"type":"Follow","object": "https://example.com","actor": "https://example.com"}""") }), objectMapper, httpSignatureSigner, @@ -114,7 +112,6 @@ class APRequestServiceImplTest { ) val responseClass = Follow( - name = "Follow", `object` = "https://example.com", actor = "https://example.com" ) @@ -166,7 +163,6 @@ class APRequestServiceImplTest { }), objectMapper, mock(), dateTimeFormatter) val body = Follow( - name = "Follow", `object` = "https://example.com", actor = "https://example.com" ) @@ -213,7 +209,6 @@ class APRequestServiceImplTest { }), objectMapper, mock(), dateTimeFormatter) val body = Follow( - name = "Follow", `object` = "https://example.com", actor = "https://example.com" ) @@ -244,7 +239,6 @@ class APRequestServiceImplTest { }), objectMapper, mock(), dateTimeFormatter) val body = Follow( - name = "Follow", `object` = "https://example.com", actor = "https://example.com" ) @@ -286,7 +280,6 @@ class APRequestServiceImplTest { }), objectMapper, httpSignatureSigner, dateTimeFormatter) val body = Follow( - name = "Follow", `object` = "https://example.com", actor = "https://example.com" ) @@ -337,7 +330,6 @@ class APRequestServiceImplTest { }), objectMapper, mock(), dateTimeFormatter) val body = Follow( - name = "Follow", `object` = "https://example.com", actor = "https://example.com" ) diff --git a/src/test/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/APNoteServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/APNoteServiceImplTest.kt index 540f642c..5ed6597d 100644 --- a/src/test/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/APNoteServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/APNoteServiceImplTest.kt @@ -56,7 +56,6 @@ class APNoteServiceImplTest { onBlocking { findById(eq(post.userId)) } doReturn user } val expected = Note( - name = "Post", id = post.apId, attributedTo = user.url, content = post.text, @@ -98,7 +97,6 @@ class APNoteServiceImplTest { onBlocking { findById(eq(post.userId)) } doReturn user } val note = Note( - name = "Post", id = post.apId, attributedTo = user.url, content = post.text, @@ -124,13 +122,11 @@ class APNoteServiceImplTest { url = user.url, icon = Image( type = emptyList(), - name = user.url + "/icon.png", mediaType = "image/png", url = user.url + "/icon.png" ), publicKey = Key( type = emptyList(), - name = "Public Key", id = user.keyId, owner = user.url, publicKeyPem = user.publicKey @@ -177,7 +173,6 @@ class APNoteServiceImplTest { onBlocking { findById(eq(post.userId)) } doReturn user } val note = Note( - name = "Post", id = post.apId, attributedTo = user.url, content = post.text, @@ -246,11 +241,11 @@ class APNoteServiceImplTest { outbox = user.outbox, url = user.url, icon = Image( - name = user.url + "/icon.png", mediaType = "image/png", url = user.url + "/icon.png" + mediaType = "image/png", + url = user.url + "/icon.png" ), publicKey = Key( type = emptyList(), - name = "Public Key", id = user.keyId, owner = user.url, publicKeyPem = user.publicKey @@ -278,7 +273,6 @@ class APNoteServiceImplTest { ) val note = Note( - name = "Post", id = post.apId, attributedTo = user.url, content = post.text, @@ -311,7 +305,6 @@ class APNoteServiceImplTest { onBlocking { findById(eq(user.id)) } doReturn user } val note = Note( - name = "Post", id = post.apId, attributedTo = user.url, content = post.text, diff --git a/src/test/kotlin/dev/usbharu/hideout/ap/ContextSerializerTest.kt b/src/test/kotlin/dev/usbharu/hideout/ap/ContextSerializerTest.kt index db434005..d73e31d7 100644 --- a/src/test/kotlin/dev/usbharu/hideout/ap/ContextSerializerTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/ap/ContextSerializerTest.kt @@ -13,7 +13,6 @@ class ContextSerializerTest { name = "aaa", actor = "bbb", `object` = Follow( - name = "ccc", `object` = "ddd", actor = "aaa" ) From 4542fdf68b4e18c57d71e8169ce0ba0a9cddea9b Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Tue, 28 Nov 2023 12:10:40 +0900 Subject: [PATCH 4/7] =?UTF-8?q?reafactor:=20=E3=81=9D=E3=81=AE=E4=BB=96?= =?UTF-8?q?=E3=81=AE=E9=83=A8=E5=88=86=E3=82=82Null-safe=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activitypub/domain/model/Accept.kt | 4 +- .../activitypub/domain/model/Create.kt | 6 +-- .../activitypub/domain/model/Delete.kt | 6 +-- .../activitypub/domain/model/Document.kt | 7 +--- .../hideout/activitypub/domain/model/Emoji.kt | 4 +- .../activitypub/domain/model/Follow.kt | 22 ++++------- .../hideout/activitypub/domain/model/Image.kt | 18 ++++----- .../hideout/activitypub/domain/model/Key.kt | 26 +++++-------- .../hideout/activitypub/domain/model/Like.kt | 38 ++++++------------- .../hideout/activitypub/domain/model/Note.kt | 16 ++++---- .../activitypub/domain/model/Person.kt | 6 +-- .../hideout/activitypub/domain/model/Undo.kt | 27 ++++--------- 12 files changed, 64 insertions(+), 116 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Accept.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Accept.kt index d1b0936b..15eaf20f 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Accept.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Accept.kt @@ -8,9 +8,7 @@ import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer open class Accept @JsonCreator constructor( type: List = emptyList(), override val name: String, - @JsonDeserialize(using = ObjectDeserializer::class) - @Suppress("VariableNaming") - var `object`: Object?, + @JsonDeserialize(using = ObjectDeserializer::class) @Suppress("VariableNaming") var `object`: Object?, override val actor: String ) : Object( type = add(type, "Accept") diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Create.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Create.kt index df22045c..6b6bb810 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Create.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Create.kt @@ -9,11 +9,11 @@ open class Create( override val name: String, @JsonDeserialize(using = ObjectDeserializer::class) @Suppress("VariableNaming") - var `object`: Object?, + val `object`: Object, override val actor: String, override val id: String, - var to: List = emptyList(), - var cc: List = emptyList() + val to: List = emptyList(), + val cc: List = emptyList() ) : Object( type = add(type, "Create") ), diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Delete.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Delete.kt index 10b919c5..e4e8ccb0 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Delete.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Delete.kt @@ -7,8 +7,8 @@ import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer open class Delete : Object, HasId, HasActor { @JsonDeserialize(using = ObjectDeserializer::class) @Suppress("VariableNaming") - var `object`: Object? = null - var published: String? = null + val `object`: Object + val published: String override val actor: String override val id: String @@ -17,7 +17,7 @@ open class Delete : Object, HasId, HasActor { actor: String, id: String, `object`: Object, - published: String? + published: String ) : super(add(type, "Delete")) { this.`object` = `object` this.published = published diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt index 480c6011..a9b3e8c9 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt @@ -5,16 +5,13 @@ import dev.usbharu.hideout.activitypub.domain.model.objects.Object open class Document( type: List = emptyList(), override val name: String = "", - mediaType: String, - url: String + val mediaType: String, + val url: String ) : Object( type = add(type, "Document") ), HasName { - var mediaType: String? = mediaType - var url: String? = url - override fun equals(other: Any?): Boolean { if (this === other) return true if (javaClass != other?.javaClass) return false diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt index 0a91be60..d46edc8a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt @@ -6,8 +6,8 @@ open class Emoji( type: List, override val name: String, override val id: String, - var updated: String?, - var icon: Image? + val updated: String, + val icon: Image ) : Object( type = add(type, "Emoji") ), diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt index 73ff75f3..2689ccb5 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt @@ -2,22 +2,14 @@ package dev.usbharu.hideout.activitypub.domain.model import dev.usbharu.hideout.activitypub.domain.model.objects.Object -open class Follow : Object, HasActor { - @Suppress("VariableNaming") - var `object`: String? = null - +open class Follow( + type: List = emptyList(), + @Suppress("VariableNaming") val `object`: String, override val actor: String - - constructor( - type: List = emptyList(), - `object`: String?, - actor: String - ) : super( - type = add(type, "Follow") - ) { - this.`object` = `object` - this.actor = actor - } +) : Object( + type = add(type, "Follow") +), + HasActor { override fun equals(other: Any?): Boolean { if (this === other) return true diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt index 60b0c8ac..6353692b 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt @@ -2,17 +2,13 @@ package dev.usbharu.hideout.activitypub.domain.model import dev.usbharu.hideout.activitypub.domain.model.objects.Object -open class Image : Object { - private var mediaType: String? = null - private var url: String? = null - - protected constructor() : super() - constructor(type: List = emptyList(), mediaType: String?, url: String?) : super( - add(type, "Image") - ) { - this.mediaType = mediaType - this.url = url - } +open class Image( + type: List = emptyList(), + val mediaType: String, + val url: String +) : Object( + add(type, "Image") +) { override fun equals(other: Any?): Boolean { if (this === other) return true diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Key.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Key.kt index 993d4af9..4a13ba56 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Key.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Key.kt @@ -2,23 +2,15 @@ package dev.usbharu.hideout.activitypub.domain.model import dev.usbharu.hideout.activitypub.domain.model.objects.Object -open class Key : Object, HasId { - var owner: String? = null - var publicKeyPem: String? = null - override val id: String - - constructor( - type: List, - id: String, - owner: String?, - publicKeyPem: String? - ) : super( - type = add(list = type, type = "Key") - ) { - this.owner = owner - this.publicKeyPem = publicKeyPem - this.id = id - } +open class Key( + type: List, + override val id: String, + val owner: String, + val publicKeyPem: String +) : Object( + type = add(list = type, type = "Key") +), + HasId { override fun equals(other: Any?): Boolean { if (this === other) return true diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Like.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Like.kt index 2400eeff..f4eaa13f 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Like.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Like.kt @@ -4,32 +4,18 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer -open class Like : Object, HasId, HasActor { - @Suppress("VariableNaming") - var `object`: String? = null - var content: String? = null - - @JsonDeserialize(contentUsing = ObjectDeserializer::class) - var tag: List = emptyList() - override val actor: String - override val id: String - - constructor( - type: List = emptyList(), - actor: String, - id: String, - `object`: String?, - content: String?, - tag: List = emptyList() - ) : super( - type = add(type, "Like") - ) { - this.`object` = `object` - this.content = content - this.tag = tag - this.actor = actor - this.id = id - } +open class Like( + type: List = emptyList(), + override val actor: String, + override val id: String, + @Suppress("VariableNaming") val `object`: 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 diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt index 74d5ce7a..889c8776 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt @@ -7,14 +7,14 @@ open class Note constructor( type: List = emptyList(), override val id: String, - var attributedTo: String, - var content: String, - var published: String, - var to: List = emptyList(), - var cc: List = emptyList(), - var sensitive: Boolean = false, - var inReplyTo: String? = null, - var attachment: List = emptyList() + 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() ) : Object( type = add(type, "Note") ), diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt index e94cc9b1..58165a81 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt @@ -10,9 +10,9 @@ constructor( override val id: String, var preferredUsername: String?, var summary: String?, - var inbox: String?, - var outbox: String?, - var url: String?, + var inbox: String, + var outbox: String, + var url: String, private var icon: Image?, var publicKey: Key?, var endpoints: Map = emptyMap(), diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt index 857416ef..d02ccc4d 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt @@ -4,27 +4,14 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer -open class Undo : Object, HasId, HasActor { - +open class Undo( + type: List = emptyList(), + override val actor: String, + override val id: String, @JsonDeserialize(using = ObjectDeserializer::class) - @Suppress("VariableNaming") - var `object`: Object? = null - var published: String? = null - override val actor: String - override val id: String - - constructor( - type: List = emptyList(), - actor: String, - id: String, - `object`: Object, - published: String - ) : super(add(type, "Undo")) { - this.`object` = `object` - this.published = published - this.id = id - this.actor = actor - } + @Suppress("VariableNaming") val `object`: Object, + val published: String +) : Object(add(type, "Undo")), HasId, HasActor { override fun equals(other: Any?): Boolean { if (this === other) return true From 34d8eabea1e39607e7ee9c2632a3ea7febc9d811 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Tue, 28 Nov 2023 12:28:32 +0900 Subject: [PATCH 5/7] =?UTF-8?q?refactor:=20=E4=B8=8D=E8=A6=81=E3=81=AA?= =?UTF-8?q?=E5=AE=A3=E8=A8=80=E7=AD=89=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/FailedProcessException.kt | 7 +++++ ...FailedToGetActivityPubResourceException.kt | 6 +++++ .../HttpSignatureUnauthorizedException.kt | 7 +++++ .../activitypub/domain/model/Document.kt | 4 +-- .../hideout/activitypub/domain/model/Emoji.kt | 4 +-- .../activitypub/domain/model/Follow.kt | 2 +- .../hideout/activitypub/domain/model/Image.kt | 4 +-- .../hideout/activitypub/domain/model/Key.kt | 4 +-- .../hideout/activitypub/domain/model/Note.kt | 16 +++++++++-- .../activitypub/domain/model/Person.kt | 6 ++--- .../activity/accept/ApAcceptProcessor.kt | 8 +++--- .../create/CreateActivityProcessor.kt | 2 +- .../activity/follow/APFollowProcessor.kt | 5 ++-- .../follow/APReceiveFollowJobProcessor.kt | 4 +-- .../service/activity/like/APLikeProcessor.kt | 7 +++-- .../service/activity/undo/APUndoProcessor.kt | 8 +++--- .../service/common/APRequestServiceImpl.kt | 14 +++++----- .../common/AbstractActivityPubProcessor.kt | 3 ++- .../service/objects/note/APNoteService.kt | 14 +++++----- .../service/objects/user/APUserService.kt | 8 +++--- .../exception/media/MediaConvertException.kt | 7 +++++ .../domain/exception/media/MediaException.kt | 7 +++++ .../exception/media/MediaFileSizeException.kt | 7 +++++ .../media/MediaFileSizeIsZeroException.kt | 7 +++++ .../exception/media/MediaProcessException.kt | 7 +++++ .../media/UnsupportedMediaException.kt | 7 +++++ .../core/domain/model/instance/Nodeinfo.kt | 8 ++---- .../core/domain/model/instance/Nodeinfo2_0.kt | 12 +++------ .../InstanceRepositoryImpl.kt | 2 +- .../ExposedOAuth2AuthorizationService.kt | 2 +- .../core/service/instance/InstanceService.kt | 4 +-- .../hideout/core/service/media/MediaSave.kt | 27 ++++++++++++++++++- .../core/service/media/MediaServiceImpl.kt | 2 +- .../core/service/media/ProcessedFile.kt | 20 +++++++++++++- .../service/reaction/ReactionServiceImpl.kt | 3 ++- .../service/resource/InMemoryCacheManager.kt | 2 +- .../core/service/user/UserServiceImpl.kt | 3 +-- .../JsonOrFormModelMethodProcessor.kt | 3 ++- .../exposedquery/StatusQueryServiceImpl.kt | 1 + .../service/media/MediaApiServiceImpl.kt | 1 - .../dev/usbharu/hideout/util/AcctUtil.kt | 2 +- .../dev/usbharu/hideout/util/HttpUtil.kt | 4 +-- 42 files changed, 189 insertions(+), 82 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/FailedProcessException.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/FailedProcessException.kt index 31c4b47e..144759d3 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/FailedProcessException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/FailedProcessException.kt @@ -1,5 +1,7 @@ package dev.usbharu.hideout.activitypub.domain.exception +import java.io.Serial + class FailedProcessException : RuntimeException { constructor() : super() constructor(message: String?) : super(message) @@ -11,4 +13,9 @@ class FailedProcessException : RuntimeException { enableSuppression, writableStackTrace ) + + companion object { + @Serial + private const val serialVersionUID: Long = -1305337651143409144L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/FailedToGetActivityPubResourceException.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/FailedToGetActivityPubResourceException.kt index e050e716..ed967555 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/FailedToGetActivityPubResourceException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/FailedToGetActivityPubResourceException.kt @@ -1,10 +1,16 @@ package dev.usbharu.hideout.activitypub.domain.exception import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException +import java.io.Serial class FailedToGetActivityPubResourceException : FailedToGetResourcesException { constructor() : super() constructor(s: String?) : super(s) constructor(message: String?, cause: Throwable?) : super(message, cause) constructor(cause: Throwable?) : super(cause) + + companion object { + @Serial + private const val serialVersionUID: Long = 6420233106776818052L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/HttpSignatureUnauthorizedException.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/HttpSignatureUnauthorizedException.kt index 9abccec6..3bba00ef 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/HttpSignatureUnauthorizedException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/HttpSignatureUnauthorizedException.kt @@ -1,5 +1,7 @@ package dev.usbharu.hideout.activitypub.domain.exception +import java.io.Serial + class HttpSignatureUnauthorizedException : RuntimeException { constructor() : super() constructor(message: String?) : super(message) @@ -11,4 +13,9 @@ class HttpSignatureUnauthorizedException : RuntimeException { enableSuppression, writableStackTrace ) + + companion object { + @Serial + private const val serialVersionUID: Long = -6449793151674654501L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt index a9b3e8c9..d8b7ff7e 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt @@ -28,8 +28,8 @@ open class Document( override fun hashCode(): Int { var result = super.hashCode() - result = 31 * result + (mediaType?.hashCode() ?: 0) - result = 31 * result + (url?.hashCode() ?: 0) + result = 31 * result + mediaType.hashCode() + result = 31 * result + url.hashCode() result = 31 * result + name.hashCode() return result } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt index d46edc8a..37ebb879 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt @@ -25,8 +25,8 @@ open class Emoji( override fun hashCode(): Int { var result = super.hashCode() - result = 31 * result + (updated?.hashCode() ?: 0) - result = 31 * result + (icon?.hashCode() ?: 0) + result = 31 * result + updated.hashCode() + result = 31 * result + icon.hashCode() return result } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt index 2689ccb5..d4ef2c95 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt @@ -26,7 +26,7 @@ open class Follow( override fun hashCode(): Int { var result = super.hashCode() - result = 31 * result + (`object`?.hashCode() ?: 0) + result = 31 * result + `object`.hashCode() result = 31 * result + actor.hashCode() return result } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt index 6353692b..5b63ef5e 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt @@ -25,8 +25,8 @@ open class Image( override fun hashCode(): Int { var result = super.hashCode() - result = 31 * result + (mediaType?.hashCode() ?: 0) - result = 31 * result + (url?.hashCode() ?: 0) + result = 31 * result + mediaType.hashCode() + result = 31 * result + url.hashCode() return result } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Key.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Key.kt index 4a13ba56..7e22097c 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Key.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Key.kt @@ -28,8 +28,8 @@ open class Key( override fun hashCode(): Int { var result = super.hashCode() - result = 31 * result + (owner?.hashCode() ?: 0) - result = 31 * result + (publicKeyPem?.hashCode() ?: 0) + result = 31 * result + owner.hashCode() + result = 31 * result + publicKeyPem.hashCode() result = 31 * result + id.hashCode() return result } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt index 889c8776..91bf8a86 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt @@ -54,6 +54,18 @@ constructor( return result } - override fun toString(): String = - "Note(id='$id', attributedTo='$attributedTo', content='$content', published='$published', to=$to, cc=$cc, sensitive=$sensitive, inReplyTo=$inReplyTo, attachment=$attachment) ${super.toString()}" + override fun toString(): String { + return "Note(" + + "id='$id', " + + "attributedTo='$attributedTo', " + + "content='$content', " + + "published='$published', " + + "to=$to, " + + "cc=$cc, " + + "sensitive=$sensitive, " + + "inReplyTo=$inReplyTo, " + + "attachment=$attachment" + + ")" + + " ${super.toString()}" + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt index 58165a81..fe1b2d5f 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt @@ -41,9 +41,9 @@ constructor( var result = super.hashCode() result = 31 * result + (preferredUsername?.hashCode() ?: 0) result = 31 * result + (summary?.hashCode() ?: 0) - result = 31 * result + (inbox?.hashCode() ?: 0) - result = 31 * result + (outbox?.hashCode() ?: 0) - result = 31 * result + (url?.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() ?: 0) result = 31 * result + endpoints.hashCode() diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/ApAcceptProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/ApAcceptProcessor.kt index 6060531f..0567bf5f 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/ApAcceptProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/ApAcceptProcessor.kt @@ -12,7 +12,7 @@ import dev.usbharu.hideout.core.query.UserQueryService import dev.usbharu.hideout.core.service.user.UserService class ApAcceptProcessor( - private val transaction: Transaction, + transaction: Transaction, private val userQueryService: UserQueryService, private val followerQueryService: FollowerQueryService, private val userService: UserService @@ -23,14 +23,14 @@ class ApAcceptProcessor( val value = activity.activity.`object` ?: throw IllegalActivityPubObjectException("object is null") if (value.type.contains("Follow").not()) { - logger.warn("FAILED Activity type is not Follow.") + logger.warn("FAILED Activity type isn't Follow.") throw IllegalActivityPubObjectException("Invalid type ${value.type}") } val follow = value as Follow - val userUrl = follow.`object` ?: throw IllegalActivityPubObjectException("object is null") - val followerUrl = follow.actor ?: throw IllegalActivityPubObjectException("actor is null") + val userUrl = follow.`object` + val followerUrl = follow.actor val user = userQueryService.findByUrl(userUrl) val follower = userQueryService.findByUrl(followerUrl) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/create/CreateActivityProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/create/CreateActivityProcessor.kt index 5d057b3f..2e1b557c 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/create/CreateActivityProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/create/CreateActivityProcessor.kt @@ -11,7 +11,7 @@ import org.springframework.stereotype.Service @Service class CreateActivityProcessor(transaction: Transaction, private val apNoteService: APNoteService) : - AbstractActivityPubProcessor(transaction, false) { + AbstractActivityPubProcessor(transaction) { override suspend fun internalProcess(activity: ActivityPubProcessContext) { apNoteService.fetchNote(activity.activity.`object` as Note) } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APFollowProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APFollowProcessor.kt index 92ad3e28..b56cd49f 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APFollowProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APFollowProcessor.kt @@ -1,7 +1,6 @@ package dev.usbharu.hideout.activitypub.service.activity.follow import com.fasterxml.jackson.databind.ObjectMapper -import dev.usbharu.hideout.activitypub.domain.exception.IllegalActivityPubObjectException import dev.usbharu.hideout.activitypub.domain.model.Follow import dev.usbharu.hideout.activitypub.service.common.AbstractActivityPubProcessor import dev.usbharu.hideout.activitypub.service.common.ActivityPubProcessContext @@ -22,9 +21,9 @@ class APFollowProcessor( // inboxをジョブキューに乗せているので既に不要だが、フォロー承認制アカウントを実装する際に必要なので残す val jobProps = ReceiveFollowJobParam( - activity.activity.actor ?: throw IllegalActivityPubObjectException("actor is null"), + activity.activity.actor, objectMapper.writeValueAsString(activity.activity), - activity.activity.`object` ?: throw IllegalActivityPubObjectException("object is null") + activity.activity.`object` ) jobQueueParentService.scheduleTypeSafe(ReceiveFollowJob, jobProps) } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APReceiveFollowJobProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APReceiveFollowJobProcessor.kt index a6aae23b..f8cf8556 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APReceiveFollowJobProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APReceiveFollowJobProcessor.kt @@ -33,7 +33,7 @@ class APReceiveFollowJobProcessor( val signer = userQueryService.findByUrl(param.targetActor) - val urlString = person.inbox ?: throw IllegalArgumentException("inbox is not found.") + val urlString = person.inbox apRequestService.apPost( url = urlString, @@ -47,7 +47,7 @@ class APReceiveFollowJobProcessor( val targetEntity = userQueryService.findByUrl(param.targetActor) val followActorEntity = - userQueryService.findByUrl(follow.actor ?: throw IllegalArgumentException("actor is null")) + userQueryService.findByUrl(follow.actor) userService.followRequest(targetEntity.id, followActorEntity.id) logger.info("SUCCESS Follow from: {} to: {}", param.targetActor, param.actor) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/APLikeProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/APLikeProcessor.kt index 470eaee7..9d56fe94 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/APLikeProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/APLikeProcessor.kt @@ -1,7 +1,6 @@ package dev.usbharu.hideout.activitypub.service.activity.like import dev.usbharu.hideout.activitypub.domain.exception.FailedToGetActivityPubResourceException -import dev.usbharu.hideout.activitypub.domain.exception.IllegalActivityPubObjectException import dev.usbharu.hideout.activitypub.domain.model.Like import dev.usbharu.hideout.activitypub.service.common.AbstractActivityPubProcessor import dev.usbharu.hideout.activitypub.service.common.ActivityPubProcessContext @@ -21,10 +20,10 @@ class APLikeProcessor( ) : AbstractActivityPubProcessor(transaction) { override suspend fun internalProcess(activity: ActivityPubProcessContext) { - val actor = activity.activity.actor ?: throw IllegalActivityPubObjectException("actor is null") - val content = activity.activity.content ?: throw IllegalActivityPubObjectException("content is null") + val actor = activity.activity.actor + val content = activity.activity.content - val target = activity.activity.`object` ?: throw IllegalActivityPubObjectException("object is null") + val target = activity.activity.`object` val personWithEntity = apUserService.fetchPersonWithEntity(actor) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt index 8c09b54f..99bd9ba1 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt @@ -24,7 +24,7 @@ class APUndoProcessor( } val type = - undo.`object`?.type.orEmpty() + undo.`object`.type.orEmpty() .firstOrNull { it == "Block" || it == "Follow" || it == "Like" || it == "Announce" || it == "Accept" } ?: return @@ -35,9 +35,9 @@ class APUndoProcessor( if (follow.`object` == null) { return } - apUserService.fetchPerson(undo.actor!!, follow.`object`) - val follower = userQueryService.findByUrl(undo.actor!!) - val target = userQueryService.findByUrl(follow.`object`!!) + apUserService.fetchPerson(undo.actor, follow.`object`) + val follower = userQueryService.findByUrl(undo.actor) + val target = userQueryService.findByUrl(follow.`object`) userService.unfollow(target.id, follower.id) return } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/APRequestServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/APRequestServiceImpl.kt index bf13b1ca..511d3e67 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/APRequestServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/APRequestServiceImpl.kt @@ -61,7 +61,7 @@ class APRequestServiceImpl( url: String ): HttpResponse { val headers = headers { - append("Accept", ContentType.Application.Activity) + append("Accept", Activity) append("Date", date) append("Host", u.host) } @@ -87,13 +87,13 @@ class APRequestServiceImpl( remove("Host") } } - contentType(ContentType.Application.Activity) + contentType(Activity) } return httpResponse } private suspend fun apGetNotSign(url: String, date: String?) = httpClient.get(url) { - header("Accept", ContentType.Application.Activity) + header("Accept", Activity) header("Date", date) } @@ -153,12 +153,12 @@ class APRequestServiceImpl( digest: String, requestBody: String? ) = httpClient.post(url) { - accept(ContentType.Application.Activity) + accept(Activity) header("Date", date) header("Digest", "sha-256=$digest") if (requestBody != null) { setBody(requestBody) - contentType(ContentType.Application.Activity) + contentType(Activity) } } @@ -170,7 +170,7 @@ class APRequestServiceImpl( requestBody: String? ): HttpResponse { val headers = headers { - append("Accept", ContentType.Application.Activity) + append("Accept", Activity) append("Date", date) append("Host", u.host) append("Digest", "sha-256=$digest") @@ -196,7 +196,7 @@ class APRequestServiceImpl( remove("Host") } setBody(requestBody) - contentType(ContentType.Application.Activity) + contentType(Activity) } return httpResponse } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/AbstractActivityPubProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/AbstractActivityPubProcessor.kt index 329941b2..1bb106e3 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/AbstractActivityPubProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/AbstractActivityPubProcessor.kt @@ -5,13 +5,14 @@ import dev.usbharu.hideout.activitypub.domain.exception.FailedProcessException import dev.usbharu.hideout.activitypub.domain.exception.HttpSignatureUnauthorizedException import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.application.external.Transaction +import org.slf4j.Logger import org.slf4j.LoggerFactory abstract class AbstractActivityPubProcessor( private val transaction: Transaction, private val allowUnauthorized: Boolean = false ) : ActivityPubProcessor { - protected val logger = LoggerFactory.getLogger(this::class.java) + protected val logger: Logger = LoggerFactory.getLogger(this::class.java) override suspend fun process(activity: ActivityPubProcessContext) { if (activity.isAuthorized.not() && allowUnauthorized.not()) { diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/APNoteService.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/APNoteService.kt index 28bf7c01..0e5b6e14 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/APNoteService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/APNoteService.kt @@ -90,7 +90,7 @@ class APNoteServiceImpl( requireNotNull(note.id) { "id is null" } return try { - noteQueryService.findByApid(note.id!!).first + noteQueryService.findByApid(note.id).first } catch (_: FailedToGetResourcesException) { saveNote(note, targetActor, url) } @@ -127,9 +127,9 @@ class APNoteServiceImpl( .map { mediaService.uploadRemoteMedia( RemoteMedia( - (it.name ?: it.url)!!, - it.url!!, - it.mediaType ?: "application/octet-stream", + it.name, + it.url, + it.mediaType, description = it.name ) ) @@ -144,10 +144,10 @@ class APNoteServiceImpl( text = note.content, createdAt = Instant.parse(note.published).toEpochMilli(), visibility = visibility, - url = note.id ?: url, + url = note.id, replyId = reply?.id, sensitive = note.sensitive, - apId = note.id ?: url, + apId = note.id, mediaIds = mediaList ) ) @@ -155,7 +155,7 @@ class APNoteServiceImpl( } override suspend fun fetchNote(note: Note, targetActor: String?): Note = - saveIfMissing(note, targetActor, note.id ?: throw IllegalArgumentException("note.id is null")) + saveIfMissing(note, targetActor, note.id) companion object { const val public: String = "https://www.w3.org/ns/activitystreams#Public" diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/user/APUserService.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/user/APUserService.kt index 31a2b505..143df20b 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/user/APUserService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/user/APUserService.kt @@ -83,7 +83,7 @@ class APUserServiceImpl( } catch (ignore: FailedToGetResourcesException) { val person = apResourceResolveService.resolve(url, null as Long?) - val id = person.id ?: throw IllegalActivityPubObjectException("id is null") + val id = person.id try { val userEntity = userQueryService.findByUrl(id) return entityToPerson(userEntity, id) to userEntity @@ -94,11 +94,11 @@ class APUserServiceImpl( name = person.preferredUsername ?: throw IllegalActivityPubObjectException("preferredUsername is null"), domain = id.substringAfter("://").substringBefore("/"), - screenName = (person.name ?: person.preferredUsername) + screenName = person.name ?: throw IllegalActivityPubObjectException("preferredUsername is null"), description = person.summary.orEmpty(), - inbox = person.inbox ?: throw IllegalActivityPubObjectException("inbox is null"), - outbox = person.outbox ?: throw IllegalActivityPubObjectException("outbox is null"), + inbox = person.inbox, + outbox = person.outbox, url = id, publicKey = person.publicKey?.publicKeyPem ?: throw IllegalActivityPubObjectException("publicKey is null"), diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaConvertException.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaConvertException.kt index d2d9d7c9..cc564619 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaConvertException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaConvertException.kt @@ -1,5 +1,7 @@ package dev.usbharu.hideout.core.domain.exception.media +import java.io.Serial + open class MediaConvertException : MediaException { constructor() : super() constructor(message: String?) : super(message) @@ -11,4 +13,9 @@ open class MediaConvertException : MediaException { enableSuppression, writableStackTrace ) + + companion object { + @Serial + private const val serialVersionUID: Long = -6349105549968160551L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaException.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaException.kt index 538e3c72..221c92e5 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaException.kt @@ -1,5 +1,7 @@ package dev.usbharu.hideout.core.domain.exception.media +import java.io.Serial + abstract class MediaException : RuntimeException { constructor() : super() constructor(message: String?) : super(message) @@ -11,4 +13,9 @@ abstract class MediaException : RuntimeException { enableSuppression, writableStackTrace ) + + companion object { + @Serial + private const val serialVersionUID: Long = 5988922562494187852L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaFileSizeException.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaFileSizeException.kt index f75b74c2..f5153641 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaFileSizeException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaFileSizeException.kt @@ -1,5 +1,7 @@ package dev.usbharu.hideout.core.domain.exception.media +import java.io.Serial + open class MediaFileSizeException : MediaException { constructor() : super() constructor(message: String?) : super(message) @@ -11,4 +13,9 @@ open class MediaFileSizeException : MediaException { enableSuppression, writableStackTrace ) + + companion object { + @Serial + private const val serialVersionUID: Long = 8672626879026555064L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaFileSizeIsZeroException.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaFileSizeIsZeroException.kt index 74261698..1837ce06 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaFileSizeIsZeroException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaFileSizeIsZeroException.kt @@ -1,5 +1,7 @@ package dev.usbharu.hideout.core.domain.exception.media +import java.io.Serial + class MediaFileSizeIsZeroException : MediaFileSizeException { constructor() : super() constructor(message: String?) : super(message) @@ -11,4 +13,9 @@ class MediaFileSizeIsZeroException : MediaFileSizeException { enableSuppression, writableStackTrace ) + + companion object { + @Serial + private const val serialVersionUID: Long = -2398394583775317875L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaProcessException.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaProcessException.kt index 4292d0e8..6751fec1 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaProcessException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaProcessException.kt @@ -1,5 +1,7 @@ package dev.usbharu.hideout.core.domain.exception.media +import java.io.Serial + class MediaProcessException : MediaException { constructor() : super() constructor(message: String?) : super(message) @@ -11,4 +13,9 @@ class MediaProcessException : MediaException { enableSuppression, writableStackTrace ) + + companion object { + @Serial + private const val serialVersionUID: Long = -5195233013542703735L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/UnsupportedMediaException.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/UnsupportedMediaException.kt index 7eea4e38..6c62f904 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/UnsupportedMediaException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/UnsupportedMediaException.kt @@ -1,5 +1,7 @@ package dev.usbharu.hideout.core.domain.exception.media +import java.io.Serial + class UnsupportedMediaException : MediaException { constructor() : super() constructor(message: String?) : super(message) @@ -11,4 +13,9 @@ class UnsupportedMediaException : MediaException { enableSuppression, writableStackTrace ) + + companion object { + @Serial + private const val serialVersionUID: Long = -116741513216017134L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo.kt index 427c76a3..f7fc3160 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo.kt @@ -1,15 +1,11 @@ package dev.usbharu.hideout.core.domain.model.instance -class Nodeinfo { +class Nodeinfo private constructor() { var links: List = emptyList() - - private constructor() } -class Links { +class Links private constructor() { var rel: String? = null var href: String? = null - - private constructor() } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo2_0.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo2_0.kt index 53479eee..98247150 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo2_0.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo2_0.kt @@ -3,23 +3,17 @@ package dev.usbharu.hideout.core.domain.model.instance @Suppress("ClassNaming") -class Nodeinfo2_0 { +class Nodeinfo2_0() { var metadata: Metadata? = null var software: Software? = null - - constructor() } -class Metadata { +class Metadata() { var nodeName: String? = null var nodeDescription: String? = null - - constructor() } -class Software { +class Software() { var name: String? = null var version: String? = null - - constructor() } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/InstanceRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/InstanceRepositoryImpl.kt index a7d8aa9b..883a5b48 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/InstanceRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/InstanceRepositoryImpl.kt @@ -54,7 +54,7 @@ class InstanceRepositoryImpl(private val idGenerateService: IdGenerateService) : } override suspend fun delete(instance: InstanceEntity) { - Instance.deleteWhere { Instance.id eq instance.id } + Instance.deleteWhere { id eq instance.id } } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/ExposedOAuth2AuthorizationService.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/ExposedOAuth2AuthorizationService.kt index 580c4029..34e72833 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/ExposedOAuth2AuthorizationService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/ExposedOAuth2AuthorizationService.kt @@ -62,7 +62,7 @@ class ExposedOAuth2AuthorizationService( it[accessTokenMetadata] = accessToken?.metadata?.let { it1 -> mapToJson(it1) } it[accessTokenType] = accessToken?.token?.tokenType?.value it[accessTokenScopes] = - accessToken?.run { token.scopes.joinToString(",").takeIf { it.isNotEmpty() } } + accessToken?.run { token.scopes.joinToString(",").takeIf { s -> s.isNotEmpty() } } it[refreshTokenValue] = refreshToken?.token?.tokenValue it[refreshTokenIssuedAt] = refreshToken?.token?.issuedAt it[refreshTokenExpiresAt] = refreshToken?.token?.expiresAt diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/instance/InstanceService.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/instance/InstanceService.kt index 41459964..2c773ce0 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/instance/InstanceService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/instance/InstanceService.kt @@ -53,7 +53,7 @@ class InstanceServiceImpl( name = nodeinfo20.metadata?.nodeName, description = nodeinfo20.metadata?.nodeDescription, url = resolveInstanceUrl, - iconUrl = resolveInstanceUrl + "/favicon.ico", + iconUrl = "$resolveInstanceUrl/favicon.ico", sharedInbox = sharedInbox, software = nodeinfo20.software?.name, version = nodeinfo20.software?.version @@ -72,7 +72,7 @@ class InstanceServiceImpl( name = nodeinfo20.metadata?.nodeName, description = nodeinfo20.metadata?.nodeDescription, url = resolveInstanceUrl, - iconUrl = resolveInstanceUrl + "/favicon.ico", + iconUrl = "$resolveInstanceUrl/favicon.ico", sharedInbox = sharedInbox, software = nodeinfo20.software?.name, version = nodeinfo20.software?.version diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaSave.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaSave.kt index 3529ace9..9fbae73a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaSave.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaSave.kt @@ -5,4 +5,29 @@ data class MediaSave( val prefix: String, val fileInputStream: ByteArray, val thumbnailInputStream: ByteArray? -) +) { + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as MediaSave + + if (name != other.name) return false + if (prefix != other.prefix) return false + if (!fileInputStream.contentEquals(other.fileInputStream)) return false + if (thumbnailInputStream != null) { + if (other.thumbnailInputStream == null) return false + if (!thumbnailInputStream.contentEquals(other.thumbnailInputStream)) return false + } else if (other.thumbnailInputStream != null) return false + + return true + } + + override fun hashCode(): Int { + var result = name.hashCode() + result = 31 * result + prefix.hashCode() + result = 31 * result + fileInputStream.contentHashCode() + result = 31 * result + (thumbnailInputStream?.contentHashCode() ?: 0) + return result + } +} diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaServiceImpl.kt index ff8f1d93..5337e53a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaServiceImpl.kt @@ -15,7 +15,7 @@ import dev.usbharu.hideout.core.domain.model.media.Media as EntityMedia @Service @Suppress("TooGenericExceptionCaught") -open class MediaServiceImpl( +class MediaServiceImpl( private val mediaDataStore: MediaDataStore, private val fileTypeDeterminationService: FileTypeDeterminationService, private val mediaBlurhashService: MediaBlurhashService, diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/media/ProcessedFile.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/media/ProcessedFile.kt index c138ed43..b3589cee 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/media/ProcessedFile.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/media/ProcessedFile.kt @@ -3,4 +3,22 @@ package dev.usbharu.hideout.core.service.media data class ProcessedFile( val byteArray: ByteArray, val extension: String -) +) { + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as ProcessedFile + + if (!byteArray.contentEquals(other.byteArray)) return false + if (extension != other.extension) return false + + return true + } + + override fun hashCode(): Int { + var result = byteArray.contentHashCode() + result = 31 * result + extension.hashCode() + return result + } +} diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt index 056e5249..1ab87448 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt @@ -6,6 +6,7 @@ import dev.usbharu.hideout.core.domain.model.reaction.Reaction import dev.usbharu.hideout.core.domain.model.reaction.ReactionRepository import dev.usbharu.hideout.core.query.ReactionQueryService import org.jetbrains.exposed.exceptions.ExposedSQLException +import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -50,6 +51,6 @@ class ReactionServiceImpl( } companion object { - val LOGGER = LoggerFactory.getLogger(ReactionServiceImpl::class.java) + val LOGGER: Logger = LoggerFactory.getLogger(ReactionServiceImpl::class.java) } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/resource/InMemoryCacheManager.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/resource/InMemoryCacheManager.kt index b48fadd7..587829c9 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/resource/InMemoryCacheManager.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/resource/InMemoryCacheManager.kt @@ -18,7 +18,7 @@ class InMemoryCacheManager : CacheManager { keyMutex.withLock { cacheKey.filter { Instant.ofEpochMilli(it.value).plusSeconds(300) <= Instant.now() } - val cached = cacheKey.get(key) + val cached = cacheKey[key] if (cached == null) { needRunBlock = true cacheKey[key] = Instant.now().toEpochMilli() diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserServiceImpl.kt index 4bf358b7..fa1c0f97 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserServiceImpl.kt @@ -52,8 +52,7 @@ class UserServiceImpl( createdAt = Instant.now(), following = "$userUrl/following", followers = "$userUrl/followers", - keyId = "$userUrl#pubkey", - instance = null + keyId = "$userUrl#pubkey" ) return userRepository.save(userEntity) } diff --git a/src/main/kotlin/dev/usbharu/hideout/generate/JsonOrFormModelMethodProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/generate/JsonOrFormModelMethodProcessor.kt index a4222880..f784a4d2 100644 --- a/src/main/kotlin/dev/usbharu/hideout/generate/JsonOrFormModelMethodProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/generate/JsonOrFormModelMethodProcessor.kt @@ -1,5 +1,6 @@ package dev.usbharu.hideout.generate +import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.core.MethodParameter import org.springframework.web.bind.support.WebDataBinderFactory @@ -49,6 +50,6 @@ class JsonOrFormModelMethodProcessor( } companion object { - val logger = LoggerFactory.getLogger(JsonOrFormModelMethodProcessor::class.java) + val logger: Logger = LoggerFactory.getLogger(JsonOrFormModelMethodProcessor::class.java) } } diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/StatusQueryServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/StatusQueryServiceImpl.kt index 5d113667..8010405d 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/StatusQueryServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/StatusQueryServiceImpl.kt @@ -11,6 +11,7 @@ import org.jetbrains.exposed.sql.select import org.springframework.stereotype.Repository import java.time.Instant +@Suppress("IncompleteDestructuring") @Repository class StatusQueryServiceImpl : StatusQueryService { override suspend fun findByPostIds(ids: List): List = findByPostIdsWithMedia(ids) diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/service/media/MediaApiServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/service/media/MediaApiServiceImpl.kt index 824a6f59..c87b6469 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/service/media/MediaApiServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/service/media/MediaApiServiceImpl.kt @@ -25,7 +25,6 @@ class MediaApiServiceImpl(private val mediaService: MediaService, private val tr type = type, url = uploadLocalMedia.url, previewUrl = uploadLocalMedia.thumbnailUrl, - remoteUrl = null, description = mediaRequest.description, blurhash = uploadLocalMedia.blurHash, textUrl = uploadLocalMedia.url diff --git a/src/main/kotlin/dev/usbharu/hideout/util/AcctUtil.kt b/src/main/kotlin/dev/usbharu/hideout/util/AcctUtil.kt index d8e7b246..a0f1a09b 100644 --- a/src/main/kotlin/dev/usbharu/hideout/util/AcctUtil.kt +++ b/src/main/kotlin/dev/usbharu/hideout/util/AcctUtil.kt @@ -35,7 +35,7 @@ object AcctUtil { } else -> { - throw IllegalArgumentException("Invalid acct.(Too many @)") + throw IllegalArgumentException("Invalid acct. (Too many @)") } } } diff --git a/src/main/kotlin/dev/usbharu/hideout/util/HttpUtil.kt b/src/main/kotlin/dev/usbharu/hideout/util/HttpUtil.kt index 882a211f..66d321fc 100644 --- a/src/main/kotlin/dev/usbharu/hideout/util/HttpUtil.kt +++ b/src/main/kotlin/dev/usbharu/hideout/util/HttpUtil.kt @@ -3,10 +3,10 @@ package dev.usbharu.hideout.util import io.ktor.http.* object HttpUtil { - val ContentType.Application.Activity: ContentType + val Activity: ContentType get() = ContentType("application", "activity+json") - val ContentType.Application.JsonLd: ContentType + val JsonLd: ContentType get() { return ContentType( contentType = "application", From 259ff937dc19996d3b1a31bfa9ad7c3f31fe3220 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Tue, 28 Nov 2023 12:34:56 +0900 Subject: [PATCH 6/7] =?UTF-8?q?refactor:=20object=E3=82=92apObject?= =?UTF-8?q?=E3=81=AB=E3=81=97=E3=81=A6=E3=82=A8=E3=82=B9=E3=82=B1=E3=83=BC?= =?UTF-8?q?=E3=83=97=E3=81=AE=E5=BF=85=E8=A6=81=E3=82=92=E3=81=AA=E3=81=8F?= =?UTF-8?q?=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activitypub/domain/model/Accept.kt | 24 +++++++++------ .../activitypub/domain/model/Create.kt | 30 ++++++++++++------- .../activitypub/domain/model/Delete.kt | 13 ++++---- .../activitypub/domain/model/Follow.kt | 9 +++--- .../hideout/activitypub/domain/model/Like.kt | 24 ++++++++++----- .../activity/accept/ApAcceptProcessor.kt | 4 +-- .../create/ApSendCreateServiceImpl.kt | 2 +- .../create/CreateActivityProcessor.kt | 2 +- .../activity/delete/APDeleteProcessor.kt | 2 +- .../activity/follow/APFollowProcessor.kt | 4 +-- .../follow/APReceiveFollowJobProcessor.kt | 2 +- .../activity/follow/APReceiveFollowService.kt | 4 +-- .../activity/follow/APSendFollowService.kt | 2 +- .../service/activity/like/APLikeProcessor.kt | 2 +- .../activity/like/ApReactionJobProcessor.kt | 2 +- .../service/activity/undo/APUndoProcessor.kt | 6 ++-- .../follow/APSendFollowServiceImplTest.kt | 2 +- .../common/APRequestServiceImplTest.kt | 16 +++++----- .../hideout/ap/ContextSerializerTest.kt | 4 +-- 19 files changed, 90 insertions(+), 64 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Accept.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Accept.kt index 15eaf20f..93ded2d2 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Accept.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Accept.kt @@ -1,6 +1,7 @@ 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 import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer @@ -8,13 +9,13 @@ import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer open class Accept @JsonCreator constructor( type: List = emptyList(), override val name: String, - @JsonDeserialize(using = ObjectDeserializer::class) @Suppress("VariableNaming") var `object`: Object?, + @JsonDeserialize(using = ObjectDeserializer::class) + @JsonProperty("object") + val apObject: Object, override val actor: String ) : Object( type = add(type, "Accept") -), - HasActor, - HasName { +), HasActor, HasName { override fun equals(other: Any?): Boolean { if (this === other) return true @@ -23,22 +24,27 @@ open class Accept @JsonCreator constructor( other as Accept - if (`object` != other.`object`) return false - if (actor != other.actor) return false if (name != other.name) return false + 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 + (`object`?.hashCode() ?: 0) - result = 31 * result + actor.hashCode() result = 31 * result + name.hashCode() + result = 31 * result + apObject.hashCode() + result = 31 * result + actor.hashCode() return result } override fun toString(): String { - return "Accept(" + "`object`=$`object`, " + "actor='$actor', " + "name='$name'" + ")" + " ${super.toString()}" + return "Accept(" + + "name='$name', " + + "apObject=$apObject, " + + "actor='$actor'" + + ")" + + " ${super.toString()}" } } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Create.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Create.kt index 6b6bb810..3353ea3c 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Create.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Create.kt @@ -1,5 +1,6 @@ package dev.usbharu.hideout.activitypub.domain.model +import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.databind.annotation.JsonDeserialize import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer @@ -8,8 +9,8 @@ open class Create( type: List = emptyList(), override val name: String, @JsonDeserialize(using = ObjectDeserializer::class) - @Suppress("VariableNaming") - val `object`: Object, + @JsonProperty("object") + val apObject: Object, override val actor: String, override val id: String, val to: List = emptyList(), @@ -28,27 +29,36 @@ open class Create( other as Create - if (`object` != other.`object`) return false - if (to != other.to) return false - if (cc != other.cc) return false 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 + (`object`?.hashCode() ?: 0) - result = 31 * result + to.hashCode() - result = 31 * result + cc.hashCode() result = 31 * result + name.hashCode() + 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 = - "Create(`object`=$`object`, to=$to, cc=$cc, name='$name', actor='$actor', id='$id') ${super.toString()}" + override fun toString(): String { + return "Create(" + + "name='$name', " + + "apObject=$apObject, " + + "actor='$actor', " + + "id='$id', " + + "to=$to, " + + "cc=$cc" + + ")" + + " ${super.toString()}" + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Delete.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Delete.kt index e4e8ccb0..f2142722 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Delete.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Delete.kt @@ -1,13 +1,14 @@ package dev.usbharu.hideout.activitypub.domain.model +import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.databind.annotation.JsonDeserialize import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer open class Delete : Object, HasId, HasActor { @JsonDeserialize(using = ObjectDeserializer::class) - @Suppress("VariableNaming") - val `object`: Object + @JsonProperty("object") + val apObject: Object val published: String override val actor: String override val id: String @@ -19,7 +20,7 @@ open class Delete : Object, HasId, HasActor { `object`: Object, published: String ) : super(add(type, "Delete")) { - this.`object` = `object` + this.apObject = `object` this.published = published this.actor = actor this.id = id @@ -32,7 +33,7 @@ open class Delete : Object, HasId, HasActor { other as Delete - if (`object` != other.`object`) return false + if (apObject != other.apObject) return false if (published != other.published) return false if (actor != other.actor) return false if (id != other.id) return false @@ -42,7 +43,7 @@ open class Delete : Object, HasId, HasActor { override fun hashCode(): Int { var result = super.hashCode() - result = 31 * result + (`object`?.hashCode() ?: 0) + result = 31 * result + (apObject?.hashCode() ?: 0) result = 31 * result + (published?.hashCode() ?: 0) result = 31 * result + actor.hashCode() result = 31 * result + id.hashCode() @@ -50,5 +51,5 @@ open class Delete : Object, HasId, HasActor { } override fun toString(): String = - "Delete(`object`=$`object`, published=$published, actor='$actor', id='$id') ${super.toString()}" + "Delete(`object`=$apObject, published=$published, actor='$actor', id='$id') ${super.toString()}" } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt index d4ef2c95..c7f292ba 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt @@ -1,10 +1,11 @@ package dev.usbharu.hideout.activitypub.domain.model +import com.fasterxml.jackson.annotation.JsonProperty import dev.usbharu.hideout.activitypub.domain.model.objects.Object open class Follow( type: List = emptyList(), - @Suppress("VariableNaming") val `object`: String, + @JsonProperty("object") val apObject: String, override val actor: String ) : Object( type = add(type, "Follow") @@ -18,7 +19,7 @@ open class Follow( other as Follow - if (`object` != other.`object`) return false + if (apObject != other.apObject) return false if (actor != other.actor) return false return true @@ -26,10 +27,10 @@ open class Follow( override fun hashCode(): Int { var result = super.hashCode() - result = 31 * result + `object`.hashCode() + result = 31 * result + apObject.hashCode() result = 31 * result + actor.hashCode() return result } - override fun toString(): String = "Follow(`object`=$`object`, actor='$actor') ${super.toString()}" + override fun toString(): String = "Follow(`object`=$apObject, actor='$actor') ${super.toString()}" } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Like.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Like.kt index f4eaa13f..39ef65a2 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Like.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Like.kt @@ -1,5 +1,6 @@ package dev.usbharu.hideout.activitypub.domain.model +import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.databind.annotation.JsonDeserialize import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer @@ -8,7 +9,7 @@ open class Like( type: List = emptyList(), override val actor: String, override val id: String, - @Suppress("VariableNaming") val `object`: String, + @JsonProperty("object") val apObject: String, val content: String, @JsonDeserialize(contentUsing = ObjectDeserializer::class) val tag: List = emptyList() ) : Object( @@ -24,26 +25,33 @@ open class Like( other as Like - if (`object` != other.`object`) return false - if (content != other.content) return false - if (tag != other.tag) return false 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 + (`object`?.hashCode() ?: 0) - result = 31 * result + (content?.hashCode() ?: 0) - result = 31 * result + tag.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(`object`=$`object`, content=$content, tag=$tag, actor='$actor', id='$id') ${super.toString()}" + return "Like(" + + "actor='$actor', " + + "id='$id', " + + "apObject='$apObject', " + + "content='$content', " + + "tag=$tag" + + ")" + + " ${super.toString()}" } } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/ApAcceptProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/ApAcceptProcessor.kt index 0567bf5f..68538572 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/ApAcceptProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/ApAcceptProcessor.kt @@ -20,7 +20,7 @@ class ApAcceptProcessor( AbstractActivityPubProcessor(transaction) { override suspend fun internalProcess(activity: ActivityPubProcessContext) { - val value = activity.activity.`object` ?: throw IllegalActivityPubObjectException("object is null") + val value = activity.activity.apObject ?: throw IllegalActivityPubObjectException("object is null") if (value.type.contains("Follow").not()) { logger.warn("FAILED Activity type isn't Follow.") @@ -29,7 +29,7 @@ class ApAcceptProcessor( val follow = value as Follow - val userUrl = follow.`object` + val userUrl = follow.apObject val followerUrl = follow.actor val user = userQueryService.findByUrl(userUrl) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/create/ApSendCreateServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/create/ApSendCreateServiceImpl.kt index 0d3eeac8..226f2a63 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/create/ApSendCreateServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/create/ApSendCreateServiceImpl.kt @@ -33,7 +33,7 @@ class ApSendCreateServiceImpl( val note = noteQueryService.findById(post.id).first val create = Create( name = "Create Note", - `object` = note, + apObject = note, actor = note.attributedTo, id = "${applicationConfig.url}/create/note/${post.id}" ) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/create/CreateActivityProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/create/CreateActivityProcessor.kt index 2e1b557c..827042ef 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/create/CreateActivityProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/create/CreateActivityProcessor.kt @@ -13,7 +13,7 @@ import org.springframework.stereotype.Service class CreateActivityProcessor(transaction: Transaction, private val apNoteService: APNoteService) : AbstractActivityPubProcessor(transaction) { override suspend fun internalProcess(activity: ActivityPubProcessContext) { - apNoteService.fetchNote(activity.activity.`object` as Note) + apNoteService.fetchNote(activity.activity.apObject as Note) } override fun isSupported(activityType: ActivityType): Boolean = activityType == ActivityType.Create diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/delete/APDeleteProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/delete/APDeleteProcessor.kt index f6f136fa..99f4b159 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/delete/APDeleteProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/delete/APDeleteProcessor.kt @@ -18,7 +18,7 @@ class APDeleteProcessor( ) : AbstractActivityPubProcessor(transaction) { override suspend fun internalProcess(activity: ActivityPubProcessContext) { - val value = activity.activity.`object` + val value = activity.activity.apObject if (value !is HasId) { throw IllegalActivityPubObjectException("object hasn't id") } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APFollowProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APFollowProcessor.kt index b56cd49f..847f4609 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APFollowProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APFollowProcessor.kt @@ -17,13 +17,13 @@ class APFollowProcessor( ) : AbstractActivityPubProcessor(transaction) { override suspend fun internalProcess(activity: ActivityPubProcessContext) { - logger.info("FOLLOW from: {} to {}", activity.activity.actor, activity.activity.`object`) + logger.info("FOLLOW from: {} to {}", activity.activity.actor, activity.activity.apObject) // inboxをジョブキューに乗せているので既に不要だが、フォロー承認制アカウントを実装する際に必要なので残す val jobProps = ReceiveFollowJobParam( activity.activity.actor, objectMapper.writeValueAsString(activity.activity), - activity.activity.`object` + activity.activity.apObject ) jobQueueParentService.scheduleTypeSafe(ReceiveFollowJob, jobProps) } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APReceiveFollowJobProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APReceiveFollowJobProcessor.kt index f8cf8556..0c3957b1 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APReceiveFollowJobProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APReceiveFollowJobProcessor.kt @@ -39,7 +39,7 @@ class APReceiveFollowJobProcessor( url = urlString, body = Accept( name = "Follow", - `object` = follow, + apObject = follow, actor = param.targetActor ), signer = signer diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APReceiveFollowService.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APReceiveFollowService.kt index 2011fce1..01d85a8b 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APReceiveFollowService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APReceiveFollowService.kt @@ -18,11 +18,11 @@ class APReceiveFollowServiceImpl( @Qualifier("activitypub") private val objectMapper: ObjectMapper ) : APReceiveFollowService { override suspend fun receiveFollow(follow: Follow) { - logger.info("FOLLOW from: {} to: {}", follow.actor, follow.`object`) + logger.info("FOLLOW from: {} to: {}", follow.actor, follow.apObject) jobQueueParentService.schedule(ReceiveFollowJob) { props[ReceiveFollowJob.actor] = follow.actor props[ReceiveFollowJob.follow] = objectMapper.writeValueAsString(follow) - props[ReceiveFollowJob.targetActor] = follow.`object` + props[ReceiveFollowJob.targetActor] = follow.apObject } return } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APSendFollowService.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APSendFollowService.kt index 554fa571..825ec198 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APSendFollowService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APSendFollowService.kt @@ -15,7 +15,7 @@ class APSendFollowServiceImpl( ) : APSendFollowService { override suspend fun sendFollow(sendFollowDto: SendFollowDto) { val follow = Follow( - `object` = sendFollowDto.followTargetUserId.url, + apObject = sendFollowDto.followTargetUserId.url, actor = sendFollowDto.userId.url ) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/APLikeProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/APLikeProcessor.kt index 9d56fe94..8938f017 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/APLikeProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/APLikeProcessor.kt @@ -23,7 +23,7 @@ class APLikeProcessor( val actor = activity.activity.actor val content = activity.activity.content - val target = activity.activity.`object` + val target = activity.activity.apObject val personWithEntity = apUserService.fetchPersonWithEntity(actor) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApReactionJobProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApReactionJobProcessor.kt index 3f73bb2e..1fee5eda 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApReactionJobProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApReactionJobProcessor.kt @@ -22,7 +22,7 @@ class ApReactionJobProcessor( param.inbox, Like( actor = param.actor, - `object` = param.postUrl, + apObject = param.postUrl, id = "${applicationConfig.url}/liek/note/${param.id}", content = param.reaction ), diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt index 99bd9ba1..16419348 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt @@ -32,12 +32,12 @@ class APUndoProcessor( "Follow" -> { val follow = undo.`object` as Follow - if (follow.`object` == null) { + if (follow.apObject == null) { return } - apUserService.fetchPerson(undo.actor, follow.`object`) + apUserService.fetchPerson(undo.actor, follow.apObject) val follower = userQueryService.findByUrl(undo.actor) - val target = userQueryService.findByUrl(follow.`object`) + val target = userQueryService.findByUrl(follow.apObject) userService.unfollow(target.id, follower.id) return } diff --git a/src/test/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APSendFollowServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APSendFollowServiceImplTest.kt index 93e1d76d..0fe5f689 100644 --- a/src/test/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APSendFollowServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APSendFollowServiceImplTest.kt @@ -24,7 +24,7 @@ class APSendFollowServiceImplTest { apSendFollowServiceImpl.sendFollow(sendFollowDto) val value = Follow( - `object` = sendFollowDto.followTargetUserId.url, + apObject = sendFollowDto.followTargetUserId.url, actor = sendFollowDto.userId.url ) verify(apRequestService, times(1)).apPost( diff --git a/src/test/kotlin/dev/usbharu/hideout/activitypub/service/common/APRequestServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/activitypub/service/common/APRequestServiceImplTest.kt index 2c609183..2bb41d56 100644 --- a/src/test/kotlin/dev/usbharu/hideout/activitypub/service/common/APRequestServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/activitypub/service/common/APRequestServiceImplTest.kt @@ -47,7 +47,7 @@ class APRequestServiceImplTest { ) val responseClass = Follow( - `object` = "https://example.com", + apObject = "https://example.com", actor = "https://example.com" ) apRequestServiceImpl.apGet("https://example.com", responseClass = responseClass::class.java) @@ -72,7 +72,7 @@ class APRequestServiceImplTest { ) val responseClass = Follow( - `object` = "https://example.com", + apObject = "https://example.com", actor = "https://example.com" ) apRequestServiceImpl.apGet( @@ -112,7 +112,7 @@ class APRequestServiceImplTest { ) val responseClass = Follow( - `object` = "https://example.com", + apObject = "https://example.com", actor = "https://example.com" ) apRequestServiceImpl.apGet( @@ -163,7 +163,7 @@ class APRequestServiceImplTest { }), objectMapper, mock(), dateTimeFormatter) val body = Follow( - `object` = "https://example.com", + apObject = "https://example.com", actor = "https://example.com" ) apRequestServiceImpl.apPost("https://example.com", body, null) @@ -209,7 +209,7 @@ class APRequestServiceImplTest { }), objectMapper, mock(), dateTimeFormatter) val body = Follow( - `object` = "https://example.com", + apObject = "https://example.com", actor = "https://example.com" ) apRequestServiceImpl.apPost("https://example.com", body, null) @@ -239,7 +239,7 @@ class APRequestServiceImplTest { }), objectMapper, mock(), dateTimeFormatter) val body = Follow( - `object` = "https://example.com", + apObject = "https://example.com", actor = "https://example.com" ) apRequestServiceImpl.apPost("https://example.com", body, UserBuilder.remoteUserOf()) @@ -280,7 +280,7 @@ class APRequestServiceImplTest { }), objectMapper, httpSignatureSigner, dateTimeFormatter) val body = Follow( - `object` = "https://example.com", + apObject = "https://example.com", actor = "https://example.com" ) apRequestServiceImpl.apPost( @@ -330,7 +330,7 @@ class APRequestServiceImplTest { }), objectMapper, mock(), dateTimeFormatter) val body = Follow( - `object` = "https://example.com", + apObject = "https://example.com", actor = "https://example.com" ) val actual = apRequestServiceImpl.apPost("https://example.com", body, null, body::class.java) diff --git a/src/test/kotlin/dev/usbharu/hideout/ap/ContextSerializerTest.kt b/src/test/kotlin/dev/usbharu/hideout/ap/ContextSerializerTest.kt index d73e31d7..a141c11b 100644 --- a/src/test/kotlin/dev/usbharu/hideout/ap/ContextSerializerTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/ap/ContextSerializerTest.kt @@ -12,8 +12,8 @@ class ContextSerializerTest { val accept = Accept( name = "aaa", actor = "bbb", - `object` = Follow( - `object` = "ddd", + apObject = Follow( + apObject = "ddd", actor = "aaa" ) ) From c28b1ab11ef0fdccbc5d4a416ac0a07728e2fb01 Mon Sep 17 00:00:00 2001 From: usbharu Date: Tue, 28 Nov 2023 12:41:26 +0900 Subject: [PATCH 7/7] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../activitypub/domain/model/Accept.kt | 14 +++++++----- .../activitypub/domain/model/Create.kt | 16 +++++++------- .../hideout/activitypub/domain/model/Like.kt | 14 ++++++------ .../hideout/activitypub/domain/model/Note.kt | 22 +++++++++---------- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Accept.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Accept.kt index 93ded2d2..2cd730db 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Accept.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Accept.kt @@ -15,7 +15,9 @@ open class Accept @JsonCreator constructor( override val actor: String ) : Object( type = add(type, "Accept") -), HasActor, HasName { +), + HasActor, + HasName { override fun equals(other: Any?): Boolean { if (this === other) return true @@ -41,10 +43,10 @@ open class Accept @JsonCreator constructor( override fun toString(): String { return "Accept(" + - "name='$name', " + - "apObject=$apObject, " + - "actor='$actor'" + - ")" + - " ${super.toString()}" + "name='$name', " + + "apObject=$apObject, " + + "actor='$actor'" + + ")" + + " ${super.toString()}" } } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Create.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Create.kt index 3353ea3c..d5b269dd 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Create.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Create.kt @@ -52,13 +52,13 @@ open class Create( override fun toString(): String { return "Create(" + - "name='$name', " + - "apObject=$apObject, " + - "actor='$actor', " + - "id='$id', " + - "to=$to, " + - "cc=$cc" + - ")" + - " ${super.toString()}" + "name='$name', " + + "apObject=$apObject, " + + "actor='$actor', " + + "id='$id', " + + "to=$to, " + + "cc=$cc" + + ")" + + " ${super.toString()}" } } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Like.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Like.kt index 39ef65a2..ec8e8ec7 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Like.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Like.kt @@ -46,12 +46,12 @@ open class Like( override fun toString(): String { return "Like(" + - "actor='$actor', " + - "id='$id', " + - "apObject='$apObject', " + - "content='$content', " + - "tag=$tag" + - ")" + - " ${super.toString()}" + "actor='$actor', " + + "id='$id', " + + "apObject='$apObject', " + + "content='$content', " + + "tag=$tag" + + ")" + + " ${super.toString()}" } } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt index 91bf8a86..2b16e1c4 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt @@ -56,16 +56,16 @@ constructor( override fun toString(): String { return "Note(" + - "id='$id', " + - "attributedTo='$attributedTo', " + - "content='$content', " + - "published='$published', " + - "to=$to, " + - "cc=$cc, " + - "sensitive=$sensitive, " + - "inReplyTo=$inReplyTo, " + - "attachment=$attachment" + - ")" + - " ${super.toString()}" + "id='$id', " + + "attributedTo='$attributedTo', " + + "content='$content', " + + "published='$published', " + + "to=$to, " + + "cc=$cc, " + + "sensitive=$sensitive, " + + "inReplyTo=$inReplyTo, " + + "attachment=$attachment" + + ")" + + " ${super.toString()}" } }