mirror of https://github.com/usbharu/Hideout.git
style: fix lint
This commit is contained in:
parent
8b1d1a5b09
commit
2f0629153b
|
@ -17,7 +17,7 @@ open class Announce @JsonCreator constructor(
|
|||
type = add(type, "Announce")
|
||||
),
|
||||
HasActor,
|
||||
HasId{
|
||||
HasId {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
@ -48,13 +48,13 @@ open class Announce @JsonCreator constructor(
|
|||
|
||||
override fun toString(): String {
|
||||
return "Announce(" +
|
||||
"apObject='$apObject', " +
|
||||
"actor='$actor', " +
|
||||
"id='$id', " +
|
||||
"published='$published', " +
|
||||
"to=$to, " +
|
||||
"cc=$cc" +
|
||||
")" +
|
||||
" ${super.toString()}"
|
||||
"apObject='$apObject', " +
|
||||
"actor='$actor', " +
|
||||
"id='$id', " +
|
||||
"published='$published', " +
|
||||
"to=$to, " +
|
||||
"cc=$cc" +
|
||||
")" +
|
||||
" ${super.toString()}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import dev.usbharu.hideout.activitypub.domain.model.objects.Object
|
|||
import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer
|
||||
|
||||
open class Note
|
||||
@Suppress("LongParameterList")
|
||||
@Suppress("LongParameterList", "CyclomaticComplexMethod")
|
||||
constructor(
|
||||
type: List<String> = emptyList(),
|
||||
override val id: String,
|
||||
|
@ -28,6 +28,8 @@ constructor(
|
|||
type = add(type, "Note")
|
||||
),
|
||||
HasId {
|
||||
|
||||
@Suppress("CyclomaticComplexMethod", "CognitiveComplexMethod")
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
@ -52,6 +54,7 @@ constructor(
|
|||
return true
|
||||
}
|
||||
|
||||
@Suppress("CyclomaticComplexMethod")
|
||||
override fun hashCode(): Int {
|
||||
var result = super.hashCode()
|
||||
result = 31 * result + id.hashCode()
|
||||
|
|
|
@ -45,7 +45,7 @@ class ExposedAnnounceQueryService(
|
|||
)
|
||||
|
||||
return Announce(
|
||||
emptyList(),
|
||||
type = emptyList(),
|
||||
id = this[Posts.apId],
|
||||
apObject = repost,
|
||||
actor = this[Actors.url],
|
||||
|
@ -63,4 +63,4 @@ class ExposedAnnounceQueryService(
|
|||
Visibility.DIRECT -> TODO()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,8 +66,7 @@ class NoteQueryServiceImpl(private val postRepository: PostRepository, private v
|
|||
logger.warn("Failed to get repostId: $repostId")
|
||||
}
|
||||
url
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
|
|
|
@ -8,4 +8,4 @@ import org.springframework.stereotype.Repository
|
|||
interface AnnounceQueryService {
|
||||
suspend fun findById(id: Long): Pair<Announce, Post>?
|
||||
suspend fun findByApId(apId: String): Pair<Announce, Post>?
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,4 +18,4 @@ class ApAnnounceProcessor(transaction: Transaction, private val apNoteService: A
|
|||
override fun isSupported(activityType: ActivityType): Boolean = ActivityType.Announce == activityType
|
||||
|
||||
override fun type(): Class<Announce> = Announce::class.java
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.Emoji
|
||||
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.NoteQueryService
|
||||
import dev.usbharu.hideout.activitypub.service.common.APResourceResolveService
|
||||
import dev.usbharu.hideout.activitypub.service.common.resolve
|
||||
import dev.usbharu.hideout.activitypub.service.objects.emoji.EmojiService
|
||||
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.PostRepository
|
||||
import dev.usbharu.hideout.core.domain.model.post.Visibility
|
||||
|
@ -68,7 +70,7 @@ class APNoteServiceImpl(
|
|||
)
|
||||
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)
|
||||
return savedNote
|
||||
}
|
||||
|
@ -136,34 +138,22 @@ class APNoteServiceImpl(
|
|||
|
||||
private suspend fun saveIfMissing(
|
||||
note: Note,
|
||||
targetActor: String?,
|
||||
url: String
|
||||
): Pair<Note, Post> = noteQueryService.findByApid(note.id) ?: saveNote(note, targetActor, url)
|
||||
targetActor: String?
|
||||
): Pair<Note, Post> = noteQueryService.findByApid(note.id) ?: saveNote(note, targetActor)
|
||||
|
||||
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(
|
||||
note.attributedTo,
|
||||
targetActor
|
||||
)
|
||||
|
||||
val post = postRepository.findByApId(note.id)
|
||||
|
||||
if (post != null) {
|
||||
return note to post
|
||||
}
|
||||
|
||||
logger.debug("VISIBILITY url: {} to: {} cc: {}", note.id, note.to, note.cc)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
val visibility = visibility(note, person)
|
||||
logger.debug("VISIBILITY is {} url: {}", visibility.name, note.id)
|
||||
|
||||
val reply = note.inReplyTo?.let {
|
||||
|
@ -176,14 +166,7 @@ class APNoteServiceImpl(
|
|||
postRepository.findByUrl(it)
|
||||
}
|
||||
|
||||
val emojis = note.tag
|
||||
.filterIsInstance<Emoji>()
|
||||
.map {
|
||||
emojiService.fetchEmoji(it).second
|
||||
}
|
||||
.map {
|
||||
it.id
|
||||
}
|
||||
val emojis = buildEmojis(note)
|
||||
|
||||
val mediaList = note.attachment.map {
|
||||
mediaService.uploadRemoteMedia(
|
||||
|
@ -228,14 +211,37 @@ class APNoteServiceImpl(
|
|||
)
|
||||
}
|
||||
|
||||
val createRemote = postService.createRemote(
|
||||
createPost
|
||||
)
|
||||
val createRemote = postService.createRemote(createPost)
|
||||
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 =
|
||||
saveIfMissing(note, targetActor, note.id).first
|
||||
saveIfMissing(note, targetActor).first
|
||||
|
||||
companion object {
|
||||
const val public: String = "https://www.w3.org/ns/activitystreams#Public"
|
||||
|
|
|
@ -223,7 +223,11 @@ data class Post private constructor(
|
|||
}
|
||||
|
||||
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 {
|
||||
return Post(
|
||||
|
|
|
@ -36,6 +36,7 @@ interface RelationshipRepository {
|
|||
|
||||
suspend fun findByTargetIdAndFollowing(targetId: Long, following: Boolean): List<Relationship>
|
||||
|
||||
@Suppress("FunctionMaxLength")
|
||||
suspend fun findByTargetIdAndFollowRequestAndIgnoreFollowRequest(
|
||||
targetId: Long,
|
||||
followRequest: Boolean,
|
||||
|
|
|
@ -8,6 +8,7 @@ interface MastodonNotificationRepository {
|
|||
suspend fun deleteById(id: Long)
|
||||
suspend fun findById(id: Long): MastodonNotification?
|
||||
|
||||
@Suppress("FunctionMaxLength")
|
||||
suspend fun findByUserIdAndInTypesAndInSourceActorId(
|
||||
loginUser: Long,
|
||||
types: List<NotificationType>,
|
||||
|
|
|
@ -84,7 +84,7 @@ class MastodonAccountApiController(
|
|||
maxId?.toLongOrNull(),
|
||||
sinceId?.toLongOrNull(),
|
||||
minId?.toLongOrNull(),
|
||||
limit.coerceIn(0, 80) ?: 40
|
||||
limit.coerceIn(0, 80)
|
||||
)
|
||||
)
|
||||
val httpHeader = statuses.toHttpHeader(
|
||||
|
|
Loading…
Reference in New Issue