summaryrefslogtreecommitdiff
path: root/Hutch/Views/Inbox/InboxViewModel.swift
diff options
context:
space:
mode:
authorChristian Cleberg <[email protected]>2026-04-12 23:19:20 -0500
committerChristian Cleberg <[email protected]>2026-04-12 23:19:20 -0500
commitee9f2904aa319231b7047fca3cb069f0c07019cd (patch)
tree69a18234512c63f38f0d477e0023969698ec3c9e /Hutch/Views/Inbox/InboxViewModel.swift
parent72f860e0e171f6aac4e7d896e7a571147dbcb5c5 (diff)
downloadhutch-ee9f2904aa319231b7047fca3cb069f0c07019cd.tar.gz
hutch-ee9f2904aa319231b7047fca3cb069f0c07019cd.tar.bz2
hutch-ee9f2904aa319231b7047fca3cb069f0c07019cd.zip
feat: add multi-account support
Implements: https://todo.sr.ht/~ccleberg/hutch/49 Implements: https://todo.sr.ht/~ccleberg/hutch/50 Implements: https://todo.sr.ht/~ccleberg/hutch/51
Diffstat (limited to 'Hutch/Views/Inbox/InboxViewModel.swift')
-rw-r--r--Hutch/Views/Inbox/InboxViewModel.swift22
1 files changed, 13 insertions, 9 deletions
diff --git a/Hutch/Views/Inbox/InboxViewModel.swift b/Hutch/Views/Inbox/InboxViewModel.swift
index a01f836..8fff2dc 100644
--- a/Hutch/Views/Inbox/InboxViewModel.swift
+++ b/Hutch/Views/Inbox/InboxViewModel.swift
@@ -72,6 +72,8 @@ final class InboxViewModel {
var searchText = ""
private let client: SRHTClient
+ private let defaults: UserDefaults
+ private let accountID: String
private let listThreadFetchLimit = 10
private let listFetchConcurrencyLimit = 4
@@ -121,8 +123,10 @@ final class InboxViewModel {
}
"""
- init(client: SRHTClient) {
+ init(client: SRHTClient, defaults: UserDefaults, accountID: String) {
self.client = client
+ self.defaults = defaults
+ self.accountID = accountID
}
func loadThreads() async {
@@ -143,7 +147,7 @@ final class InboxViewModel {
}
return lhs.lastActivityAt > rhs.lastActivityAt
}
- NeedsAttentionSnapshotStore.update(unreadInboxThreads: threads.count)
+ NeedsAttentionSnapshotStore.update(unreadInboxThreads: threads.count, accountID: accountID)
} catch {
inboxListLogger.error("Inbox request failed")
self.error = "Failed to load inbox"
@@ -152,9 +156,9 @@ final class InboxViewModel {
func markThreadRead(_ thread: InboxThreadSummary) {
let viewedAt = max(Date(), thread.lastActivityAt)
- InboxReadStateStore.markViewed(viewedAt, for: thread.id)
+ InboxReadStateStore.markViewed(viewedAt, for: thread.id, defaults: defaults)
threads.removeAll { $0.id == thread.id }
- NeedsAttentionSnapshotStore.adjustUnreadInboxThreads(by: -1)
+ NeedsAttentionSnapshotStore.adjustUnreadInboxThreads(by: -1, accountID: accountID)
}
func markAllThreadsRead() {
@@ -162,17 +166,17 @@ final class InboxViewModel {
let viewedAt = Date()
for thread in threads where thread.isUnread {
- InboxReadStateStore.markViewed(max(viewedAt, thread.lastActivityAt), for: thread.id)
+ InboxReadStateStore.markViewed(max(viewedAt, thread.lastActivityAt), for: thread.id, defaults: defaults)
}
threads.removeAll { $0.isUnread }
- NeedsAttentionSnapshotStore.update(unreadInboxThreads: threads.count)
+ NeedsAttentionSnapshotStore.update(unreadInboxThreads: threads.count, accountID: accountID)
}
func markThreadUnread(_ thread: InboxThreadSummary) {
- InboxReadStateStore.markUnread(for: thread.id)
+ InboxReadStateStore.markUnread(for: thread.id, defaults: defaults)
updateThread(thread, isUnread: true)
- NeedsAttentionSnapshotStore.adjustUnreadInboxThreads(by: 1)
+ NeedsAttentionSnapshotStore.adjustUnreadInboxThreads(by: 1, accountID: accountID)
}
func toggleThreadReadState(_ thread: InboxThreadSummary) {
@@ -291,7 +295,7 @@ final class InboxViewModel {
return response.list.threads.results.prefix(listThreadFetchLimit).map { thread in
let groupingKey = "\(mailingList.rid)#\(thread.subject.replacingOccurrences(of: #"\s+"#, with: " ", options: .regularExpression).trimmingCharacters(in: .whitespacesAndNewlines).replacingOccurrences(of: #"^(?:(?:re|fwd?)\s*:\s*)+"#, with: "", options: [.regularExpression, .caseInsensitive]).lowercased())"
- let isUnread = InboxReadStateStore.isUnread(threadID: groupingKey, lastActivityAt: thread.updated)
+ let isUnread = InboxReadStateStore.isUnread(threadID: groupingKey, lastActivityAt: thread.updated, defaults: defaults)
return InboxThreadSummary(
rootEmailID: thread.root.id,
rootMessageID: thread.root.messageID,