Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions apps/mobile/src/features/threads/threadListV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`]),
Expand Down
3 changes: 2 additions & 1 deletion apps/mobile/src/features/threads/threadListV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
import {
sortActiveThreadsByOrderKey,
resolveSettledThreadTimestamp,
resolveThreadActivityTimestamp,
sortPinnedThreadsByOrderKey,
sortSettledThreads,
} from "@t3tools/client-runtime/state/thread-sort";
Expand Down Expand Up @@ -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,
);
}

Expand Down
15 changes: 7 additions & 8 deletions apps/web/src/components/sidebar/SidebarThreadRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -1318,7 +1317,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
timestamp={
variantAction === "unsettle"
? resolveSettledThreadTimestamp(thread)
: threadTimeTimestamp(thread)
: resolveThreadActivityTimestamp(thread)
}
/>
</span>
Expand Down Expand Up @@ -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 ? (
Expand Down Expand Up @@ -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 ? (
Expand Down
5 changes: 5 additions & 0 deletions packages/client-runtime/src/state/threadSort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
Loading