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
3 changes: 2 additions & 1 deletion src/bundled/agents/AgentShareRecipients.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { viewerMember } from "../../features/relay/membership";
// Who Share sends an agent to: people by direct message, or a channel the
// viewer belongs to, found with one search as Share access does.
import { useSyncExternalStore, type Ref } from "react";
Expand Down Expand Up @@ -70,7 +71,7 @@ export function AgentShareRecipients({
!item.cached &&
!item.archived &&
["stream", "forum"].includes(item.channelType ?? "") &&
item.members?.includes(session.viewer ?? "") &&
viewerMember(item, session.viewer) &&
!picked.has(item.id) &&
item.name.toLowerCase().includes(needle),
)
Expand Down
5 changes: 2 additions & 3 deletions src/bundled/bestie/BestieConversation.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { viewerMember } from "../../features/relay/membership";
import {
useCallback,
useEffect,
Expand Down Expand Up @@ -559,9 +560,7 @@ export function BestieConversation({
current.cached ||
(current.readOnly &&
current.viewerRole !== "guest") ||
!current.members?.includes(
session.viewer ?? "",
) ||
!viewerMember(current, session.viewer) ||
!host.panels.snapshot().includes(panel) ||
!panel.channelMenu?.eligible(current, session)
)
Expand Down
110 changes: 77 additions & 33 deletions src/bundled/bestie/PinnedBestie.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,15 @@ async function fixture({
owner.dispose();
});
const send = vi.fn<typeof owner.session.messages.send>(() => "d".repeat(64));
let channelListOverride:
| ReturnType<typeof owner.session.channels.list>
| undefined;
const session = {
...owner.session,
channels: {
...owner.session.channels,
list: () => channelListOverride ?? owner.session.channels.list(),
},
agentChoices,
messages: { ...owner.session.messages, send },
};
Expand Down Expand Up @@ -365,6 +372,9 @@ async function fixture({
find: () => undefined,
} as unknown as Agents;
return {
setChannelList(next: ReturnType<typeof owner.session.channels.list>) {
channelListOverride = next;
},
setPanels(next: readonly RegisteredPanel[]) {
panels = next;
for (const listener of panelListeners) listener();
Expand Down Expand Up @@ -1086,39 +1096,73 @@ it("offers the shared DM actions and channel details in Bestie", async () => {
).toBeInTheDocument();
});

it("opens eligible plugin menu items in the Bestie workspace", async () => {
const f = await fixture({ existing: true });
f.choose(pollen);
const user = userEvent.setup();
f.setPanels([
{
id: "canvas",
key: "test/canvas",
pluginId: "test",
revision: "1",
title: "Canvas",
matches: () => false,
channelMenu: {
label: "View canvas",
eligible: (channel) => channel.id === pollenDM,
},
component: ({ channelContext }) => (
<p>Canvas for {channelContext?.channelId}</p>
),
} satisfies RegisteredPanel,
]);
f.mount();
await user.click(
await screen.findByRole("button", { name: "Channel actions" }),
);
await user.click(
await screen.findByRole("menuitem", { name: "View canvas" }),
);
expect(await screen.findByText(`Canvas for ${pollenDM}`)).toBeVisible();
expect(
screen.getByRole("textbox", { name: "Message Pollen" }),
).toBeInTheDocument();
});
it.each([
"legacy roster",
"joined without peers",
"denied with retained peers",
])(
"opens eligible Bestie menu panels using viewer authority: %s",
async (membership) => {
const f = await fixture({ existing: true });
f.choose(pollen);
const user = userEvent.setup();
f.setPanels([
{
id: "canvas",
key: "test/canvas",
pluginId: "test",
revision: "1",
title: "Canvas",
matches: () => false,
channelMenu: {
label: "View canvas",
eligible: (channel) => channel.id === pollenDM,
},
component: ({ channelContext }) => (
<p>Canvas for {channelContext?.channelId}</p>
),
} satisfies RegisteredPanel,
]);
f.mount();
await user.click(
await screen.findByRole("button", { name: "Channel actions" }),
);
const action = await screen.findByRole("menuitem", { name: "View canvas" });
// Change only the authoritative read at click time. The rendered menu is
// already open, so denial must be rechecked by the Bestie handler itself.
const list = f.session.channels.list();
const current = list.channels.find((channel) => channel.id === pollenDM);
if (!current) throw new Error("Fixture needs the selected DM");
if (membership !== "legacy roster") {
const { members: _peers, ...withoutPeers } = current;
const updated =
membership === "joined without peers"
? {
...withoutPeers,
viewerMembership: { pubkey: f.viewer, joined: true },
}
: {
...current,
viewerMembership: { pubkey: f.viewer, joined: false },
};
f.setChannelList({
...list,
channels: list.channels.map((channel) =>
channel.id === pollenDM ? updated : channel,
),
});
}
await user.click(action);
if (membership === "denied with retained peers") {
expect(screen.queryByText(`Canvas for ${pollenDM}`)).toBeNull();
} else {
expect(await screen.findByText(`Canvas for ${pollenDM}`)).toBeVisible();
}
expect(
screen.getByRole("textbox", { name: "Message Pollen" }),
).toBeInTheDocument();
},
);

it("opens the DM an addition lands in, when Bestie's Members starts or finds another", async () => {
const f = await fixture();
Expand Down
3 changes: 2 additions & 1 deletion src/bundled/bestie/PrivateChannels.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { viewerMember } from "../../features/relay/membership";
import { useEffect, useId, useLayoutEffect, useRef, useState } from "react";
import { administerMember } from "../../features/channel-members/administration";
import { canAddMembers } from "../../features/channel-members/members";
Expand Down Expand Up @@ -32,7 +33,7 @@ export function privateChannels(
!channel.huddle &&
(channel.channelType === "stream" || channel.channelType === "forum") &&
channel.private &&
channel.members?.includes(viewer),
viewerMember(channel, viewer),
)
.sort(compareRecent);
return {
Expand Down
3 changes: 2 additions & 1 deletion src/bundled/bestie/chat.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { viewerMember } from "../../features/relay/membership";
import type { ChannelSummary } from "../../features/relay/contracts";

/** The verified one-to-one DM with this Bestie. Solo chats stay separate. */
Expand All @@ -13,7 +14,7 @@ export function bestieChat(
channel.channelType === "dm" &&
!channel.cached &&
!channel.archived &&
channel.members?.includes(viewer) &&
viewerMember(channel, viewer) &&
onlyOther(channel.members, viewer) === bestie,
)
.sort(
Expand Down
3 changes: 2 additions & 1 deletion src/bundled/channels/ChannelCompletion.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { viewerMember } from "../../features/relay/membership";
import { useContext, useLayoutEffect, useSyncExternalStore } from "react";
import { channelIcon } from "../../features/channels/channel-icon";
import { usePublicChannelSearch } from "../../features/channels/usePublicChannelSearch";
Expand Down Expand Up @@ -38,7 +39,7 @@ function joined(channel: ChannelSummary, viewer: string | undefined) {
!!viewer &&
referable(channel) &&
(!channel.readOnly || channel.viewerRole === "guest" || !!channel.cached) &&
!!channel.members?.includes(viewer)
viewerMember(channel, viewer)
);
}

Expand Down
68 changes: 67 additions & 1 deletion src/bundled/channels/ChannelsPage.tabs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ async function page(
sidebarPreferences?: RelaySession["sidebarPreferences"],
uploadAttachment?: (file: File) => Promise<never>,
linkedPanel?: Partial<RegisteredPanel>,
menuPanel = false,
) {
const viewer = keypair(),
authority = keypair();
Expand Down Expand Up @@ -179,6 +180,17 @@ async function page(
await vi.waitFor(() =>
expect(owner.session.channels.list().status).toBe("ready"),
);
let channelListOverride:
| ReturnType<RelaySession["channels"]["list"]>
| undefined;
const menuSession = menuPanel
? (Object.defineProperty(Object.create(owner.session), "channels", {
value: {
...owner.session.channels,
list: () => channelListOverride ?? owner.session.channels.list(),
},
}) as RelaySession)
: undefined;
const snapshot = {
status: "ready" as const,
generation: 1,
Expand All @@ -193,7 +205,7 @@ async function page(
value: sidebarPreferences,
},
) as typeof owner.session)
: owner.session,
: (menuSession ?? owner.session),
};
const relay: RelayData = {
snapshot: () => snapshot,
Expand All @@ -211,6 +223,9 @@ async function page(
title: "Notes",
matches: () => false,
channelPlacement: "tab",
...(menuPanel && {
channelMenu: { label: "View notes", eligible: () => true },
}),
channelLauncher: ({ context, toggle }) => (
<button type="button" onClick={() => toggle(context.channelId)}>
Open notes
Expand Down Expand Up @@ -302,10 +317,61 @@ async function page(
root: root?.id,
navigation,
events,
setChannelList: (list: ReturnType<RelaySession["channels"]["list"]>) => {
channelListOverride = list;
},
present: (request: PageNavigation) => mounted.rerender(view(request)),
};
}

it.each([
"legacy roster",
"joined without peers",
"denied with retained peers",
])(
"opens Channels menu panels using live viewer authority: %s",
async (membership) => {
const h = await page(
"stream",
undefined,
false,
undefined,
undefined,
undefined,
undefined,
true,
);
await h.user.click(screen.getByRole("button", { name: "Channel actions" }));
const action = await screen.findByRole("menuitem", { name: "View notes" });
const list = h.session.channels.list();
const channel = list.channels.find((item) => item.id === "alpha");
if (!channel) throw new Error("Fixture needs Alpha");
if (membership !== "legacy roster") {
const { members: _peers, ...withoutPeers } = channel;
const updated = {
...(membership === "joined without peers" ? withoutPeers : channel),
viewerMembership: {
pubkey: h.viewer,
joined: membership === "joined without peers",
},
};
h.setChannelList({
...list,
channels: list.channels.map((item) =>
item.id !== channel.id ? item : updated,
),
});
}
await h.user.click(action);
if (membership === "denied with retained peers")
expect(screen.queryByRole("textbox", { name: "Notes draft" })).toBeNull();
else
expect(
await screen.findByRole("textbox", { name: "Notes draft" }),
).toBeVisible();
},
);

it("passes only the visible side thread's root to the timeline and clears it when hidden or moved", async () => {
// A routed thread opens inline under the default; this is about its tab.
setThreadPlacementPreference("side");
Expand Down
7 changes: 3 additions & 4 deletions src/bundled/channels/ChannelsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { viewerMember } from "../../features/relay/membership";
import { useChannelHistoryFocus } from "./useChannelHistoryFocus";
import type { Conversation } from "../../features/conversation/service";
import { StartLinkedChat, canStartLinkedChat } from "./StartLinkedChat";
Expand Down Expand Up @@ -2354,7 +2355,7 @@ function ChannelWorkspace({
!item.cached &&
!item.readOnly &&
!item.archived &&
item.members?.includes(queries.viewer ?? ""),
viewerMember(item, queries.viewer),
);
if (linkedChat && linkedChat.id !== current?.id) {
const id = `conversation:${linkedChat.id}`;
Expand Down Expand Up @@ -3248,9 +3249,7 @@ function ChannelWorkspace({
channel.cached ||
(channel.readOnly &&
channel.viewerRole !== "guest") ||
!channel.members?.includes(
queries.viewer ?? "",
) ||
!viewerMember(channel, queries.viewer) ||
!panels.snapshot().includes(panel) ||
!panel.channelMenu?.eligible(channel, queries)
)
Expand Down
14 changes: 14 additions & 0 deletions src/bundled/channels/canvas-panel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ it("lets a joined Guest read the canvas and reacts to promotion and demotion", a
const panel = panels.snapshot()[0];
assert.exists(panel);
expect(panel?.channelMenu?.eligible(channel, session)).toBe(true);
const { members: _peers, ...withoutPeers } = channel;
expect(
panel?.channelMenu?.eligible(
{ ...withoutPeers, viewerMembership: { pubkey: viewer, joined: true } },
session,
),
).toBe(true);
expect(
panel?.channelMenu?.eligible(
{ ...channel, viewerMembership: { pubkey: viewer, joined: false } },
session,
),
).toBe(false);

expect(
panel?.channelMenu?.eligible({ ...channel, cached: true }, session),
).toBe(false);
Expand Down
3 changes: 2 additions & 1 deletion src/bundled/channels/canvas-panel.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { viewerMember } from "../../features/relay/membership";
import { useSyncExternalStore } from "react";
import type { Context } from "@deepseek-ai/cordis";
import { useListedChannel } from "../../features/relay/listed-channel";
Expand All @@ -14,7 +15,7 @@ function eligible(channel: ChannelSummary, session: RelaySession) {
return (
!channel.cached &&
(!channel.readOnly || channel.viewerRole === "guest") &&
!!channel.members?.includes(session.viewer ?? "")
viewerMember(channel, session.viewer)
);
}

Expand Down
10 changes: 10 additions & 0 deletions src/bundled/channels/useConversationTabs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2480,6 +2480,16 @@ it.each([
cachedOnly: true,
text: "This conversation will appear once Buzz reconnects.",
},
{
name: "a Solo chat with denied viewer membership and retained peers",
kind: "conversation",
listed: {
channelType: "solo",
members: ["viewer"],
viewerMembership: { pubkey: "viewer", joined: false },
},
text: "This conversation is no longer available.",
},
{
name: "an archived channel",
kind: "conversation",
Expand Down
Loading
Loading