Skip to content

Commit

Permalink
feat: resolveする時にresolve先のユーザであればそのまま参照するようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
pantasystem committed Jul 16, 2023
1 parent 9b20d4b commit f971aeb
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package net.pantasystem.milktea.model.ap

import net.pantasystem.milktea.common.mapCancellableCatching
import net.pantasystem.milktea.common.runCancellableCatching
import net.pantasystem.milktea.model.account.AccountRepository
import net.pantasystem.milktea.model.notes.Note
import net.pantasystem.milktea.model.notes.NoteRepository
import net.pantasystem.milktea.model.user.User
import net.pantasystem.milktea.model.user.UserRepository
import javax.inject.Inject

class ApResolverService @Inject constructor(
private val apResolverRepository: ApResolverRepository,
private val noteRepository: NoteRepository,
private val userRepository: UserRepository,
private val accountRepository: AccountRepository,
) {

suspend fun resolve(noteId: Note.Id, resolveToAccountId: Long): Result<Note> {
Expand All @@ -25,5 +29,20 @@ class ApResolverService @Inject constructor(
}
}


suspend fun resolve(userId: User.Id, resolveToAccountId: Long): Result<User> = runCancellableCatching {
val user = (userRepository.find(userId, true) as User.Detail)
val resolveAccount = accountRepository.get(resolveToAccountId).getOrThrow()
if (resolveAccount.getHost() == user.host) {
return@runCancellableCatching userRepository.findByUserName(resolveToAccountId, user.userName, user.host)
}
val uri = user.getRemoteProfileUrl(
accountRepository.get(userId.accountId).getOrThrow()
)
apResolverRepository.resolve(resolveToAccountId, uri).mapCancellableCatching {
when (it) {
is ApResolver.TypeNote -> throw IllegalStateException("Cannot resolve note")
is ApResolver.TypeUser -> it.user
}
}.getOrThrow()
}
}

0 comments on commit f971aeb

Please sign in to comment.