Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
usbharu 2024-02-03 16:15:27 +09:00 committed by GitHub
parent 35d126703b
commit 7b9ef770da
9 changed files with 52 additions and 55 deletions

View File

@ -15,4 +15,6 @@ open class Announce @JsonCreator constructor(
val cc: List<String> = emptyList() val cc: List<String> = emptyList()
) : Object( ) : Object(
type = add(type, "Announce") type = add(type, "Announce")
), HasActor, HasId ),
HasActor,
HasId

View File

@ -20,10 +20,10 @@ constructor(
val attachment: List<Document> = emptyList(), val attachment: List<Document> = emptyList(),
@JsonDeserialize(contentUsing = ObjectDeserializer::class) @JsonDeserialize(contentUsing = ObjectDeserializer::class)
val tag: List<Object> = emptyList(), val tag: List<Object> = emptyList(),
val quoteUri:String? = null, val quoteUri: String? = null,
val quoteUrl:String? = null, val quoteUrl: String? = null,
@JsonProperty("_misskey_quote") @JsonProperty("_misskey_quote")
val misskeyQuote:String? = null val misskeyQuote: String? = null
) : Object( ) : Object(
type = add(type, "Note") type = add(type, "Note")
), ),
@ -72,20 +72,20 @@ constructor(
override fun toString(): String { override fun toString(): String {
return "Note(" + return "Note(" +
"id='$id', " + "id='$id', " +
"attributedTo='$attributedTo', " + "attributedTo='$attributedTo', " +
"content='$content', " + "content='$content', " +
"published='$published', " + "published='$published', " +
"to=$to, " + "to=$to, " +
"cc=$cc, " + "cc=$cc, " +
"sensitive=$sensitive, " + "sensitive=$sensitive, " +
"inReplyTo=$inReplyTo, " + "inReplyTo=$inReplyTo, " +
"attachment=$attachment, " + "attachment=$attachment, " +
"tag=$tag, " + "tag=$tag, " +
"quoteUri=$quoteUri, " + "quoteUri=$quoteUri, " +
"quoteUrl=$quoteUrl, " + "quoteUrl=$quoteUrl, " +
"misskeyQuote=$misskeyQuote" + "misskeyQuote=$misskeyQuote" +
")" + ")" +
" ${super.toString()}" " ${super.toString()}"
} }
} }

View File

@ -42,7 +42,7 @@ class ObjectDeserializer : JsonDeserializer<Object>() {
ExtendedActivityVocabulary.OrderedCollectionPage -> null ExtendedActivityVocabulary.OrderedCollectionPage -> null
ExtendedActivityVocabulary.Accept -> p.codec.treeToValue(treeNode, Accept::class.java) ExtendedActivityVocabulary.Accept -> p.codec.treeToValue(treeNode, Accept::class.java)
ExtendedActivityVocabulary.Add -> null ExtendedActivityVocabulary.Add -> null
ExtendedActivityVocabulary.Announce -> p.codec.treeToValue(treeNode,Announce::class.java) ExtendedActivityVocabulary.Announce -> p.codec.treeToValue(treeNode, Announce::class.java)
ExtendedActivityVocabulary.Arrive -> null ExtendedActivityVocabulary.Arrive -> null
ExtendedActivityVocabulary.Block -> p.codec.treeToValue(treeNode, Block::class.java) ExtendedActivityVocabulary.Block -> p.codec.treeToValue(treeNode, Block::class.java)
ExtendedActivityVocabulary.Create -> p.codec.treeToValue(treeNode, Create::class.java) ExtendedActivityVocabulary.Create -> p.codec.treeToValue(treeNode, Create::class.java)

View File

@ -35,7 +35,6 @@ class ExposedAnnounceQueryService(
?.let { (it.toAnnounce() ?: return null) to (postResultRowMapper.map(it)) } ?.let { (it.toAnnounce() ?: return null) to (postResultRowMapper.map(it)) }
} }
private suspend fun ResultRow.toAnnounce(): Announce? { private suspend fun ResultRow.toAnnounce(): Announce? {
val repostId = this[Posts.repostId] ?: return null val repostId = this[Posts.repostId] ?: return null
val repost = postRepository.findById(repostId)?.url ?: return null val repost = postRepository.findById(repostId)?.url ?: return null

View File

@ -62,11 +62,12 @@ class NoteQueryServiceImpl(private val postRepository: PostRepository, private v
val repostId = this[Posts.repostId] val repostId = this[Posts.repostId]
val repost = if (repostId != null) { val repost = if (repostId != null) {
val url = postRepository.findById(repostId)?.url val url = postRepository.findById(repostId)?.url
if (url == null){ if (url == null) {
logger.warn("Failed to get repostId: $repostId") logger.warn("Failed to get repostId: $repostId")
} }
url url
}else{ }
else {
null null
} }

View File

@ -9,7 +9,7 @@ import dev.usbharu.hideout.application.external.Transaction
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
@Service @Service
class ApAnnounceProcessor(transaction: Transaction,private val apNoteService:APNoteService) : class ApAnnounceProcessor(transaction: Transaction, private val apNoteService: APNoteService) :
AbstractActivityPubProcessor<Announce>(transaction) { AbstractActivityPubProcessor<Announce>(transaction) {
override suspend fun internalProcess(activity: ActivityPubProcessContext<Announce>) { override suspend fun internalProcess(activity: ActivityPubProcessContext<Announce>) {
apNoteService.fetchAnnounce(activity.activity) apNoteService.fetchAnnounce(activity.activity)

View File

@ -100,7 +100,6 @@ class APNoteServiceImpl(
} }
override suspend fun fetchAnnounce(announce: Announce, signerId: Long?): Pair<Announce, Post> { override suspend fun fetchAnnounce(announce: Announce, signerId: Long?): Pair<Announce, Post> {
val findByApId = announceQueryService.findByApId(announce.id) val findByApId = announceQueryService.findByApId(announce.id)
if (findByApId != null) { if (findByApId != null) {
@ -227,7 +226,6 @@ class APNoteServiceImpl(
mediaIds = mediaList, mediaIds = mediaList,
emojiIds = emojis emojiIds = emojis
) )
} }
val createRemote = postService.createRemote( val createRemote = postService.createRemote(

View File

@ -177,8 +177,8 @@ data class Actor private constructor(
following = following, following = following,
instance = instance, instance = instance,
locked = locked, locked = locked,
followersCount = max(0,followersCount), followersCount = max(0, followersCount),
followingCount = max(0,followingCount), followingCount = max(0, followingCount),
postsCount = max(0, postsCount), postsCount = max(0, postsCount),
lastPostDate = lastPostDate, lastPostDate = lastPostDate,
emojis = emojis emojis = emojis
@ -201,27 +201,27 @@ data class Actor private constructor(
fun withLastPostAt(lastPostDate: Instant): Actor = this.copy(lastPostDate = lastPostDate) fun withLastPostAt(lastPostDate: Instant): Actor = this.copy(lastPostDate = lastPostDate)
override fun toString(): String { override fun toString(): String {
return "Actor(" + return "Actor(" +
"id=$id, " + "id=$id, " +
"name='$name', " + "name='$name', " +
"domain='$domain', " + "domain='$domain', " +
"screenName='$screenName', " + "screenName='$screenName', " +
"description='$description', " + "description='$description', " +
"inbox='$inbox', " + "inbox='$inbox', " +
"outbox='$outbox', " + "outbox='$outbox', " +
"url='$url', " + "url='$url', " +
"publicKey='$publicKey', " + "publicKey='$publicKey', " +
"privateKey=$privateKey, " + "privateKey=$privateKey, " +
"createdAt=$createdAt, " + "createdAt=$createdAt, " +
"keyId='$keyId', " + "keyId='$keyId', " +
"followers=$followers, " + "followers=$followers, " +
"following=$following, " + "following=$following, " +
"instance=$instance, " + "instance=$instance, " +
"locked=$locked, " + "locked=$locked, " +
"followersCount=$followersCount, " + "followersCount=$followersCount, " +
"followingCount=$followingCount, " + "followingCount=$followingCount, " +
"postsCount=$postsCount, " + "postsCount=$postsCount, " +
"lastPostDate=$lastPostDate, " + "lastPostDate=$lastPostDate, " +
"emojis=$emojis" + "emojis=$emojis" +
")" ")"
} }
} }

View File

@ -98,7 +98,6 @@ data class Post private constructor(
repost: Post, repost: Post,
apId: String apId: String
): Post { ): Post {
// リポストの公開範囲は元のポストより広くてはいけない // リポストの公開範囲は元のポストより広くてはいけない
val fixedVisibility = if (visibility.ordinal <= repost.visibility.ordinal) { val fixedVisibility = if (visibility.ordinal <= repost.visibility.ordinal) {
repost.visibility repost.visibility
@ -110,7 +109,6 @@ data class Post private constructor(
require(actorId >= 0) { "actorId must be greater than or equal to 0." } require(actorId >= 0) { "actorId must be greater than or equal to 0." }
return Post( return Post(
id, id,
actorId, actorId,
@ -138,14 +136,13 @@ data class Post private constructor(
createdAt: Instant, createdAt: Instant,
visibility: Visibility, visibility: Visibility,
url: String, url: String,
repost:Post, repost: Post,
replyId: Long? = null, replyId: Long? = null,
sensitive: Boolean = false, sensitive: Boolean = false,
apId: String = url, apId: String = url,
mediaIds: List<Long> = emptyList(), mediaIds: List<Long> = emptyList(),
emojiIds: List<Long> = emptyList() emojiIds: List<Long> = emptyList()
): Post { ): Post {
// リポストの公開範囲は元のポストより広くてはいけない // リポストの公開範囲は元のポストより広くてはいけない
val fixedVisibility = if (visibility.ordinal <= repost.visibility.ordinal) { val fixedVisibility = if (visibility.ordinal <= repost.visibility.ordinal) {
repost.visibility repost.visibility
@ -225,7 +222,7 @@ 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 {