summaryrefslogtreecommitdiff
path: root/Hutch/Views/Inbox/InboxViewModel.swift
diff options
context:
space:
mode:
Diffstat (limited to 'Hutch/Views/Inbox/InboxViewModel.swift')
-rw-r--r--Hutch/Views/Inbox/InboxViewModel.swift25
1 files changed, 23 insertions, 2 deletions
diff --git a/Hutch/Views/Inbox/InboxViewModel.swift b/Hutch/Views/Inbox/InboxViewModel.swift
index edb7593..a01f836 100644
--- a/Hutch/Views/Inbox/InboxViewModel.swift
+++ b/Hutch/Views/Inbox/InboxViewModel.swift
@@ -56,12 +56,19 @@ private struct InboxEmailPreview: Decodable, Sendable {
let patch: InboxPatchPreview?
}
+enum InboxThreadFilter: String, CaseIterable, Sendable {
+ case all = "All"
+ case patches = "Patches"
+ case discussions = "Talk"
+}
+
@Observable
@MainActor
final class InboxViewModel {
private(set) var threads: [InboxThreadSummary] = []
private(set) var isLoading = false
var error: String?
+ var filter: InboxThreadFilter = .all
var searchText = ""
private let client: SRHTClient
@@ -181,9 +188,10 @@ final class InboxViewModel {
}
var filteredThreads: [InboxThreadSummary] {
+ let filteredByKind = Self.filterThreads(threads, filter: filter)
let q = searchText.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
- guard !q.isEmpty else { return threads }
- return threads.filter {
+ guard !q.isEmpty else { return filteredByKind }
+ return filteredByKind.filter {
$0.displaySubject.lowercased().contains(q) ||
$0.listName.lowercased().contains(q) ||
$0.latestSender.canonicalName.lowercased().contains(q)
@@ -389,4 +397,17 @@ final class InboxViewModel {
}
return nil
}
+
+ nonisolated static func filterThreads(_ threads: [InboxThreadSummary], filter: InboxThreadFilter) -> [InboxThreadSummary] {
+ threads.filter { thread in
+ switch filter {
+ case .all:
+ return true
+ case .patches:
+ return thread.containsPatch
+ case .discussions:
+ return !thread.containsPatch
+ }
+ }
+ }
}