diff options
| author | Christian Cleberg <[email protected]> | 2026-04-20 13:04:57 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-04-20 13:04:57 -0500 |
| commit | 8b73fd9cd43753b36b3ab3ca5e4dc83a47ea3480 (patch) | |
| tree | 25658dbdc28775764f5745576c240efd38fd4685 /Hutch/Views/Projects | |
| parent | d29fbef60abdffaee190b758530dde9212745ed2 (diff) | |
| download | hutch-8b73fd9cd43753b36b3ab3ca5e4dc83a47ea3480.tar.gz hutch-8b73fd9cd43753b36b3ab3ca5e4dc83a47ea3480.tar.bz2 hutch-8b73fd9cd43753b36b3ab3ca5e4dc83a47ea3480.zip | |
fix: add mark all read actions and avoid resending unchanged repo metadata
Diffstat (limited to 'Hutch/Views/Projects')
| -rw-r--r-- | Hutch/Views/Projects/ProjectMailingListView.swift | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/Hutch/Views/Projects/ProjectMailingListView.swift b/Hutch/Views/Projects/ProjectMailingListView.swift index d7c0abc..ca6066c 100644 --- a/Hutch/Views/Projects/ProjectMailingListView.swift +++ b/Hutch/Views/Projects/ProjectMailingListView.swift @@ -105,6 +105,39 @@ final class MailingListDetailViewModel { NeedsAttentionSnapshotStore.adjustUnreadInboxThreads(by: 1, accountID: accountID) } + func markAllThreadsRead() { + let unreadThreads = threads.filter(\.isUnread) + guard !unreadThreads.isEmpty else { return } + + let viewedAt = Date() + for thread in unreadThreads { + InboxReadStateStore.markViewed(max(viewedAt, thread.lastActivityAt), for: thread.id, defaults: defaults) + } + + threads = threads.map { thread in + guard thread.isUnread else { return thread } + return InboxThreadSummary( + rootEmailID: thread.rootEmailID, + rootMessageID: thread.rootMessageID, + threadRootEmailIDs: thread.threadRootEmailIDs, + threadRootMessageIDs: thread.threadRootMessageIDs, + listID: thread.listID, + listRID: thread.listRID, + listName: thread.listName, + listOwner: thread.listOwner, + subject: thread.subject, + latestSender: thread.latestSender, + lastActivityAt: thread.lastActivityAt, + messageCount: thread.messageCount, + repo: thread.repo, + containsPatch: thread.containsPatch, + isUnread: false + ) + } + + NeedsAttentionSnapshotStore.adjustUnreadInboxThreads(by: -unreadThreads.count, accountID: accountID) + } + private func makeSummary(from thread: ProjectMailingListThreadPayload) -> InboxThreadSummary { let normalizedSubject = thread.subject .replacingOccurrences(of: #"\s+"#, with: " ", options: .regularExpression) @@ -241,6 +274,10 @@ struct MailingListDetailView: View { return HomePinStore.isPinned(.mailingList(mailingList), for: currentUserKey, defaults: appState.accountDefaults) } + private var hasUnreadThreads: Bool { + viewModel?.threads.contains(where: \.isUnread) == true + } + var body: some View { Group { if let viewModel { @@ -252,6 +289,12 @@ struct MailingListDetailView: View { .navigationTitle(mailingList.name) .navigationBarTitleDisplayMode(.inline) .toolbar { + ToolbarItem(placement: .topBarTrailing) { + Button("Mark All Read") { + viewModel?.markAllThreadsRead() + } + .disabled(hasUnreadThreads == false) + } if currentUserKey != nil { ToolbarItem(placement: .topBarTrailing) { Button { @@ -299,16 +342,13 @@ struct MailingListDetailView: View { ThreadDetailView( thread: thread, onViewed: { - InboxReadStateStore.markViewed(max(Date(), thread.lastActivityAt), for: thread.id, defaults: appState.accountDefaults) - NeedsAttentionSnapshotStore.adjustUnreadInboxThreads(by: -1, accountID: appState.activeAccountID) + viewModel.markThreadRead(thread) }, onMarkRead: { - InboxReadStateStore.markViewed(max(Date(), thread.lastActivityAt), for: thread.id, defaults: appState.accountDefaults) - NeedsAttentionSnapshotStore.adjustUnreadInboxThreads(by: -1, accountID: appState.activeAccountID) + viewModel.markThreadRead(thread) }, onMarkUnread: { - InboxReadStateStore.markUnread(for: thread.id, defaults: appState.accountDefaults) - NeedsAttentionSnapshotStore.adjustUnreadInboxThreads(by: 1, accountID: appState.activeAccountID) + viewModel.markThreadUnread(thread) } ) } label: { |
