Skip to content
Open
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
2 changes: 2 additions & 0 deletions docs/buzz-help.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ if that desktop app is up and running.
chat. Sharing a chat with a channel shares its whole history.
- **Channels** are open (anyone can find and join them) or private (invite
only). The member avatars in the header manage members, access and roles.
A private channel or chat that has, or once had, members besides you and
your own agents can't be made open or shared; create a new channel instead.
Archived channels are read-only, and owners and admins can unarchive them.
- **Workspaces.** Drag conversations in, or use **Move to…**. A workspace can
set the folders and default agents for new chats started in it.
Expand Down
90 changes: 90 additions & 0 deletions src/bundled/channels/ChannelGeneralAccess.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -899,3 +899,93 @@ it("rechecks plugin participation policy after consent was staged", async () =>
await user.click(confirm);
expect(h.save).not.toHaveBeenCalled();
});

it.each([true, false])(
"offers opening a private channel only when nobody else is a member (blocked: %s)",
async (blocked) => {
const h = harness();
const user = userEvent.setup();
h.load.mockResolvedValue({ ...base, visibility: "private" });
render(
<ChannelGeneralAccess
capability={h.capability}
channelId="alpha"
openingBlocked={blocked}
/>,
);
const control = screen.getByRole("combobox", { name: "General access" });
await waitFor(() => expect(control).toBeEnabled());
await user.click(control);
for (const name of ["Public", "View only"]) {
const option = await screen.findByRole("option", { name });
if (blocked) {
expect(option).toHaveAttribute("aria-disabled", "true");
expect(option).toHaveAccessibleDescription(
"Has other members. Create a new channel instead.",
);
} else expect(option).not.toHaveAttribute("aria-disabled", "true");
}
await user.click(screen.getByRole("option", { name: "View only" }));
if (blocked) {
expect(screen.queryByRole("alertdialog")).not.toBeInTheDocument();
expect(h.load).toHaveBeenCalledTimes(1);
} else expect(await screen.findByRole("alertdialog")).toBeVisible();
expect(h.save).not.toHaveBeenCalled();
},
);

it("refuses a staged opening the opening check closes after consent opened", async () => {
const h = harness();
h.load.mockResolvedValue({ ...base, visibility: "private" });
const user = userEvent.setup();
const view = render(
<ChannelGeneralAccess capability={h.capability} channelId="alpha" />,
);
await select(user, "General access", "View only");
const confirm = await screen.findByRole("button", { name: "Change access" });
expect(confirm).toBeEnabled();
view.rerender(
<ChannelGeneralAccess
capability={h.capability}
channelId="alpha"
openingBlocked
/>,
);
expect(confirm).toBeDisabled();
expect(screen.getByRole("alertdialog")).toHaveAccessibleDescription(
expect.stringContaining("Has other members. Create a new channel instead."),
);
await user.click(confirm);
expect(h.save).not.toHaveBeenCalled();
await user.click(screen.getByRole("button", { name: "Cancel" }));
await waitFor(() =>
expect(screen.queryByRole("alertdialog")).not.toBeInTheDocument(),
);
});

it.each([
["Public", "member"],
["View only", "guest"],
] as const)(
"keeps switching an already %s channel open when opening is blocked",
async (current, joinRole) => {
const h = harness();
h.load.mockResolvedValue({ ...base, visibility: "public", joinRole });
const user = userEvent.setup();
render(
<ChannelGeneralAccess
capability={h.capability}
channelId="alpha"
openingBlocked
/>,
);
const control = screen.getByRole("combobox", { name: "General access" });
await waitFor(() => expect(control).toHaveTextContent(current));
await user.click(control);
for (const name of ["Public", "View only"])
expect(await screen.findByRole("option", { name })).not.toHaveAttribute(
"aria-disabled",
"true",
);
},
);
42 changes: 36 additions & 6 deletions src/bundled/channels/ChannelGeneralAccess.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
generalAccessOptions,
generalAccessPolicy,
generalAccessValue,
OPENING_BLOCKED_REASON,
} from "../../features/channels/general-access";

/** Resource wording and participation policy; relay authorization remains authoritative. */
Expand All @@ -53,6 +54,8 @@ export type ChannelGeneralAccessProps = {
/** False only when the signed member-role snapshot verifies no Guests. */
mayHaveGuestMembers?: boolean;
policy?: GeneralAccessPolicy;
/** The relay will refuse to open it: someone else is a member. */
openingBlocked?: boolean;
};

/** General access uses the same signed save/readback owner as channel details.
Expand All @@ -64,6 +67,7 @@ export function ChannelGeneralAccess({
channel,
mayHaveGuestMembers = true,
policy,
openingBlocked = false,
}: ChannelGeneralAccessProps) {
const place =
policy?.subject ?? (channel?.channelType === "solo" ? "chat" : "channel");
Expand Down Expand Up @@ -118,6 +122,7 @@ export function ChannelGeneralAccess({
summary={channel && capability.summaryAccess?.(channel)}
autoJoin={channel?.autoJoin ?? false}
policy={policy}
openingBlocked={openingBlocked}
/>
);
}
Expand All @@ -130,6 +135,7 @@ function ChannelGeneralAccessEditor({
summary,
autoJoin,
policy,
openingBlocked,
}: {
capability: ChannelDetailsCapability;
recovery: RelayRecovery | undefined;
Expand All @@ -139,6 +145,7 @@ function ChannelGeneralAccessEditor({
summary: ChannelAccess | undefined;
autoJoin: boolean;
policy: GeneralAccessPolicy | undefined;
openingBlocked: boolean;
}) {
const attempt = useSyncExternalStore(capability.subscribe, () =>
capability.snapshot(channelId),
Expand Down Expand Up @@ -211,6 +218,9 @@ function ChannelGeneralAccessEditor({
choice?.visibility !== "public" ||
choice.joinRole === "guest";
const access = shown ? generalAccessValue(shown) : "";
const closed = access === "private" && openingBlocked;
Comment thread
loganj marked this conversation as resolved.
Resolved
// The opening check can settle after the confirmation opened.
const choiceOpensClosed = closed && choice?.visibility === "public";
const Icon =
access === "public"
? GlobeIcon
Expand All @@ -222,7 +232,12 @@ function ChannelGeneralAccessEditor({
const option = Object.values(generalAccessOptions).find(
(option) => option.value === value,
);
if (value === access || !option || (restrictPublic && value === "public"))
if (
value === access ||
!option ||
(restrictPublic && value === "public") ||
(closed && value !== "private")
Comment thread
loganj marked this conversation as resolved.
Resolved
)
return;
origin.current =
section.current?.querySelector<HTMLElement>('[role="combobox"]') ?? null;
Expand Down Expand Up @@ -252,7 +267,11 @@ function ChannelGeneralAccessEditor({
busy.current ||
(check
? attempt?.status !== "unconfirmed"
: !base || !choice || locked || !policyAllowsChoice)
: !base ||
!choice ||
locked ||
!policyAllowsChoice ||
choiceOpensClosed)
)
return;
if (check) section.current?.focus();
Expand Down Expand Up @@ -358,9 +377,19 @@ function ChannelGeneralAccessEditor({
...generalAccessOptions["view-only"],
leading: <EyeIcon size={20} />,
},
].filter(
(option) => !restrictPublic || option.value !== "public",
),
]
.filter(
(option) => !restrictPublic || option.value !== "public",
)
.map((option) =>
closed
? {
...option,
disabled: true,
description: OPENING_BLOCKED_REASON,
}
: option,
),
},
{
label: "",
Expand All @@ -381,6 +410,7 @@ function ChannelGeneralAccessEditor({
<AlertDialog
title="Change general access?"
description={[
choiceOpensClosed ? OPENING_BLOCKED_REASON : "",
solo && choice.visibility === "public"
? SOLO_ACCESS_DISCLOSURE
: choice.visibility !== base.visibility
Expand Down Expand Up @@ -426,7 +456,7 @@ function ChannelGeneralAccessEditor({
</Button>
<Button
variant="prominent"
disabled={locked || !policyAllowsChoice}
disabled={locked || !policyAllowsChoice || choiceOpensClosed}
onClick={() => void apply()}
>
Change access
Expand Down
29 changes: 28 additions & 1 deletion src/bundled/channels/ChannelMembersDialog.solo.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,8 @@ it("shows Shared on cold render from verified members and cached human evidence
});

it("offers matching people and channels as labelled results without public keys", async () => {
const t = fixture(true);
// Another person is in the chat only after it was shared as View only.
const t = fixture(true, { visibility: "public", joinRole: "guest" });
const planningPerson = keypair();
t.addProfile(planningPerson, "Planning Person");
t.members.set(source, [t.viewer.pubkey, t.aria.pubkey]);
Expand Down Expand Up @@ -1596,3 +1597,29 @@ it("Back never walks history behind a pending Share, and the dialog still closes
await ctx.fiber.dispose();
}
});

it("closes opening once Manage members loads a person member's profile", async () => {
const t = fixture(true);
t.setSourceMembers([t.viewer.pubkey, t.aria.pubkey]);
await t.ready();
t.mount();
const user = userEvent.setup();
await user.click(screen.getByRole("button", { name: "Access" }));
const audience = await screen.findByRole("combobox", {
name: "General access",
});
await waitFor(() => expect(audience).toBeEnabled());
await waitFor(async () => {
await user.click(audience);
const option = await screen.findByRole("option", { name: "View only" });
await user.keyboard("{Escape}");
expect(option).toHaveAttribute("aria-disabled", "true");
});
await user.click(audience);
expect(
await screen.findByRole("option", { name: "View only" }),
).toHaveAccessibleDescription(
"Has other members. Create a new channel instead.",
);
expect(t.published).toEqual([]);
});
3 changes: 3 additions & 0 deletions src/bundled/channels/ChannelMembersDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ import { useReauthorizedRetry } from "../../features/relay/RecoveryNotice";
import { ChannelGeneralAccess } from "./ChannelGeneralAccess";
import { avatarMedia } from "../../shared/avatar-source";
import { channelIcon, channelText } from "../../features/channels/channel-icon";
import { useOpeningBlocked } from "../../features/channels/use-opening-blocked";
import { writeClipboardText } from "../../shared/clipboard";
import { messagePersonLink } from "../../features/direct-messages/message-person";

Expand Down Expand Up @@ -889,6 +890,7 @@ export function ChannelMembersDialog({
const channel =
list.channels.find((item) => item.id === channelId) ??
session.channels.get?.(channelId);
const openingBlocked = useOpeningBlocked(session, channel?.members);
Comment thread
loganj marked this conversation as resolved.
Resolved
const solo = channel?.channelType === "solo";
const dm = channel?.channelType === "dm";
const place = solo ? "chat" : dm ? "DM" : "channel";
Expand Down Expand Up @@ -2326,6 +2328,7 @@ export function ChannelMembersDialog({
administration.status !== "ready" ||
Object.values(administration.authority.roles).includes("guest")
}
openingBlocked={openingBlocked}
/>
) : null;
const dialog = (
Expand Down
87 changes: 87 additions & 0 deletions src/features/channels/general-access.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { expect, it } from "vitest";
import { openingBlocked } from "./general-access";

const viewer = "a".repeat(64);
const ownAgent = "b".repeat(64);
const inventoryAgent = "c".repeat(64);
const person = "d".repeat(64);
const othersAgent = "e".repeat(64);
const claimedAgent = "f".repeat(64);
const unloaded = "1".repeat(64);
const listedOthersAgent = "2".repeat(64);
const flaggedAgent = "3".repeat(64);
const verified = new Map([
[ownAgent, viewer],
[othersAgent, person],
[listedOthersAgent, person],
]);
const session = {
viewer,
profiles: {
snapshot: () =>
new Map<string, { isAgent?: true; ownerPubkey?: string }>([
[ownAgent, { isAgent: true, ownerPubkey: viewer }],
[othersAgent, { isAgent: true, ownerPubkey: person }],
// An agent whose attestation is missing or does not verify.
[claimedAgent, { isAgent: true, ownerPubkey: viewer }],
[person, {}],
// Listed in the viewer's inventory; its profile claims no agent.
[inventoryAgent, {}],
// An agent only by its profile content: no auth tag, no inventory entry.
[flaggedAgent, { isAgent: true }],
]),
owner: (pubkey: string) => verified.get(pubkey),
},
agentChoices: {
snapshot: () => ({
identities: [{ pubkey: inventoryAgent }, { pubkey: listedOthersAgent }],
complete: true,
}),
},
};

it.each([
["only the viewer", [viewer], false],
["the viewer and their agents", [viewer, ownAgent, inventoryAgent], false],
["another person", [viewer, person], true],
["someone else's verified agent", [viewer, othersAgent], true],
[
"someone else's verified agent in the viewer's inventory",
[viewer, listedOthersAgent],
true,
],
["an agent with unverified ownership", [viewer, claimedAgent], false],
["an agent flagged only in its profile", [viewer, flaggedAgent], false],
["a member whose profile has not loaded", [viewer, unloaded], false],
["an unknown roster", undefined, false],
] as const)("%s", (_, members, blocked) => {
expect(openingBlocked(session, members)).toBe(blocked);
});

it("blocks once a member's profile shows a person", () => {
const loaded = new Map(session.profiles.snapshot());
const later = {
...session,
profiles: { ...session.profiles, snapshot: () => loaded },
};
expect(openingBlocked(later, [viewer, unloaded])).toBe(false);
loaded.set(unloaded, {});
expect(openingBlocked(later, [viewer, unloaded])).toBe(true);
});

it("leaves an untagged member to the relay while the inventory is incomplete", () => {
const loading = {
...session,
agentChoices: {
snapshot: () => ({ identities: [], complete: false }),
},
};
expect(openingBlocked(loading, [viewer, person])).toBe(false);
expect(openingBlocked(loading, [viewer, othersAgent])).toBe(true);
});

it("never blocks without a viewer", () => {
expect(openingBlocked({ ...session, viewer: undefined }, [person])).toBe(
false,
);
});
Loading
Loading