Skip to content
Merged
2 changes: 2 additions & 0 deletions docs/buzz-help.md
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,8 @@ and are asked to sign in again in Buzz.
not change.
Chats reorder by recent activity with the same short slides and fades as Team
channels. Reduced motion applies the new order immediately.
A Solo chat name you save here changes immediately. Title changes that arrive
from an agent or another device animate unless reduced motion is enabled.
Deleting or archiving the open chat keeps you in Solo and opens another chat
or a new draft.
**Start Solo chat**, in the menu of any delivered message (and in a channel's
Expand Down
2 changes: 2 additions & 0 deletions src/app/shell/PrimarySidebar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ it("double-clicks a Solo row to edit its selected name, retaining a failed save
base,
expect.objectContaining({ name: "New plan", labels: [SOLO_LABEL] }),
expect.any(AbortSignal),
undefined,
f.session.channels,
);
await user.dblClick(screen.getByRole("button", { name: /^Planning/ }));
await screen.findByRole("textbox", { name: "Chat name" });
Expand Down
14 changes: 13 additions & 1 deletion src/bundled/channels/ChannelHeaderIdentity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ComponentProps } from "react";
import type { ChannelSummary } from "../../features/relay/contracts";
import type { RelaySession } from "../../features/relay/session";
import { SurfaceButton } from "../../shared/design-system/ui/SurfaceButton";
import { SoloChatTitle } from "../../features/solo/SoloChatTitle";
import { ChannelMemberAvatars } from "./ChannelMemberAvatars";
import styles from "./ChannelHeaderIdentity.module.css";

Expand Down Expand Up @@ -73,7 +74,18 @@ export function ChannelHeaderIdentity({
<ChannelMemberAvatars session={session} channelId={channelId} />
</span>
<span className={styles.label}>
<span className={`${styles.name} text-body-sm`}>{name}</span>
<span className={`${styles.name} text-body-sm`}>
{access === soloAccess || access === soloReadOnlyAccess ? (
<SoloChatTitle
key={channelId}
channelId={channelId}
title={name}
details={session.channelDetails}
/>
) : (
name
)}
</span>
</span>
</SurfaceButton>
);
Expand Down
9 changes: 7 additions & 2 deletions src/bundled/channels/SoloChatName.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ afterEach(cleanup);
function setup(overrides: Partial<ChannelDetailsCapability> = {}) {
const save = vi.fn(async () => {});
const close = vi.fn();
const channels = { subscribeList: () => () => {} };
const details: ChannelDetailsCapability = {
available: true,
load: vi.fn(async () => ({
Expand All @@ -36,15 +37,17 @@ function setup(overrides: Partial<ChannelDetailsCapability> = {}) {
render(
<>
<SoloChatName
session={{ channelDetails: details } as RelaySession}
session={
{ channels, channelDetails: details } as unknown as RelaySession
}
id="chat"
title="Plan"
close={close}
/>
<button type="button">Elsewhere</button>
</>,
);
return { save, close, details, user: userEvent.setup() };
return { save, close, details, channels, user: userEvent.setup() };
}

it.each(["", "Plan"])(
Expand Down Expand Up @@ -78,6 +81,8 @@ it("saves on click-away without taking focus back from the destination", async (
labels: ["buzz.solo"],
}),
expect.any(AbortSignal),
undefined,
f.channels,
);
expect(screen.getByRole("button", { name: "Elsewhere" })).toHaveFocus();
});
Expand Down
10 changes: 9 additions & 1 deletion src/bundled/channels/SoloInventory.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useSoloRowActivation } from "../../features/channel-navigation/useSoloRowActivation";
import { useIsPresent } from "motion/react";
import { SoloChatTitle } from "../../features/solo/SoloChatTitle";
import type { ComposeWorkspaces } from "../../features/channel-navigation/WorkspaceComposition";
import { useSoloNavigation } from "../../features/channel-navigation/solo-navigation-react";
import { soloNavigationFor } from "../../features/channel-navigation/solo-navigation";
Expand Down Expand Up @@ -625,7 +626,14 @@ function SoloConversationRow({
<UnreadBadge
session={session}
channelId={id}
label={title}
label={
<SoloChatTitle
key={id}
channelId={id}
title={title}
details={session.channelDetails}
/>
}
labelUnread="all"
/>
</span>
Expand Down
14 changes: 13 additions & 1 deletion src/features/channel-navigation/SoloDestination.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useSoloRowActivation } from "./useSoloRowActivation";
import { SoloChatTitle } from "../solo/SoloChatTitle";
import {
type ReactNode,
type RefObject,
Expand Down Expand Up @@ -302,7 +303,18 @@ function ConversationLink(props: SoloConversationLinkProps) {
{...(primary ? { "data-solo-destination-id": state.channel.id } : {})}
aria-label={props["aria-label"]}
aria-describedby={props["aria-describedby"]}
label={props.label}
label={
!props.multiline && props.label === state.channel.name ? (
<SoloChatTitle
key={state.channel.id}
channelId={state.channel.id}
title={state.channel.name}
details={context?.session.channelDetails}
/>
) : (
props.label
)
}
icon={props.icon}
trailing={props.trailing}
multiline={!!props.multiline}
Expand Down
56 changes: 56 additions & 0 deletions src/features/relay/channel-details.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,62 @@ it.each([undefined, 600])(
},
);

it.each(["away and back", "rejection", "disposal"] as const)(
"retires the local Solo rename marker after %s",
async (ending) => {
const h = harness("owner", true);
const details = h.owner.capability;
h.set([
h.metadata("First prompt", "", "private", "stream", [SOLO_LABEL]),
...h.events().slice(1),
]);
const base = await details.load(id);
const next = { ...base, name: "Release notes" };
let name = base.name;
const listeners = new Set<() => void>();
const channels = {
get: () => ({ id, name }),
subscribeList(listener: () => void) {
listeners.add(listener);
return () => {
listeners.delete(listener);
};
},
};
const observe = (title: string) => {
name = title;
for (const listener of listeners) listener();
};
const marker = () => details.localRename?.(id, next.name);
h.publish.mockImplementationOnce(async () => {
expect(marker()).toBeDefined();
if (ending === "rejection") throw new PublishRejected("Not permitted");
h.set([
h.metadata(next.name, "", "private", "stream", [
SOLO_LABEL,
SOLO_NAMED_LABEL,
]),
...h.events().slice(1),
]);
observe(next.name);
});
const save = details.save(base, next, undefined, undefined, channels);
if (ending === "rejection") {
await expect(save).rejects.toThrow("Not permitted");
} else {
await save;
expect(marker()).toBeDefined();
if (ending === "disposal") h.owner.dispose();
else {
observe(base.name);
observe(next.name);
}
}
expect(marker()).toBeUndefined();
expect(listeners.size).toBe(0);
},
);

it("refuses chosen-name label overflow before signing and retains the existing label set", async () => {
const h = harness("owner", true);
const labels = [
Expand Down
48 changes: 48 additions & 0 deletions src/features/relay/channel-details.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { regionLabels } from "../solo/region-labels";
import { getEventHash, verifyEvent } from "nostr-tools";
import type { RelayReader } from "./reader";
import type { ChannelQueries } from "./contracts";
import { retryRead } from "./read-retry";
import type { RelayWriter } from "./transport";
import type { RelayEvent } from "./events";
Expand All @@ -21,6 +22,8 @@ export type DetailsAttempt = Readonly<{
draft: ChannelDetailsDraft;
status: "saving" | "unconfirmed";
}>;
type ChannelNames = Pick<ChannelQueries, "get" | "subscribeList">;

export interface ChannelDetailsCapability {
readonly available: boolean;
load(id: string, signal?: AbortSignal): Promise<ChannelDetails>;
Expand All @@ -30,7 +33,11 @@ export interface ChannelDetailsCapability {
signal?: AbortSignal,
/** Checked synchronously right before publishing; false publishes nothing. */
active?: () => boolean,
/** Present only for name edits initiated by this app's Solo editor. */
manualRename?: ChannelNames,
): Promise<void>;
/** An in-memory revision of a matching title change initiated here. */
localRename?(id: string, name: string): number | undefined;
check(id: string, signal?: AbortSignal): Promise<void>;
snapshot(id: string): DetailsAttempt | undefined;
subscribe(listener: () => void): () => void;
Expand Down Expand Up @@ -59,11 +66,41 @@ export function createChannelDetails({
}) {
let closed = false;
const attempts = new Map<string, DetailsAttempt>();
const manualNames = new Map<
string,
{ name: string; previous?: string | undefined; revision: number }
>();
let renameRevision = 0;
let unsubscribeNames: (() => void) | undefined;
const controllers = new Set<AbortController>();
const listeners = new Set<() => void>();
function emit() {
for (const listener of listeners) listener();
}
function forgetManualName(id: string) {
manualNames.delete(id);
if (!manualNames.size) {
unsubscribeNames?.();
unsubscribeNames = undefined;
}
}
function rememberManualName(
channels: ChannelNames,
id: string,
previous: string,
name: string,
) {
if (channels.get?.(id)?.name !== previous) return;
manualNames.set(id, { name, previous, revision: ++renameRevision });
unsubscribeNames ??= channels.subscribeList(() => {
for (const [id, rename] of manualNames) {
const current = channels.get?.(id)?.name;
if (current === rename.name) rename.previous = undefined;
else if (current === undefined || current !== rename.previous)
forgetManualName(id);
}
});
}
function assertAccess(id: string) {
if (closed || !canAccess(id))
throw new Error("Channel access changed. Reopen channel settings.");
Expand Down Expand Up @@ -134,6 +171,10 @@ export function createChannelDetails({
}
const capability: ChannelDetailsCapability = Object.freeze({
available: !!reader && !!writer,
localRename(id: string, name: string) {
const rename = manualNames.get(id);
return rename?.name === name ? rename.revision : undefined;
},
snapshot: (id: string) => attempts.get(id),
subscribe(listener: () => void) {
listeners.add(listener);
Expand Down Expand Up @@ -173,6 +214,7 @@ export function createChannelDetails({
input: ChannelDetailsDraft,
caller?: AbortSignal,
active?: () => boolean,
manualRename?: ChannelNames,
) {
const id = lifecycleChannelId(base.channelId);
if (!writer || !reader)
Expand Down Expand Up @@ -253,6 +295,8 @@ export function createChannelDetails({
signal.throwIfAborted();
if (active?.() === false)
throw new DOMException("Channel edit cancelled", "AbortError");
if (manualRename && chosenName)
rememberManualName(manualRename, id, base.name, draft.name);
Comment thread
tellaho marked this conversation as resolved.
Resolved
publicationStarted = true;
await writer.publish(signed, signal);
await confirm(id, draft, signal);
Expand All @@ -265,6 +309,8 @@ export function createChannelDetails({
attempts.set(id, Object.freeze({ draft, status: "unconfirmed" }));
throw new Error(uncertain);
}
if (publicationStarted && manualRename && chosenName)
forgetManualName(id);
Comment thread
tellaho marked this conversation as resolved.
Resolved
attempts.delete(id);
if (error instanceof Error && error.name === "AbortError") throw error;
if (!publicationStarted)
Expand All @@ -290,6 +336,8 @@ export function createChannelDetails({
closed = true;
cancel();
attempts.clear();
unsubscribeNames?.();
manualNames.clear();
listeners.clear();
},
};
Expand Down
2 changes: 2 additions & 0 deletions src/features/solo/Lifetime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ export function useLifetime({
ttlSeconds: ttl,
},
active,
undefined,
nameChanged ? session.channels : undefined,
);
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/features/solo/SoloChatTitle.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.title {
position: relative;
display: block;
min-width: 0;
overflow: hidden;
}

.value {
display: block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

.character {
display: inline-block;
Comment thread
tellaho marked this conversation as resolved.
Resolved
white-space: pre;
}
25 changes: 25 additions & 0 deletions src/features/solo/SoloChatTitle.reduced-motion.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// @vitest-environment jsdom
import "@testing-library/jest-dom/vitest";
import { cleanup, render, screen } from "@testing-library/react";
import { afterEach, expect, it, vi } from "vitest";
import { SoloChatTitle } from "./SoloChatTitle";

afterEach(() => {
cleanup();
vi.unstubAllGlobals();
});

it("replaces the visible and accessible title immediately with reduced motion", () => {
const media = Object.assign(new EventTarget(), { matches: true });
vi.stubGlobal("matchMedia", () => media);
const { rerender } = render(<SoloChatTitle title="First" />, {
wrapper: ({ children }) => <button type="button">{children}</button>,
});
rerender(<SoloChatTitle title="Renamed" />);

expect(screen.queryByText("First")).toBeNull();
expect(
screen.getByText("Renamed", { selector: '[aria-hidden="true"]' }),
).toBeVisible();
expect(screen.getByRole("button")).toHaveAccessibleName("Renamed");
});
Loading
Loading