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