style: fix lint

This commit is contained in:
usbharu 2024-02-03 16:37:25 +09:00
parent 8b1d1a5b09
commit 2f0629153b
11 changed files with 62 additions and 48 deletions

View File

@ -17,7 +17,7 @@ open class Announce @JsonCreator constructor(
type = add(type, "Announce") type = add(type, "Announce")
), ),
HasActor, HasActor,
HasId{ HasId {
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
if (javaClass != other?.javaClass) return false if (javaClass != other?.javaClass) return false
@ -48,13 +48,13 @@ open class Announce @JsonCreator constructor(
override fun toString(): String { override fun toString(): String {
return "Announce(" + return "Announce(" +
"apObject='$apObject', " + "apObject='$apObject', " +
"actor='$actor', " + "actor='$actor', " +
"id='$id', " + "id='$id', " +
"published='$published', " + "published='$published', " +
"to=$to, " + "to=$to, " +
"cc=$cc" + "cc=$cc" +
")" + ")" +
" ${super.toString()}" " ${super.toString()}"
} }
} }

View File

@ -6,7 +6,7 @@ import dev.usbharu.hideout.activitypub.domain.model.objects.Object
import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer
open class Note open class Note
@Suppress("LongParameterList") @Suppress("LongParameterList", "CyclomaticComplexMethod")
constructor( constructor(
type: List<String> = emptyList(), type: List<String> = emptyList(),
override val id: String, override val id: String,
@ -28,6 +28,8 @@ constructor(
type = add(type, "Note") type = add(type, "Note")
), ),
HasId { HasId {
@Suppress("CyclomaticComplexMethod", "CognitiveComplexMethod")
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
if (javaClass != other?.javaClass) return false if (javaClass != other?.javaClass) return false
@ -52,6 +54,7 @@ constructor(
return true return true
} }
@Suppress("CyclomaticComplexMethod")
override fun hashCode(): Int { override fun hashCode(): Int {
var result = super.hashCode() var result = super.hashCode()
result = 31 * result + id.hashCode() result = 31 * result + id.hashCode()

View File

@ -45,7 +45,7 @@ class ExposedAnnounceQueryService(
) )
return Announce( return Announce(
emptyList(), type = emptyList(),
id = this[Posts.apId], id = this[Posts.apId],
apObject = repost, apObject = repost,
actor = this[Actors.url], actor = this[Actors.url],
@ -63,4 +63,4 @@ class ExposedAnnounceQueryService(
Visibility.DIRECT -> TODO() Visibility.DIRECT -> TODO()
} }
} }
} }

View File

@ -66,8 +66,7 @@ class NoteQueryServiceImpl(private val postRepository: PostRepository, private v
logger.warn("Failed to get repostId: $repostId") logger.warn("Failed to get repostId: $repostId")
} }
url url
} } else {
else {
null null
} }

View File

@ -8,4 +8,4 @@ import org.springframework.stereotype.Repository
interface AnnounceQueryService { interface AnnounceQueryService {
suspend fun findById(id: Long): Pair<Announce, Post>? suspend fun findById(id: Long): Pair<Announce, Post>?
suspend fun findByApId(apId: String): Pair<Announce, Post>? suspend fun findByApId(apId: String): Pair<Announce, Post>?
} }

View File

@ -18,4 +18,4 @@ class ApAnnounceProcessor(transaction: Transaction, private val apNoteService: A
override fun isSupported(activityType: ActivityType): Boolean = ActivityType.Announce == activityType override fun isSupported(activityType: ActivityType): Boolean = ActivityType.Announce == activityType
override fun type(): Class<Announce> = Announce::class.java override fun type(): Class<Announce> = Announce::class.java
} }

View File

@ -4,12 +4,14 @@ import dev.usbharu.hideout.activitypub.domain.exception.FailedToGetActivityPubRe
import dev.usbharu.hideout.activitypub.domain.model.Announce import dev.usbharu.hideout.activitypub.domain.model.Announce
import dev.usbharu.hideout.activitypub.domain.model.Emoji import dev.usbharu.hideout.activitypub.domain.model.Emoji
import dev.usbharu.hideout.activitypub.domain.model.Note import dev.usbharu.hideout.activitypub.domain.model.Note
import dev.usbharu.hideout.activitypub.domain.model.Person
import dev.usbharu.hideout.activitypub.query.AnnounceQueryService import dev.usbharu.hideout.activitypub.query.AnnounceQueryService
import dev.usbharu.hideout.activitypub.query.NoteQueryService import dev.usbharu.hideout.activitypub.query.NoteQueryService
import dev.usbharu.hideout.activitypub.service.common.APResourceResolveService import dev.usbharu.hideout.activitypub.service.common.APResourceResolveService
import dev.usbharu.hideout.activitypub.service.common.resolve import dev.usbharu.hideout.activitypub.service.common.resolve
import dev.usbharu.hideout.activitypub.service.objects.emoji.EmojiService import dev.usbharu.hideout.activitypub.service.objects.emoji.EmojiService
import dev.usbharu.hideout.activitypub.service.objects.user.APUserService import dev.usbharu.hideout.activitypub.service.objects.user.APUserService
import dev.usbharu.hideout.core.domain.model.actor.Actor
import dev.usbharu.hideout.core.domain.model.post.Post import dev.usbharu.hideout.core.domain.model.post.Post
import dev.usbharu.hideout.core.domain.model.post.PostRepository import dev.usbharu.hideout.core.domain.model.post.PostRepository
import dev.usbharu.hideout.core.domain.model.post.Visibility import dev.usbharu.hideout.core.domain.model.post.Visibility
@ -68,7 +70,7 @@ class APNoteServiceImpl(
) )
throw FailedToGetActivityPubResourceException("Could not retrieve $url.", e) throw FailedToGetActivityPubResourceException("Could not retrieve $url.", e)
} }
val savedNote = saveIfMissing(note, targetActor, url) val savedNote = saveIfMissing(note, targetActor)
logger.debug("SUCCESS Fetch Note url: {}", url) logger.debug("SUCCESS Fetch Note url: {}", url)
return savedNote return savedNote
} }
@ -136,34 +138,22 @@ class APNoteServiceImpl(
private suspend fun saveIfMissing( private suspend fun saveIfMissing(
note: Note, note: Note,
targetActor: String?, targetActor: String?
url: String ): Pair<Note, Post> = noteQueryService.findByApid(note.id) ?: saveNote(note, targetActor)
): Pair<Note, Post> = noteQueryService.findByApid(note.id) ?: saveNote(note, targetActor, url)
private suspend fun saveNote(note: Note, targetActor: String?, url: String): Pair<Note, Post> { private suspend fun saveNote(note: Note, targetActor: String?): Pair<Note, Post> {
val person = apUserService.fetchPersonWithEntity( val person = apUserService.fetchPersonWithEntity(
note.attributedTo, note.attributedTo,
targetActor targetActor
) )
val post = postRepository.findByApId(note.id) val post = postRepository.findByApId(note.id)
if (post != null) { if (post != null) {
return note to post return note to post
} }
logger.debug("VISIBILITY url: {} to: {} cc: {}", note.id, note.to, note.cc) logger.debug("VISIBILITY url: {} to: {} cc: {}", note.id, note.to, note.cc)
val visibility = visibility(note, person)
val visibility = if (note.to.contains(public)) {
Visibility.PUBLIC
} else if (note.to.contains(person.second.followers) && note.cc.contains(public)) {
Visibility.UNLISTED
} else if (note.to.contains(person.second.followers)) {
Visibility.FOLLOWERS
} else {
Visibility.DIRECT
}
logger.debug("VISIBILITY is {} url: {}", visibility.name, note.id) logger.debug("VISIBILITY is {} url: {}", visibility.name, note.id)
val reply = note.inReplyTo?.let { val reply = note.inReplyTo?.let {
@ -176,14 +166,7 @@ class APNoteServiceImpl(
postRepository.findByUrl(it) postRepository.findByUrl(it)
} }
val emojis = note.tag val emojis = buildEmojis(note)
.filterIsInstance<Emoji>()
.map {
emojiService.fetchEmoji(it).second
}
.map {
it.id
}
val mediaList = note.attachment.map { val mediaList = note.attachment.map {
mediaService.uploadRemoteMedia( mediaService.uploadRemoteMedia(
@ -228,14 +211,37 @@ class APNoteServiceImpl(
) )
} }
val createRemote = postService.createRemote( val createRemote = postService.createRemote(createPost)
createPost
)
return note to createRemote return note to createRemote
} }
private suspend fun buildEmojis(note: Note) = note.tag
.filterIsInstance<Emoji>()
.map {
emojiService.fetchEmoji(it).second
}
.map {
it.id
}
private fun visibility(
note: Note,
person: Pair<Person, Actor>
): Visibility {
val visibility = if (note.to.contains(public)) {
Visibility.PUBLIC
} else if (note.to.contains(person.second.followers) && note.cc.contains(public)) {
Visibility.UNLISTED
} else if (note.to.contains(person.second.followers)) {
Visibility.FOLLOWERS
} else {
Visibility.DIRECT
}
return visibility
}
override suspend fun fetchNote(note: Note, targetActor: String?): Note = override suspend fun fetchNote(note: Note, targetActor: String?): Note =
saveIfMissing(note, targetActor, note.id).first saveIfMissing(note, targetActor).first
companion object { companion object {
const val public: String = "https://www.w3.org/ns/activitystreams#Public" const val public: String = "https://www.w3.org/ns/activitystreams#Public"

View File

@ -223,7 +223,11 @@ data class Post private constructor(
} }
fun isPureRepost(): Boolean = fun isPureRepost(): Boolean =
this.text.isEmpty() && this.content.isEmpty() && this.overview == null && this.replyId == null && this.repostId != null this.text.isEmpty() &&
this.content.isEmpty() &&
this.overview == null &&
this.replyId == null &&
this.repostId != null
fun delete(): Post { fun delete(): Post {
return Post( return Post(

View File

@ -36,6 +36,7 @@ interface RelationshipRepository {
suspend fun findByTargetIdAndFollowing(targetId: Long, following: Boolean): List<Relationship> suspend fun findByTargetIdAndFollowing(targetId: Long, following: Boolean): List<Relationship>
@Suppress("FunctionMaxLength")
suspend fun findByTargetIdAndFollowRequestAndIgnoreFollowRequest( suspend fun findByTargetIdAndFollowRequestAndIgnoreFollowRequest(
targetId: Long, targetId: Long,
followRequest: Boolean, followRequest: Boolean,

View File

@ -8,6 +8,7 @@ interface MastodonNotificationRepository {
suspend fun deleteById(id: Long) suspend fun deleteById(id: Long)
suspend fun findById(id: Long): MastodonNotification? suspend fun findById(id: Long): MastodonNotification?
@Suppress("FunctionMaxLength")
suspend fun findByUserIdAndInTypesAndInSourceActorId( suspend fun findByUserIdAndInTypesAndInSourceActorId(
loginUser: Long, loginUser: Long,
types: List<NotificationType>, types: List<NotificationType>,

View File

@ -84,7 +84,7 @@ class MastodonAccountApiController(
maxId?.toLongOrNull(), maxId?.toLongOrNull(),
sinceId?.toLongOrNull(), sinceId?.toLongOrNull(),
minId?.toLongOrNull(), minId?.toLongOrNull(),
limit.coerceIn(0, 80) ?: 40 limit.coerceIn(0, 80)
) )
) )
val httpHeader = statuses.toHttpHeader( val httpHeader = statuses.toHttpHeader(