feat: Implement translation of reposts
This commit is contained in:
parent
d5be87992d
commit
ac76e7f435
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue