diff --git a/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/application/accounts/GetAccountApplicationService.kt b/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/application/accounts/GetAccountApplicationService.kt index 0696b53a..6e699fe1 100644 --- a/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/application/accounts/GetAccountApplicationService.kt +++ b/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/application/accounts/GetAccountApplicationService.kt @@ -16,9 +16,9 @@ package dev.usbharu.hideout.mastodon.application.accounts -import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService +import dev.usbharu.hideout.core.application.shared.AbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction -import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser +import dev.usbharu.hideout.core.domain.model.support.principal.Principal import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.Account import dev.usbharu.hideout.mastodon.query.AccountQueryService import org.slf4j.LoggerFactory @@ -26,11 +26,11 @@ import org.springframework.stereotype.Service @Service class GetAccountApplicationService(private val accountQueryService: AccountQueryService, transaction: Transaction) : - LocalUserAbstractApplicationService( + AbstractApplicationService( transaction, logger ) { - override suspend fun internalExecute(command: GetAccount, principal: LocalUser): Account { + override suspend fun internalExecute(command: GetAccount, principal: Principal): Account { return accountQueryService.findById(command.accountId.toLong()) ?: throw IllegalArgumentException("Account ${command.accountId} not found") } diff --git a/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/application/timeline/MastodonReadTimelineApplicationService.kt b/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/application/timeline/MastodonReadTimelineApplicationService.kt index 9858228b..be0319c8 100644 --- a/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/application/timeline/MastodonReadTimelineApplicationService.kt +++ b/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/application/timeline/MastodonReadTimelineApplicationService.kt @@ -69,7 +69,6 @@ class MastodonReadTimelineApplicationService( lastStatusAt = it.postActor.lastPostAt?.toString(), followersCount = it.postActor.followersCount?.relationshipCount, followingCount = it.postActor.followingCount?.relationshipCount, - source = null ), content = it.post.content.content, visibility = when (it.post.visibility) { diff --git a/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/ExposedAccountQueryServiceImpl.kt b/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/ExposedAccountQueryServiceImpl.kt index f4332cc9..4645c3af 100644 --- a/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/ExposedAccountQueryServiceImpl.kt +++ b/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/ExposedAccountQueryServiceImpl.kt @@ -53,10 +53,10 @@ class ExposedAccountQueryServiceImpl(private val applicationConfig: ApplicationC url = resultRow[Actors.url], displayName = resultRow[Actors.screenName], note = resultRow[Actors.description], - avatar = userUrl + "/icon.jpg", - avatarStatic = userUrl + "/icon.jpg", - header = userUrl + "/header.jpg", - headerStatic = userUrl + "/header.jpg", + avatar = "$userUrl/icon.jpg", + avatarStatic = "$userUrl/icon.jpg", + header = "$userUrl/header.jpg", + headerStatic = "$userUrl/header.jpg", locked = resultRow[Actors.locked], fields = emptyList(), emojis = emptyList(), @@ -68,6 +68,10 @@ class ExposedAccountQueryServiceImpl(private val applicationConfig: ApplicationC statusesCount = resultRow[Actors.postsCount], followersCount = resultRow[Actors.followersCount], followingCount = resultRow[Actors.followingCount], + noindex = false, + moved = false, + suspended = resultRow[Actors.suspend], + limited = false, ) } } diff --git a/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/SpringAccountApi.kt b/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/SpringAccountApi.kt index 6723e9ec..caac2717 100644 --- a/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/SpringAccountApi.kt +++ b/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/SpringAccountApi.kt @@ -39,11 +39,16 @@ import dev.usbharu.hideout.core.application.relationship.unfollow.Unfollow import dev.usbharu.hideout.core.application.relationship.unfollow.UserUnfollowApplicationService import dev.usbharu.hideout.core.application.relationship.unmute.Unmute import dev.usbharu.hideout.core.application.relationship.unmute.UserUnmuteApplicationService +import dev.usbharu.hideout.core.domain.model.support.principal.Principal import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.SpringSecurityOauth2PrincipalContextHolder import dev.usbharu.hideout.mastodon.application.accounts.GetAccount import dev.usbharu.hideout.mastodon.application.accounts.GetAccountApplicationService import dev.usbharu.hideout.mastodon.interfaces.api.generated.AccountApi import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.* +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.asFlow +import kotlinx.coroutines.flow.mapNotNull +import kotlinx.coroutines.runBlocking import org.springframework.http.ResponseEntity import org.springframework.stereotype.Controller @@ -66,27 +71,30 @@ class SpringAccountApi( ) : AccountApi { override suspend fun apiV1AccountsIdBlockPost(id: String): ResponseEntity { - userBlockApplicationService.execute(Block(id.toLong()), principalContextHolder.getPrincipal()) - return fetchRelationship(id) + val principal = principalContextHolder.getPrincipal() + userBlockApplicationService.execute(Block(id.toLong()), principal) + return fetchRelationship(id, principal) } override suspend fun apiV1AccountsIdFollowPost( id: String, followRequestBody: FollowRequestBody?, ): ResponseEntity { + val principal = principalContextHolder.getPrincipal() userFollowRequestApplicationService.execute( FollowRequest(id.toLong()), - principalContextHolder.getPrincipal() + principal ) - return fetchRelationship(id) + return fetchRelationship(id, principal) } private suspend fun fetchRelationship( id: String, + principal: Principal ): ResponseEntity { val relationship = getRelationshipApplicationService.execute( GetRelationship(id.toLong()), - principalContextHolder.getPrincipal() + principal ) return ResponseEntity.ok( Relationship( @@ -117,43 +125,56 @@ class SpringAccountApi( } override suspend fun apiV1AccountsIdMutePost(id: String): ResponseEntity { + val principal = principalContextHolder.getPrincipal() userMuteApplicationService.execute( Mute(id.toLong()), - principalContextHolder.getPrincipal() + principal ) - return fetchRelationship(id) + return fetchRelationship(id, principal) } override suspend fun apiV1AccountsIdRemoveFromFollowersPost(id: String): ResponseEntity { + val principal = principalContextHolder.getPrincipal() userRemoveFromFollowersApplicationService.execute( RemoveFromFollowers(id.toLong()), - principalContextHolder.getPrincipal() + principal ) - return fetchRelationship(id) + return fetchRelationship(id, principal) } override suspend fun apiV1AccountsIdUnblockPost(id: String): ResponseEntity { + val principal = principalContextHolder.getPrincipal() userUnblockApplicationService.execute( Unblock(id.toLong()), - principalContextHolder.getPrincipal() + principal ) - return fetchRelationship(id) + return fetchRelationship(id, principal) } override suspend fun apiV1AccountsIdUnfollowPost(id: String): ResponseEntity { + val principal = principalContextHolder.getPrincipal() userUnfollowApplicationService.execute( Unfollow(id.toLong()), - principalContextHolder.getPrincipal() + principal ) - return fetchRelationship(id) + return fetchRelationship(id, principal) + } + + override fun apiV1AccountsRelationshipsGet( + id: List?, + withSuspended: Boolean + ): ResponseEntity> { + val principal = runBlocking { principalContextHolder.getPrincipal() } + return ResponseEntity.ok(id.orEmpty().asFlow().mapNotNull { fetchRelationship(it, principal).body }) } override suspend fun apiV1AccountsIdUnmutePost(id: String): ResponseEntity { + val principal = principalContextHolder.getPrincipal() userUnmuteApplicationService.execute( Unmute(id.toLong()), - principalContextHolder.getPrincipal() + principal ) - return fetchRelationship(id) + return fetchRelationship(id, principal) } override suspend fun apiV1AccountsPost(accountsCreateRequest: AccountsCreateRequest): ResponseEntity = @@ -220,18 +241,20 @@ class SpringAccountApi( } override suspend fun apiV1FollowRequestsAccountIdAuthorizePost(accountId: String): ResponseEntity { + val principal = principalContextHolder.getPrincipal() userAcceptFollowRequestApplicationService.execute( AcceptFollowRequest(accountId.toLong()), - principalContextHolder.getPrincipal() + principal ) - return fetchRelationship(accountId) + return fetchRelationship(accountId, principal) } override suspend fun apiV1FollowRequestsAccountIdRejectPost(accountId: String): ResponseEntity { + val principal = principalContextHolder.getPrincipal() userRejectFollowRequestApplicationService.execute( RejectFollowRequest(accountId.toLong()), - principalContextHolder.getPrincipal() + principal ) - return fetchRelationship(accountId) + return fetchRelationship(accountId, principal) } } diff --git a/hideout-mastodon/src/main/resources/openapi/mastodon.yaml b/hideout-mastodon/src/main/resources/openapi/mastodon.yaml index 1fb96267..4461417e 100644 --- a/hideout-mastodon/src/main/resources/openapi/mastodon.yaml +++ b/hideout-mastodon/src/main/resources/openapi/mastodon.yaml @@ -1597,8 +1597,6 @@ components: type: integer following_count: type: integer - source: - $ref: "#/components/schemas/AccountSource" required: - id