Add optional language filter on Universe feed
This commit is contained in:
@@ -153,6 +153,8 @@ struct ConfigView: View {
|
||||
}
|
||||
|
||||
Section(NSLocalizedString("Translations", comment: "Section title for selecting the translation service.")) {
|
||||
Toggle(NSLocalizedString("Show only preferred languages on Universe feed", comment: "Toggle to show notes that are only in the device's preferred languages on the Universe feed and hide notes that are in other languages."), isOn: $settings.show_only_preferred_languages)
|
||||
.toggleStyle(.switch)
|
||||
Picker(NSLocalizedString("Service", comment: "Prompt selection of translation service provider."), selection: $settings.translation_service) {
|
||||
ForEach(TranslationService.allCases, id: \.self) { server in
|
||||
Text(server.model.displayName)
|
||||
|
||||
@@ -7,12 +7,15 @@
|
||||
|
||||
import SwiftUI
|
||||
import CryptoKit
|
||||
import NaturalLanguage
|
||||
|
||||
struct SearchHomeView: View {
|
||||
let damus_state: DamusState
|
||||
@StateObject var model: SearchHomeModel
|
||||
@State var search: String = ""
|
||||
@FocusState private var isFocused: Bool
|
||||
|
||||
let preferredLanguages = Set(Locale.preferredLanguages.map { localeToLanguage($0) })
|
||||
|
||||
var SearchInput: some View {
|
||||
HStack {
|
||||
@@ -41,12 +44,29 @@ struct SearchHomeView: View {
|
||||
}
|
||||
|
||||
var GlobalContent: some View {
|
||||
return TimelineView(events: model.events, loading: $model.loading, damus: damus_state, show_friend_icon: true, filter: { _ in true })
|
||||
.refreshable {
|
||||
// Fetch new information by unsubscribing and resubscribing to the relay
|
||||
model.unsubscribe()
|
||||
model.subscribe()
|
||||
return TimelineView(
|
||||
events: model.events,
|
||||
loading: $model.loading,
|
||||
damus: damus_state,
|
||||
show_friend_icon: true,
|
||||
filter: {
|
||||
if damus_state.settings.show_only_preferred_languages == false {
|
||||
return true
|
||||
}
|
||||
|
||||
// If we can't determine the note's language with 50%+ confidence, lean on the side of caution and show it anyway.
|
||||
guard let noteLanguage = $0.note_language(damus_state.keypair.privkey) else {
|
||||
return true
|
||||
}
|
||||
|
||||
return preferredLanguages.contains(noteLanguage)
|
||||
}
|
||||
)
|
||||
.refreshable {
|
||||
// Fetch new information by unsubscribing and resubscribing to the relay
|
||||
model.unsubscribe()
|
||||
model.subscribe()
|
||||
}
|
||||
}
|
||||
|
||||
var SearchContent: some View {
|
||||
|
||||
Reference in New Issue
Block a user