feat: Implement translation of reposts

This commit is contained in:
Marcus Kida 2022-12-02 14:42:50 +01:00
parent d5be87992d
commit ac76e7f435
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
2 changed files with 34 additions and 9 deletions

View File

@ -24,13 +24,20 @@ extension DataSourceFacade {
return
}
let result = try await provider.context
.apiService
.translateStatus(
statusID: status.id,
authenticationBox: provider.authContext.mastodonAuthenticationBox
).value
func translate(status: Status) async throws -> String? {
let value = try await provider.context
.apiService
.translateStatus(
statusID: status.id,
authenticationBox: provider.authContext.mastodonAuthenticationBox
).value
return value.content
}
status.translatedContent = result.content
if let reblog = status.reblog {
reblog.translatedContent = try await translate(status: reblog)
} else {
status.translatedContent = try await translate(status: status)
}
}
}

View File

@ -63,6 +63,14 @@ extension StatusView {
self?.configureTranslated(status: status)
}
.store(in: &disposeBag)
status.reblog?.$translatedContent
.receive(on: DispatchQueue.main)
.compactMap { $0 }
.sink { [weak self] _ in
self?.configureTranslated(status: status)
}
.store(in: &disposeBag)
}
}
@ -240,9 +248,19 @@ extension StatusView {
}
func configureTranslated(status: Status) {
let translatedContent: String? = {
if let translatedContent = status.reblog?.translatedContent {
return translatedContent
}
return status.translatedContent
}()
guard
let translatedContent = status.translatedContent
else { return }
let translatedContent = translatedContent
else {
return
}
// content
do {