summaryrefslogtreecommitdiff
path: root/Hutch/Views
diff options
context:
space:
mode:
Diffstat (limited to 'Hutch/Views')
-rw-r--r--Hutch/Views/Home/HomeViewModel.swift13
-rw-r--r--Hutch/Views/Projects/ProjectMailingListView.swift21
2 files changed, 28 insertions, 6 deletions
diff --git a/Hutch/Views/Home/HomeViewModel.swift b/Hutch/Views/Home/HomeViewModel.swift
index 98dd968..a3aed30 100644
--- a/Hutch/Views/Home/HomeViewModel.swift
+++ b/Hutch/Views/Home/HomeViewModel.swift
@@ -819,6 +819,14 @@ final class HomeViewModel {
var cursor: String?
var unreadThreads: [InboxThreadSummary] = []
+ // thread.updated is the root email's insert time and never advances when a
+ // reply lands, so activity has to come from the list's mail feed.
+ let activity = await MailingListActivityLoader.load(
+ client: client,
+ listRID: mailingList.rid,
+ since: InboxReadStateStore.baseline(defaults: defaults) ?? .distantPast
+ )
+
while true {
var variables: [String: any Sendable] = ["rid": mailingList.rid]
if let cursor {
@@ -838,6 +846,7 @@ final class HomeViewModel {
let response = cached.value
let unreadThreadSummaries = response.list.threads.results.compactMap { thread -> InboxThreadSummary? in
+ let lastActivityAt = activity.lastActivity(rootEmailID: thread.root.id, fallback: thread.updated)
let summary = InboxThreadSummary(
rootEmailID: thread.root.id,
rootMessageID: thread.root.messageID,
@@ -849,13 +858,13 @@ final class HomeViewModel {
listOwner: mailingList.owner,
subject: thread.subject,
latestSender: thread.sender,
- lastActivityAt: thread.updated,
+ lastActivityAt: lastActivityAt,
messageCount: thread.replies + 1,
repo: InboxThreadUtilities.deriveRepositoryName(from: mailingList.name),
containsPatch: thread.root.patch != nil || thread.subject.localizedCaseInsensitiveContains("[patch"),
isUnread: InboxReadStateStore.isUnread(
threadID: "\(mailingList.rid)#\(InboxThreadSummary.normalizationKey(for: thread.subject))",
- lastActivityAt: thread.updated,
+ lastActivityAt: lastActivityAt,
defaults: defaults
)
)
diff --git a/Hutch/Views/Projects/ProjectMailingListView.swift b/Hutch/Views/Projects/ProjectMailingListView.swift
index d466121..e4c9df4 100644
--- a/Hutch/Views/Projects/ProjectMailingListView.swift
+++ b/Hutch/Views/Projects/ProjectMailingListView.swift
@@ -84,8 +84,14 @@ final class MailingListDetailViewModel {
responseType: ProjectMailingListThreadsResponse.self
)
+ let activity = await MailingListActivityLoader.load(
+ client: client,
+ listRID: mailingList.rid,
+ since: InboxReadStateStore.baseline(defaults: defaults) ?? .distantPast
+ )
+
threads = deduplicateThreads(
- response.list.threads.results.map(makeSummary(from:))
+ response.list.threads.results.map { makeSummary(from: $0, activity: activity) }
)
} catch {
self.error = "Failed to load mailing list"
@@ -138,7 +144,10 @@ final class MailingListDetailViewModel {
NeedsAttentionSnapshotStore.adjustUnreadInboxThreads(by: -unreadThreads.count, accountID: accountID)
}
- private func makeSummary(from thread: ProjectMailingListThreadPayload) -> InboxThreadSummary {
+ private func makeSummary(
+ from thread: ProjectMailingListThreadPayload,
+ activity: MailingListActivity
+ ) -> InboxThreadSummary {
let normalizedSubject = thread.subject
.replacingOccurrences(of: #"\s+"#, with: " ", options: .regularExpression)
.trimmingCharacters(in: .whitespacesAndNewlines)
@@ -146,6 +155,10 @@ final class MailingListDetailViewModel {
.lowercased()
let threadID = "\(mailingList.rid)#\(normalizedSubject)"
+ // thread.updated is the root email's insert time and never advances when a
+ // reply lands, so activity has to come from the list's mail feed.
+ let lastActivityAt = activity.lastActivity(rootEmailID: thread.root.id, fallback: thread.updated)
+
return InboxThreadSummary(
rootEmailID: thread.root.id,
rootMessageID: thread.root.messageID,
@@ -157,11 +170,11 @@ final class MailingListDetailViewModel {
listOwner: mailingList.owner,
subject: thread.subject,
latestSender: thread.sender,
- lastActivityAt: thread.updated,
+ lastActivityAt: lastActivityAt,
messageCount: thread.replies + 1,
repo: nil,
containsPatch: thread.root.patch != nil || thread.subject.localizedCaseInsensitiveContains("[patch"),
- isUnread: InboxReadStateStore.isUnread(threadID: threadID, lastActivityAt: thread.updated, defaults: defaults)
+ isUnread: InboxReadStateStore.isUnread(threadID: threadID, lastActivityAt: lastActivityAt, defaults: defaults)
)
}