Skip to content
Draft
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
81 changes: 81 additions & 0 deletions desktop/src/features/home/lib/inbox.test.mjs
Original file line number Diff line number Diff line change
@@ -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);
});
11 changes: 9 additions & 2 deletions desktop/src/features/home/lib/inbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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) {
Expand Down
20 changes: 20 additions & 0 deletions desktop/src/features/home/ui/HomeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
countDueReminders,
useRemindersQuery,
} from "@/features/reminders/hooks";
import { useRemindLater } from "@/features/reminders/ui/RemindMeLaterProvider";
import { deleteMessage, sendChannelMessage } from "@/shared/api/tauri";
import type { HomeFeedResponse } from "@/shared/api/types";
import { KIND_REACTION } from "@/shared/constants/kinds";
Expand Down Expand Up @@ -108,6 +109,7 @@ export function HomeView({
);
const [isDeletingMessage, setIsDeletingMessage] = React.useState(false);
const [isSendingReply, setIsSendingReply] = React.useState(false);
const { openReminder, activeReminderEventIds } = useRemindLater();
const [localRepliesByItemId, setLocalRepliesByItemId] = React.useState<
Record<string, InboxReply[]>
>({});
Expand Down Expand Up @@ -407,11 +409,29 @@ export function HomeView({
>
{showListPane ? (
<InboxListPane
activeReminderEventIds={activeReminderEventIds}
doneSet={effectiveDoneSet}
dueReminderCount={dueReminderCount}
filter={filter}
items={filteredItems}
onFilterChange={setFilter}
onMarkUnread={markItemUnread}
onOpenDirect={(item) => {
const channelId = item.item.channelId;
if (!channelId) {
return;
}

onOpenContext(channelId, item.id);
}}
onRemindLater={(item) => {
openReminder({
eventId: item.id,
channelId: item.item.channelId ?? "",
preview: item.preview.slice(0, 100),
authorPubkey: item.item.pubkey,
});
}}
onSelect={(itemId) => {
handleUserSelectItem(itemId);
markItemRead(itemId);
Expand Down
Loading