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 return
} }
let result = try await provider.context func translate(status: Status) async throws -> String? {
.apiService let value = try await provider.context
.translateStatus( .apiService
statusID: status.id, .translateStatus(
authenticationBox: provider.authContext.mastodonAuthenticationBox statusID: status.id,
).value 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) self?.configureTranslated(status: status)
} }
.store(in: &disposeBag) .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) { func configureTranslated(status: Status) {
let translatedContent: String? = {
if let translatedContent = status.reblog?.translatedContent {
return translatedContent
}
return status.translatedContent
}()
guard guard
let translatedContent = status.translatedContent let translatedContent = translatedContent
else { return } else {
return
}
// content // content
do { do {