Skip to content
TypeScript

fix: show latest reply age in active thread rows (#31825)

shivam08a3909406bf
diff --git a/apps/mobile/src/features/threads/threadListV2.test.ts b/apps/mobile/src/features/threads/threadListV2.test.ts
index a88f0ddc10a..786f1ce2291 100644
--- a/apps/mobile/src/features/threads/threadListV2.test.ts
+++ b/apps/mobile/src/features/threads/threadListV2.test.ts
@@ -1562,6 +1562,30 @@ describe("buildThreadListV2ListItems row-state stamps", () => {
});
const allEnvironments = new Set<EnvironmentId>([environmentId]);
+ it("ages a read row from its latest reply", () => {
+ using _timers = { [Symbol.dispose]: () => vi.useRealTimers() };
+ vi.useFakeTimers({ now: BASE_MS });
+ const label = (latestUserMessageAt: string, completedAt: string) => {
+ const thread = makeThread({
+ id: ThreadId.make("stamp-read"),
+ title: "stamp read",
+ latestUserMessageAt,
+ lastVisitedAt: isoAt(BASE_MS),
+ latestRun: {
+ runId: RunId.make("stamp-read-run"),
+ status: "completed",
+ requestedAt: latestUserMessageAt,
+ startedAt: latestUserMessageAt,
+ completedAt,
+ assistantMessageId: null,
+ },
+ });
+ const row = buildTickList([thread], BASE_MS, [])[0]!;
+ return row.type === "v2-thread" ? row.timeLabel : null;
+ };
+ expect(label(isoAt(BASE_MS - 40 * MINUTE_MS), isoAt(BASE_MS - 2 * MINUTE_MS))).toBe("2m");
+ });
+
it("stamps queued outbox messages onto the matching row and notices removal", () => {
const queued = buildTickList([readyThread, settledThread], BASE_MS, [], {
queuedThreadKeys: new Set([`${environmentId}:stamp-ready`]),
diff --git a/apps/mobile/src/features/threads/threadListV2.ts b/apps/mobile/src/features/threads/threadListV2.ts
index 1b79c9a15d6..3245c1c281e 100644
--- a/apps/mobile/src/features/threads/threadListV2.ts
+++ b/apps/mobile/src/features/threads/threadListV2.ts
@@ -25,6 +25,7 @@ import {
import {
sortActiveThreadsByOrderKey,
resolveSettledThreadTimestamp,
+ resolveThreadActivityTimestamp,
sortPinnedThreadsByOrderKey,
sortSettledThreads,
} from "@t3tools/client-runtime/state/thread-sort";
@@ -513,7 +514,7 @@ function resolveThreadListV2ItemTimeLabel(
const settledTimestamp =
variant === "slim" && !snoozed ? resolveSettledThreadTimestamp(thread) : null;
return relativeTime(
- settledTimestamp ?? thread.latestUserMessageAt ?? thread.updatedAt ?? thread.createdAt,
+ settledTimestamp ?? resolveThreadActivityTimestamp(thread) ?? thread.createdAt,
);
}
diff --git a/apps/web/src/components/sidebar/SidebarThreadRow.tsx b/apps/web/src/components/sidebar/SidebarThreadRow.tsx
index f0c45198774..41cb733daff 100644
--- a/apps/web/src/components/sidebar/SidebarThreadRow.tsx
+++ b/apps/web/src/components/sidebar/SidebarThreadRow.tsx
@@ -13,7 +13,10 @@ import {
QUEUED_TURN_START_GRACE_MS,
} from "@t3tools/client-runtime/state/thread-settled";
import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
-import { resolveSettledThreadTimestamp } from "@t3tools/client-runtime/state/thread-sort";
+import {
+ resolveSettledThreadTimestamp,
+ resolveThreadActivityTimestamp,
+} from "@t3tools/client-runtime/state/thread-sort";
import { type EnvironmentThreadSearchMatch } from "@t3tools/client-runtime/state/thread-search";
import {
formatWorkingDurationLabel,
@@ -145,10 +148,6 @@ function RelativeTimeLabel(props: { timestamp: string | null }) {
);
}
-function threadTimeTimestamp(thread: SidebarThreadSummary): string {
- return thread.latestUserMessageAt ?? thread.updatedAt;
-}
-
function JumpHintBadge(props: { label: string }) {
return (
<Kbd aria-hidden data-jump-hint>
@@ -1318,7 +1317,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
timestamp={
variantAction === "unsettle"
? resolveSettledThreadTimestamp(thread)
- : threadTimeTimestamp(thread)
+ : resolveThreadActivityTimestamp(thread)
}
/>
</span>
@@ -1513,7 +1512,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
</span>
)
) : (
- <RelativeTimeLabel timestamp={threadTimeTimestamp(thread)} />
+ <RelativeTimeLabel timestamp={resolveThreadActivityTimestamp(thread)} />
)}
</span>
{props.settlementSupported || showSnoozeButton || hasUnsentDraft ? (
@@ -1752,7 +1751,7 @@ export const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props
/>
</span>
<span className="w-8 shrink-0 text-right text-xs text-muted-foreground/55 tabular-nums">
- <RelativeTimeLabel timestamp={threadTimeTimestamp(thread)} />
+ <RelativeTimeLabel timestamp={resolveThreadActivityTimestamp(thread)} />
</span>
</span>
{props.searchMatch ? (
diff --git a/packages/client-runtime/src/state/threadSort.ts b/packages/client-runtime/src/state/threadSort.ts
index 5d258ed95b9..89b412a2c5d 100644
--- a/packages/client-runtime/src/state/threadSort.ts
+++ b/packages/client-runtime/src/state/threadSort.ts
@@ -27,7 +27,12 @@ export function resolveSettledThreadTimestamp(thread: SettledThreadTimestampInpu
if (thread.settledAt != null && toSortableTimestamp(thread.settledAt) !== null) {
return thread.settledAt;
}
+ return resolveThreadActivityTimestamp(thread);
+}
+export function resolveThreadActivityTimestamp(
+ thread: Pick<EnvironmentThreadShell, "latestUserMessageAt" | "latestRun" | "updatedAt">,
+): string | null {
let latest: string | null = null;
let latestMs = Number.NEGATIVE_INFINITY;
for (const candidate of [