mirror of https://github.com/usbharu/Hideout.git
fix: ActivityPubのidが重複した際の処理を修正
This commit is contained in:
parent
d3d91fc2bc
commit
1a63ae104c
|
@ -20,4 +20,5 @@ interface IPostRepository {
|
|||
userId: Long?): List<Post>
|
||||
|
||||
suspend fun findByUserId(idOrNull: Long, since: Instant?, until: Instant?, minId: Long?, maxId: Long?, limit: Int?, userId: Long?): List<Post>
|
||||
suspend fun findByApId(id: String): Post?
|
||||
}
|
||||
|
|
|
@ -89,6 +89,12 @@ class PostRepositoryImpl(database: Database, private val idGenerateService: IdGe
|
|||
override suspend fun findByUserId(idOrNull: Long, since: Instant?, until: Instant?, minId: Long?, maxId: Long?, limit: Int?, userId: Long?): List<Post> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun findByApId(id: String): Post? {
|
||||
return query {
|
||||
Posts.select { Posts.apId eq id }.singleOrNull()?.toPost()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object Posts : Table() {
|
||||
|
|
|
@ -72,6 +72,17 @@ class ActivityPubNoteServiceImpl(
|
|||
override suspend fun fetchNote(url: String, targetActor: String?): Note {
|
||||
val post = postRepository.findByUrl(url)
|
||||
if (post != null) {
|
||||
return postToNote(post)
|
||||
}
|
||||
val response = httpClient.getAp(
|
||||
url,
|
||||
"$targetActor#pubkey"
|
||||
)
|
||||
val note = response.body<Note>()
|
||||
return note(note, targetActor, url)
|
||||
}
|
||||
|
||||
private suspend fun postToNote(post: Post): Note {
|
||||
val user = userService.findById(post.userId)
|
||||
val reply = post.replyId?.let { postRepository.findOneById(it) }
|
||||
return Note(
|
||||
|
@ -86,19 +97,16 @@ class ActivityPubNoteServiceImpl(
|
|||
inReplyTo = reply?.url
|
||||
)
|
||||
}
|
||||
val response = httpClient.getAp(
|
||||
url,
|
||||
"$targetActor#pubkey"
|
||||
)
|
||||
val note = response.body<Note>()
|
||||
return note(note, targetActor, url)
|
||||
}
|
||||
|
||||
private suspend fun ActivityPubNoteServiceImpl.note(
|
||||
note: Note,
|
||||
targetActor: String?,
|
||||
url: String
|
||||
): Note {
|
||||
val findByApId = postRepository.findByApId(url)
|
||||
if (findByApId != null) {
|
||||
return postToNote(findByApId)
|
||||
}
|
||||
val person = activityPubUserService.fetchPerson(
|
||||
note.attributedTo ?: throw IllegalActivityPubObjectException("note.attributedTo is null"),
|
||||
targetActor
|
||||
|
|
Loading…
Reference in New Issue