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
37 changes: 37 additions & 0 deletions src/features/messages/MessageRow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,43 @@ it("renders the signed whole-thread total rather than only direct replies", () =
expect(html).toContain('aria-label="View thread: 3 replies"');
expect(html).toContain("3 replies</span>");
});
it("draws a thread-title root as one line that opens its thread, and in full in the thread", async () => {
const open = vi.fn();
const title = {
...row,
content: "Fix the login test",
threadTitle: true as const,
};
const props = {
profile: { name: "Alex" },
media: () => undefined,
onOpenLink: () => false,
day: false,
retry: undefined,
onOpenThread: open,
};
try {
const { rerender } = renderDom(<MessageRow row={title} {...props} />);
await userEvent.click(
screen.getByRole("button", {
name: /^Thread by Alex: Fix the login test, /,
}),
);
expect(open).toHaveBeenCalledWith("root", "root");
// The thread's own summary stays its control, with its reply count.
expect(
screen.getByRole("button", { name: "View thread: 23 replies" }),
).toBeInTheDocument();
rerender(<MessageRow row={title} {...props} layout="thread" />);
expect(screen.queryByRole("button", { name: /^Thread by/ })).toBeNull();
expect(screen.getByText("Fix the login test")).toBeInTheDocument();
// A failed send keeps its full row, so its Retry stays in the timeline.
rerender(<MessageRow row={{ ...title, delivery: "failed" }} {...props} />);
expect(screen.queryByRole("button", { name: /^Thread by/ })).toBeNull();
} finally {
cleanup();
}
});
it("selects this thread, adds an accessible unread cue and preserves the total reply count", () => {
const { html, snapshot } = render({ observedCount: 2 });
expect(snapshot).toHaveBeenCalledExactlyOnceWith({
Expand Down
168 changes: 167 additions & 1 deletion src/features/messages/MessageRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ import {
FlagIcon,
ListBulletsIcon,
PinIcon,
ThreadIcon,
} from "../../shared/design-system/icons";
import { usePinnedMessages } from "./use-pins";
import {
Expand Down Expand Up @@ -209,6 +210,8 @@ type MessageContentProps = MessageRowProps & {
renderMessage?: (
message: ReactNode,
trigger: RefObject<HTMLButtonElement | null>,
/** The row's thread summary control, or null when it has none. */
summary: ReactNode,
) => ReactElement;
};

Expand Down Expand Up @@ -1820,7 +1823,13 @@ function MessageRowContent({
);
return renderMessage ? (
<>
{messageActions(renderMessage(message, menuTrigger))}
{messageActions(
renderMessage(
message,
menuTrigger,
summaryThread ? renderMessageSummary() : null,
),
)}
{overlays}
</>
) : row.membership || row.huddle ? (
Expand Down Expand Up @@ -1859,6 +1868,8 @@ export const MessageRow = memo(function AudienceMessageRow(
)
) : row.relayedFrom?.verified ? (
<RelayedMessageRow {...props} />
) : titleLine(props) ? (
<ThreadTitleRow {...props} />
) : row.audience === "agents" ? (
<AgentsMessageRow {...props} />
) : (
Expand Down Expand Up @@ -2337,6 +2348,143 @@ function RelayedMessageRow(props: MessageRowProps) {
);
}

/** A thread title is one line only in the timeline, where it can open its
* thread, and only while the title is all there is to show: a failed send
* keeps its Retry, and attachments, forwards and agent or workflow rows keep
* their own presentation. */
const titleLine = ({
row,
layout = "timeline",
onOpenThread,
startsThreads = true,
}: MessageRowProps) =>
!!row.threadTitle &&
!row.threadRootId &&
layout === "timeline" &&
!!onOpenThread &&
(startsThreads || row.replyCount > 0) &&
row.delivery !== "failed" &&
row.delivery !== "unknown" &&
!!row.content.trim() &&
!row.attachments.length &&
!row.forward &&
!row.diff &&
!row.agentEnvelope &&
!row.pluginRequest &&
!row.audience &&
!row.workflowOwnerId &&
!row.membership &&
!row.huddle;

/** A top-level message whose signer marked it as only its thread's title
* reads as one line in the timeline: who started it, the title, the thread's
* summary and the time. The line opens the thread, where the root is shown in
* full; the message menu keeps its usual actions. */
function ThreadTitleRow(props: MessageRowProps) {
const { row, session, media, agentPubkeys, onOpenThread } = props;
const references = props.references ?? session;
const resolveName = useChannelIdentityNames(references, row.channelId);
const showTime = useMessageTimeVisible(references?.channels, row.channelId);
// The button's name carries the full date, so it follows time zone changes.
useLocalDay();
const name = resolveName(
row.authorId,
props.profile?.name ?? row.authorId.slice(0, 10),
);
const excerpt = Array.from(
messagePreviewText(row.content).replace(/\s+/g, " ").trim(),
);
const title =
excerpt.length > 280
? `${excerpt.slice(0, 279).join("")}…`
: excerpt.join("");
return (
<FullMessageRow
{...props}
shownRow={row}
withoutReactions
alignViewer={false}
day={false}
layout="continuation"
stackPrevious
stackNext
renderMessage={(_message, trigger, summary) => (
<div
className={styles.relayedRow}
data-thread-title=""
data-layout="timeline"
>
{props.day && <DayDivider createdAt={row.createdAt} />}
<div
className={styles.relayedEntry}
data-highlight-surface=""
data-thread-open={props.threadOpen || undefined}
aria-current={props.threadOpen ? true : undefined}
data-message-id={row.id}
>
<div className={styles.relayedHeader}>
<button
ref={trigger}
type="button"
data-buzz-ui=""
className={styles.relayedTrigger}
aria-label={`Thread by ${name}: ${title}${row.edited ? " (edited)" : ""}, ${formatFullTimestamp(row.createdAt)}`}
onClick={(event) => {
event.currentTarget.focus({ preventScroll: true });
onOpenThread?.(row.id, row.id);
}}
/>
<span className={styles.relayedAvatar} aria-hidden="true">
<AgentAvatar
session={session}
agentPubkey={row.authorId}
channelId={row.channelId}
src={avatarMedia(props.profile?.picture, media)}
alt=""
fallback={name}
size="fill"
shape={
agentPubkeys?.has(row.authorId) || props.profile?.isAgent
? "squircle"
: "circle"
}
/>
</span>
<span className={styles.relayedName} aria-hidden="true">
{name}
</span>
<ThreadIcon
className={styles.threadTitleIcon}
aria-hidden="true"
/>
<span className={styles.threadTitleText} aria-hidden="true">
{title}
</span>
{row.edited && (
<span aria-hidden="true">
<EditedMarker />
</span>
)}
{session?.relayAuthor && (
<PinnedLineMark session={session} row={row} />
)}
{summary && (
<span className={styles.threadTitleSummary}>{summary}</span>
)}
<span className={styles.relayedTime} aria-hidden="true">
<MessageTimestamp
createdAt={row.createdAt}
visible={showTime}
/>
</span>
</div>
</div>
</div>
)}
/>
);
}

// Subscribe only for mounted thread buttons. Evidence and reading remain session-owned;
// rendering a row must not initiate per-thread reads or acknowledge unseen replies.
function useThreadUnread(
Expand Down Expand Up @@ -2439,6 +2587,24 @@ function useThreadAgents(
};
}

/** A thread title's line has no body for the pinned line, so a pin shows
* beside its title. */
function PinnedLineMark({
session,
row,
}: {
session: RelaySession;
row: ChannelMessage;
}) {
const pins = usePinnedMessages(session, row.channelId);
if (!pins.set.has(row.id)) return null;
return (
<span className={styles.relayedSubtle} role="img" aria-label="Pinned">
<PinIcon size={12} aria-hidden="true" />
</span>
);
}

/** A quiet line on a message that is pinned in its channel. */
function PinnedMarker({
session,
Expand Down
32 changes: 32 additions & 0 deletions src/features/messages/Messages.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,24 @@ html[data-keyboard-navigation] .attachmentImage:focus-visible {
margin-top: var(--space-half);
padding-block: var(--space-half);
}
/* The summary is the thread's own control, so it sits above
the title line's button. */
.threadTitleSummary {
position: relative;
z-index: 1;
flex: none;
display: flex;
margin-block: calc(-1 * var(--space-half));
}
.threadTitleSummary > [data-thread-summary] {
min-height: 0;
padding: var(--space-half) var(--space-1h) var(--space-half) var(--space-1);
font-size: var(--text-caption);
line-height: var(--text-caption--line-height);
letter-spacing: var(--text-caption--letter-spacing);
font-weight: var(--type-weight-regular);
user-select: none;
}
.messageBody [data-reply-connector] {
margin-inline-start: calc(var(--space-4) + var(--space-3));
max-width: calc(100% - var(--space-4) - var(--space-3));
Expand Down Expand Up @@ -4346,6 +4364,20 @@ html[data-keyboard-navigation]
.relayedRun > .relayedHeader > .relayedTime {
margin-inline-start: auto;
}
/* A thread title's line: its title gives up room first, so who started it,
its summary and the time stay readable. */
.threadTitleIcon {
flex: none;
inline-size: var(--space-4);
block-size: var(--space-4);
}
.threadTitleText {
flex: 1 1 0;
min-inline-size: 0;
overflow: hidden;
text-overflow: ellipsis;
color: var(--text-standard);
}
/* Points right while closed and down while open, as other disclosures do. */
.relayedCaret {
flex: none;
Expand Down
3 changes: 3 additions & 0 deletions src/features/messages/message-grouping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export function continuesMessageGroup(
// A relayed line is another agent's, never part of its signer's group.
!previous.relayedFrom?.verified &&
!current.relayedFrom?.verified &&
// A thread title is its own line, the way its thread is its own topic.
!previous.threadTitle &&
!current.threadTitle &&
previous.channelId === current.channelId &&
previous.authorId === current.authorId &&
(previous.audience === current.audience || current.audience === "agents") &&
Expand Down
3 changes: 3 additions & 0 deletions src/features/relay/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ export type ChannelMessage = Readonly<{
notice?: string;
verified: boolean;
}>;
/** Signed `thread-title` tag on a top-level message: the signer's claim
* that it is only its thread's title. Display metadata, not authority. */
threadTitle?: true;
/** Signed `buzz:request` tag: the agent's claim of the triggering message
* this update belongs to, separate from its flattened reply link. */
request?: string;
Expand Down
25 changes: 25 additions & 0 deletions src/features/relay/fold.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,31 @@ it("honours a relayed-from claim only while the author owns the named agent", ()
expect(fold(relayed(tags), alice.pubkey)?.relayedFrom).toBeUndefined();
});

it("marks only a top-level message with one exact thread-title tag", () => {
const root = message(alice, channel, "Fix the login test", 10, [
["thread-title", "1"],
]);
const fold = (event: ReturnType<typeof message>) =>
foldMessages(channel, relay.pubkey, [event], { includeReplies: true })[0];
expect(fold(root)?.threadTitle).toBe(true);
for (const tags of [
[["thread-title", "0"]],
[["thread-title", "1", "extra"]],
[
["thread-title", "1"],
["thread-title", "1"],
],
[
["thread-title", "1"],
["e", root.id, "", "reply"],
],
])
expect(
fold(message(alice, channel, "Fix the login test", 11, tags))
?.threadTitle,
).toBeUndefined();
});

it("replaces a shared row when only its relayed claim's verification changes", () => {
const event = message(alice, channel, "Notice\n\nText", 10, [
["relayed-from", bob.pubkey],
Expand Down
2 changes: 2 additions & 0 deletions src/features/relay/fold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { validatedBlurhash } from "./blurhash";
import { threadReference } from "./thread-reference";
import { agentAudience } from "./audience";
import { relayedFromClaim, relayNotice } from "./relayed-from";
import { threadTitleClaim } from "./thread-title";
import { pluginRequestId } from "./plugin-request";
import { emojiTags } from "./emoji";
import { objectBody } from "./body";
Expand Down Expand Up @@ -484,6 +485,7 @@ export function foldMessages(
}),
}
: {}),
...(threadTitleClaim(event) ? { threadTitle: true as const } : {}),
...(() => {
// One exact id, or none: conflicting claims bind no request.
const ids = new Set(
Expand Down
1 change: 1 addition & 0 deletions src/features/relay/row-identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function sameRow(left: ChannelMessage, right: ChannelMessage) {
left.relayedFrom?.channelId === right.relayedFrom?.channelId &&
left.relayedFrom?.verified === right.relayedFrom?.verified &&
left.relayedFrom?.notice === right.relayedFrom?.notice &&
left.threadTitle === right.threadTitle &&
left.request === right.request &&
!!left.diff === !!right.diff &&
left.diff?.filePath === right.diff?.filePath &&
Expand Down
14 changes: 14 additions & 0 deletions src/features/relay/thread-title.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { EventData } from "./events";
import { threadReference } from "./thread-reference";

/** The signer's claim, in a signed `["thread-title", "1"]` tag, that a
* top-level message is only its thread's title: the content is in the
* replies. One well-formed claim, or none: a reply, another kind, another
* value or a repeated tag claims nothing. */
export function threadTitleClaim(
event: Pick<EventData, "kind" | "tags">,
): boolean {
if (event.kind !== 9 || threadReference(event)) return false;
const claims = event.tags.filter(([name]) => name === "thread-title");
return claims.length === 1 && claims[0]?.length === 2 && claims[0][1] === "1";
}
Loading
Loading