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
9 changes: 9 additions & 0 deletions docs/buzz-help.md
Original file line number Diff line number Diff line change
Expand Up @@ -1904,3 +1904,12 @@ occurs. It contains operation metadata, with no draft text or secrets. See
## Plugin account actions

Plugins can add actions to your avatar menu. Profile-related actions may appear just above Settings; other plugin actions appear below it.


### Viewer participation in channels

Channel owners and admins can use **Edit details** to allow viewers to reply in
threads and to react, independently, when the community supports these settings.
Both are off by default. Viewers still cannot start conversations or send replies
to the channel feed. Changing general access affects future joiners; existing
members keep their roles until an owner or admin changes them.
39 changes: 38 additions & 1 deletion src-tauri/src/relay/channel_writes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn common(event: &EventTemplate) -> bool {
event.content.is_empty() && event.created_at <= i64::MAX as u64
}
fn details(event: &EventTemplate) -> bool {
if event.kind != 9002 || !common(event) || !(3..=14).contains(&event.tags.len()) {
if event.kind != 9002 || !common(event) || !(3..=16).contains(&event.tags.len()) {
return false;
}
let (Some(id), Some(name), Some(about)) = (
Expand Down Expand Up @@ -54,6 +54,14 @@ fn details(event: &EventTemplate) -> bool {
}
index += 1;
}
for key in ["guest_replies", "guest_reactions"] {
if let Some(value) = tag(event, index, key) {
if !matches!(value, "true" | "false") {
return false;
}
index += 1;
}
}
let labels = &event.tags[index..];
let labels_valid = details_labels(labels);
uuid(id)
Expand Down Expand Up @@ -633,6 +641,35 @@ mod boundary_tests {
}
}

#[test]
fn details_admit_only_explicit_guest_contribution_booleans() {
for value in ["true", "false"] {
let event = serde_json::to_value(details_event(vec![
vec!["guest_replies".into(), value.into()],
vec!["guest_reactions".into(), value.into()],
]))
.unwrap();
assert!(validate("channel-details", &event, None).is_ok());
assert!(validate("channel-lifecycle", &event, None).is_err());
}
for tags in [
vec![vec!["guest_replies", "yes"]],
vec![vec!["guest_reactions", ""]],
vec![
vec!["guest_replies", "true"],
vec!["guest_replies", "false"],
],
] {
let event = serde_json::to_value(details_event(
tags.into_iter()
.map(|tag| tag.into_iter().map(str::to_owned).collect())
.collect(),
))
.unwrap();
assert!(validate("channel-details", &event, None).is_err());
}
}

#[test]
fn details_admit_only_member_and_guest_admission_defaults() {
let host = IdentityHost::fixture();
Expand Down
32 changes: 32 additions & 0 deletions src/bundled/channels/ChannelDetailsEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1505,3 +1505,35 @@ it("keeps invited-only Read access intact when editing details", async () => {
expect.any(AbortSignal),
);
});

it("saves independent viewer grants through the existing details editor", async () => {
const h = harness();
const grants = { ...base, guestReplies: false, guestReactions: false };
h.load.mockResolvedValue(grants);
const user = userEvent.setup();
render(
<ChannelDetailsEditor
scope="community:viewer"
capability={h.capability}
channel={channel}
/>,
);
await user.click(await screen.findByRole("button", { name: "Edit details" }));
const replies = screen.getByRole("switch", {
name: "Allow viewers to reply in threads",
});
const reactions = screen.getByRole("switch", {
name: "Allow viewers to react",
});
expect(replies).not.toBeChecked();
expect(reactions).not.toBeChecked();
await user.click(replies);
expect(replies).toBeChecked();
expect(reactions).not.toBeChecked();
await user.click(screen.getByRole("button", { name: "Save changes" }));
expect(h.save).toHaveBeenCalledWith(
grants,
{ ...grants, guestReplies: true },
expect.any(AbortSignal),
);
});
31 changes: 31 additions & 0 deletions src/bundled/channels/ChannelDetailsEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
type ChannelDetails,
type ChannelDetailsDraft,
} from "../../features/relay/channel-details-protocol";
import { Switch } from "../../shared/design-system/ui/Switch";
import { Button } from "../../shared/design-system/ui/Button";
import { Dialog } from "../../shared/design-system/ui/Dialog";
import { ChannelDurationField } from "./ChannelDurationField";
Expand Down Expand Up @@ -159,6 +160,8 @@ export function ChannelDetailsEditor({
normalized.description !== view.base.description ||
normalized.visibility !== view.base.visibility ||
normalized.joinRole !== view.base.joinRole ||
normalized.guestReplies !== view.base.guestReplies ||
normalized.guestReactions !== view.base.guestReactions ||
normalized.ttlSeconds !== view.base.ttlSeconds);
const temporaryTtl =
draft?.ttlSeconds ??
Expand Down Expand Up @@ -201,6 +204,8 @@ export function ChannelDetailsEditor({
draft.description !== view.base.description ||
draft.visibility !== view.base.visibility ||
draft.joinRole !== view.base.joinRole ||
draft.guestReplies !== view.base.guestReplies ||
draft.guestReactions !== view.base.guestReactions ||
draft.ttlSeconds !== view.base.ttlSeconds);
const requestClose = () => {
if (pending || busy.current) return;
Expand Down Expand Up @@ -417,6 +422,32 @@ export function ChannelDetailsEditor({
patch({ draft: { ...draft, description } })
}
/>
{["stream", "forum"].includes(channel.channelType ?? "") &&
view.base?.guestReplies !== undefined &&
view.base.guestReactions !== undefined && (
<>
<Switch
label="Allow viewers to reply in threads"
checked={draft.guestReplies ?? false}
disabled={locked || !canEdit}
onCheckedChange={(guestReplies) =>
patch({ draft: { ...draft, guestReplies } })
}
/>
<Switch
label="Allow viewers to react"
checked={draft.guestReactions ?? false}
disabled={locked || !canEdit}
onCheckedChange={(guestReactions) =>
patch({ draft: { ...draft, guestReactions } })
}
/>
<p className="text-caption text-subtle">
Viewers cannot start conversations. Existing members
keep their posting access.
</p>
</>
)}
<ChannelDurationField
temporary={draft.ttlSeconds !== undefined}
ttlSeconds={temporaryTtl}
Expand Down
4 changes: 3 additions & 1 deletion src/bundled/channels/ChannelGeneralAccess.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ export function ChannelGeneralAccess({
</p>
<p className="text-caption text-subtle">
{channel.viewerRole === "guest" || channel.joinRole === "guest"
? "Viewing only. Ask an owner or admin to participate."
? channel.guestReplies || channel.guestReactions
? `Viewers can ${[channel.guestReplies ? "reply in threads" : "", channel.guestReactions ? "react" : ""].filter(Boolean).join(" and ")}. Only members with posting access can start conversations.`
: "Viewing only. Ask an owner or admin to participate."
: channel.joinRole === "member"
? `New people can participate. People already in the ${policy?.subject ?? "channel"} keep their access.`
: "New people’s access could not be confirmed."}
Expand Down
34 changes: 32 additions & 2 deletions src/features/messages/MediaReviewViewer.comments.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type MediaKind = "image" | "video";
type ReviewFixtureOptions = {
kind: MediaKind;
typingAgent?: ReturnType<typeof keypair>;
guestReplies?: boolean;
openComments?: boolean;
replies?: (
viewer: ReturnType<typeof keypair>,
Expand All @@ -57,6 +58,7 @@ function mime(kind: MediaKind) {
async function setupReview({
kind,
typingAgent,
guestReplies = false,
openComments = true,
replies: buildReplies = () => [],
extraRootTags = [],
Expand Down Expand Up @@ -130,8 +132,23 @@ async function setupReview({
return events.filter((event) => event.kind === 0);
if (filter.kinds?.includes(39002) || filter.kinds?.includes(39000))
return [
roster(relay, "one", [viewer.pubkey]),
metadata(relay, "one", "One"),
guestReplies
? signed(relay, {
kind: 39002,
content: "",
created_at: 1_700_000_000,
tags: [
["d", "one"],
["p", viewer.pubkey, "", "guest"],
],
})
: roster(relay, "one", [viewer.pubkey]),
guestReplies
? metadata(relay, "one", "One", 1_700_000_000, [
["t", "stream"],
["guest_replies", "true"],
])
: metadata(relay, "one", "One"),
];
if (filter.ids)
return events.filter((event) => filter.ids?.includes(event.id));
Expand Down Expand Up @@ -835,6 +852,19 @@ it("shares legacy fractional timecodes between timeline markers and sidebar and
).toBeInTheDocument();
});

it("keeps frame reactions writer-only when Guests can reply", async () => {
const { user, sign } = await setupReview({
kind: "video",
guestReplies: true,
});
const react = await screen.findByRole("button", {
name: "React 👍 at current frame",
});
expect(react).toBeDisabled();
await user.click(react);
expect(sign).not.toHaveBeenCalled();
});

it.each(["image", "video"] as const)(
"starts an empty %s review with a dark stage and comments closed",
async (kind) => {
Expand Down
10 changes: 5 additions & 5 deletions src/features/messages/MessageComposer.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { channelCan } from "../relay/channel-permissions";
import { draftEditorId, traceDraft } from "../../shared/draft-diagnostics";
import {
soloModelPicksKey,
Expand Down Expand Up @@ -562,10 +563,8 @@ function Composer({
const listed =
session.channels?.get || soloConversation ? session.channels : undefined;
const channels = () => (listed?.list() ?? noChannels).channels;
const writable = useListedChannel(
listed,
channelId,
(channel) => !!channel && !channel.readOnly && !channel.archived,
const writable = useListedChannel(listed, channelId, (channel) =>
channelCan(channel, threadRootId ? "reply" : "post"),
);
const readOnly = !submission && !!session.channels?.get && !writable;
const cached = useListedChannel(
Expand Down Expand Up @@ -1316,7 +1315,8 @@ function Composer({
const editLocked = useListedChannel(
listed,
channelId,
(channel) => !!channel?.archived || !!channel?.readOnly,
(channel) =>
!!channel && !channelCan(channel, threadRootId ? "reply" : "post"),
);
const editDisabled = disabled || editLocked;
const chips = useMemo(
Expand Down
9 changes: 5 additions & 4 deletions src/features/messages/MessageManagement.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { channelCan } from "../relay/channel-permissions";
import {
BellIcon,
BellSlashIcon,
Expand Down Expand Up @@ -173,7 +174,7 @@ export function useMessageKeyActions(session: RelaySession) {
const channel = joined(row);
return (
!!channel &&
!channel.readOnly &&
channelCan(channel, row.threadRootId ? "reply" : "post") &&
!channel.archived &&
!!session.viewer &&
row.authorId === session.viewer &&
Expand Down Expand Up @@ -247,7 +248,7 @@ export function MessageManagement({
(channel) =>
!!channel &&
!channel.cached &&
(!channel.readOnly ||
(channelCan(channel, selection?.row.threadRootId ? "reply" : "post") ||
(channel.viewerRole === "guest" && !!selection?.authorization)),
);
const available =
Expand Down Expand Up @@ -590,7 +591,7 @@ function ManagedMessageItems({
const writable = useListedChannel(
session.channels,
row.channelId,
(channel) => !!channel && !channel.readOnly && !channel.cached,
(channel) => channelCan(channel, row.threadRootId ? "reply" : "post"),
);
const threadRootId = row.threadRootId ?? row.id;
const following = useSyncExternalStore(session.unread.subscribeSync, () =>
Expand Down Expand Up @@ -745,7 +746,7 @@ function DeleteMessageDialog({
channel.id === row.channelId &&
!channel.archived &&
!channel.cached &&
(!channel.readOnly ||
(channelCan(channel, row.threadRootId ? "reply" : "post") ||
(channel.viewerRole === "guest" && !!authorization)),
)
)
Expand Down
18 changes: 18 additions & 0 deletions src/features/messages/MessageReactions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ function harness(
disabled = false,
onFocusedRemoval,
audience,
removalAllowed = false,
}: {
removalAllowed?: boolean;
audience?: "agents";
disabled?: boolean;
onFocusedRemoval?: () => void;
Expand All @@ -145,6 +147,7 @@ function harness(
/>
</div>
<MessageReactions
removalAllowed={removalAllowed}
{...(onFocusedRemoval ? { onFocusedRemoval } : {})}
row={audience ? { ...row, audience } : row}
session={owner.session}
Expand Down Expand Up @@ -1043,3 +1046,18 @@ it("keeps the raw emoji when the name table fails to load, and the next reveal r
warned.mockRestore();
}
});

it("allows removing an owned reaction while additions remain disabled", async () => {
const h = harness([react(), react(other)]);
render(<h.Controls disabled removalAllowed />);
expect(screen.queryByTestId("inline-add-reaction")).toBeNull();
fireEvent.click(screen.getByRole("button", { name: "👍: 2 people" }));
await waitFor(() => expect(h.publish).toHaveBeenCalledOnce());
expect(h.session.outbox?.snapshot().map((item) => item.event.kind)).toEqual([
5,
]);
fireEvent.click(
screen.getByRole("button", { name: `👍: ${other.pubkey.slice(0, 10)}` }),
);
expect(h.session.outbox?.snapshot()).toHaveLength(1);
});
8 changes: 5 additions & 3 deletions src/features/messages/MessageReactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,20 @@ type Props = {
session: RelaySession;
scope: string;
disabled: boolean;
removalAllowed?: boolean;
tools: ContributionReader<ComposerTool>;
inline: ContributionReader<InlineRenderer>;
};
const noSubscribe = () => () => {};
const noOperations = Object.freeze([]);
const empty = () => noOperations;

function useReactionAction({ row, session, disabled }: Props) {
function useReactionAction({ row, session, disabled, removalAllowed }: Props) {
const presented = useConversationPresentation();
const [error, setError] = useState<string>();
const active = useRef(false);
useLayoutEffect(() => {
active.current = !disabled && presented;
active.current = (!disabled || !!removalAllowed) && presented;
});
useLayoutEffect(
() => () => {
Expand Down Expand Up @@ -79,6 +80,7 @@ function useReactionAction({ row, session, disabled }: Props) {
[];
if (mine.length) session.messages.remove(mine.map((event) => event.id));
else {
if (disabled) return false;
session.messages.react(row.id, content, emoji);
}
setError(undefined);
Expand Down Expand Up @@ -503,7 +505,7 @@ export function MessageReactions(
mine={mine}
session={session}
profiles={props.profiles}
disabled={props.disabled}
disabled={props.disabled && !(mine && props.removalAllowed)}
busy={action.busy}
toggle={action.toggle}
onFocusedRemoval={props.onFocusedRemoval}
Expand Down
Loading
Loading