diff --git a/desktop/src/features/home/lib/inbox.test.mjs b/desktop/src/features/home/lib/inbox.test.mjs new file mode 100644 index 0000000000..783636855c --- /dev/null +++ b/desktop/src/features/home/lib/inbox.test.mjs @@ -0,0 +1,81 @@ +import assert from "node:assert/strict"; +import test from "node:test"; + +import { buildInboxItems, INBOX_PREVIEW_MAX_LENGTH } from "./inbox.ts"; + +function feedItem(overrides = {}) { + return { + id: overrides.id ?? "event-1", + kind: overrides.kind ?? 45003, + pubkey: overrides.pubkey ?? "pubkey-1", + content: overrides.content ?? "hello", + createdAt: overrides.createdAt ?? 1_700_000_000, + channelId: overrides.channelId ?? "channel-1", + channelName: overrides.channelName ?? "general", + channelType: overrides.channelType, + tags: overrides.tags ?? [], + category: overrides.category ?? "activity", + }; +} + +function homeFeed({ + mentions = [], + needsAction = [], + activity = [], + agentActivity = [], +} = {}) { + return { + feed: { + mentions, + needsAction, + activity, + agentActivity, + }, + meta: { + since: 0, + total: + mentions.length + + needsAction.length + + activity.length + + agentActivity.length, + generatedAt: 1_700_000_000, + }, + }; +} + +test("buildInboxItems caps regular and agent previews to the same length", () => { + const longHumanMessage = `human ${"message ".repeat(50)}`; + const longAgentMessage = `agent\n\n${"response ".repeat(50)}`; + + const items = buildInboxItems({ + feed: homeFeed({ + activity: [ + feedItem({ + id: "human-message", + content: longHumanMessage, + createdAt: 1_700_000_000, + category: "activity", + }), + ], + agentActivity: [ + feedItem({ + id: "agent-message", + content: longAgentMessage, + createdAt: 1_700_000_001, + category: "agent_activity", + }), + ], + }), + }); + + const human = items.find((item) => item.id === "human-message"); + const agent = items.find((item) => item.id === "agent-message"); + + assert.ok(human); + assert.ok(agent); + assert.equal(human.preview.length, INBOX_PREVIEW_MAX_LENGTH); + assert.equal(agent.preview.length, INBOX_PREVIEW_MAX_LENGTH); + assert.equal(human.preview.endsWith("..."), true); + assert.equal(agent.preview.endsWith("..."), true); + assert.equal(agent.preview.includes("\n"), false); +}); diff --git a/desktop/src/features/home/lib/inbox.ts b/desktop/src/features/home/lib/inbox.ts index 99d4fe31ba..ff53134c9f 100644 --- a/desktop/src/features/home/lib/inbox.ts +++ b/desktop/src/features/home/lib/inbox.ts @@ -88,6 +88,9 @@ const weekdayFormatter = new Intl.DateTimeFormat("en-US", { weekday: "long", }); +/** Shared text cap for inbox list previews, including long agent responses. */ +export const INBOX_PREVIEW_MAX_LENGTH = 160; + function startOfDay(value: Date) { return new Date(value.getFullYear(), value.getMonth(), value.getDate()); } @@ -134,9 +137,13 @@ function feedHeadline(item: FeedItem) { } function feedPreview(item: FeedItem) { - const content = item.content.trim(); + const content = item.content.trim().replace(/\s+/g, " "); if (content.length > 0) { - return content; + if (content.length <= INBOX_PREVIEW_MAX_LENGTH) { + return content; + } + + return `${content.slice(0, INBOX_PREVIEW_MAX_LENGTH - 3).trimEnd()}...`; } if (item.kind === 46010) { diff --git a/desktop/src/features/home/ui/HomeView.tsx b/desktop/src/features/home/ui/HomeView.tsx index fd5085bb31..2a02284fb6 100644 --- a/desktop/src/features/home/ui/HomeView.tsx +++ b/desktop/src/features/home/ui/HomeView.tsx @@ -414,7 +414,6 @@ export function HomeView({ onFilterChange={setFilter} onSelect={(itemId) => { handleUserSelectItem(itemId); - markItemRead(itemId); }} reminderPubkey={currentPubkey} selectedId={selectedItemId} diff --git a/desktop/src/features/home/ui/InboxListPane.tsx b/desktop/src/features/home/ui/InboxListPane.tsx index 670c95b465..5990fd1d2f 100644 --- a/desktop/src/features/home/ui/InboxListPane.tsx +++ b/desktop/src/features/home/ui/InboxListPane.tsx @@ -1,4 +1,4 @@ -import { ChevronDown } from "lucide-react"; +import { ChevronDown, Mail } from "lucide-react"; import * as React from "react"; import { @@ -88,22 +88,32 @@ export function InboxListPane({
- {item.senderLabel} +
+ {item.senderLabel} +
+ {item.isActionRequired ? ( + + Needs action + + ) : null} ++ {typeLabel}
- {item.isActionRequired ? ( - - Needs action - - ) : null}