Skip to content

Commit d97f6b4

Browse files
loganjLarry
andauthored
feat(relay): add announce channels with a join_role setting (#8143)
🤖 ## Summary Channels are Buzz's main way to control access, but today they cannot separate reading from writing. In an open channel, anyone who can read can also write. So there is no way to say "many people read, a few people write". Announcements, release feeds, plugin release records and shared configuration all need that. This PR adds **announce channels**: anyone can follow and read them, but only members can post. It does this with one new channel setting and without changing what any role means. - **Roles mean the same thing in every channel.** A *guest* can read and leave, but cannot write. A *member* (or *bot*) can write. *Admins* and *owners* also manage the channel. The relay already had the guest role, but no client used it until now. - **A new setting, `join_role` (`member` | `guest`), picks the role a new person gets** when nobody chooses one: when they join by themselves, or when someone adds them without a role. The default, `member`, keeps today's behavior for every existing channel. - **An open channel with `join_role = guest` is an announce channel.** Anyone can find, read and join it. People who join are guests, so they cannot write until someone makes them a member. The relay enforces these rules, so a client cannot get around them. What each role can do (the same in every channel): | Action | Guest | Member or bot | Admin / owner | | --- | --- | --- | --- | | Read, leave | ✅ | ✅ | ✅ | | Post, reply, edit, delete own, react, artifacts, canvas, forum, pins, topic, typing, workflow messages, save or run workflows, huddles | ❌ | ✅ | ✅ | | Add people | ❌ | ✅ as member, guest or bot | ✅ any role | | Make a guest a member (person or agent) | ❌ | ✅ | ✅ | | Any other role change | ❌ | ❌ | ✅ | | Change name, about, visibility, TTL, `join_role` | ❌ | ❌ | ✅ | Other rules: - **Joining by yourself.** A person who joins (kind:9021), or adds themselves (kind:9000 with their own key), gets the channel's `join_role`. They may ask for `join_role` or a lower role, never a higher one. So in an announce channel nobody can join as a member by themselves. - **Non-members.** A non-member may write only where joining would let them write: an open channel with `join_role = member`. That is today's behavior for open channels. - **Agents.** Agents follow the same rules as people. Any member who can write may make a guest agent a member. Limits that only an agent's owner may lift belong to the later IFC work (its "restricted" agent level), not to this PR. That work only refuses more actions, so it can be added later without breaking anything here. - **Leaving always works.** A member may leave an archived channel too (kind:9022, or kind:9001 naming themselves). The last owner still cannot leave. - **Agent owners keep edit and delete.** Today the human owner of an agent can edit (kind:40003) and delete (kind:9005) that agent's messages without being a member. This PR keeps that existing behavior in announce channels too, and documents and tests it. It does not let the owner post. - **Changing the setting changes no roles.** Existing members can still write after a change to `guest`. Existing guests stay read-only after a change back to `member`. A refused write gets `restricted: only members can post in this channel`. ## Details - **One write rule.** The relay's channel write check decides from the actor's role and the channel's `join_role`. Some event types skip that check and run their own: message edit, deleting your own message (kind:9005), topic and purpose (kind:9002), add-member (kind:9000), workflow messages and joining a huddle. Each of these now uses the same rule. Membership changes (add, remove, leave) do not need write access, so a guest can always leave. If the relay finds a stored `join_role` value it does not know, it treats it as `guest`, so an unknown value can never give more access. - **Admission is decided in the database transaction.** The membership write (`put_member`) makes the whole admission decision inside its transaction, after it takes the channel's membership lock: `join_role` for a missing role tag, the self-join ceiling, guests cannot add people, who may grant admin or owner, and role changes (`MemberRole::may_change_role`). The relay's request check uses the same rules, but the database is the authority, so a write that skips the request check cannot get around them. A change to `visibility` or `join_role` takes the same lock, so an add and a setting change cannot interleave. - **No creator exception.** `put_member` used to give owner to a channel's creator who added themselves to a private channel without an active membership. A removed creator could use that: their join (kind:9021) passes the open-channel check, the channel becomes private before the join takes the membership lock, and the join restored them as owner. Channel creation already makes the creator owner in the same transaction, so the exception is removed. A removed creator is now admitted like anyone else. - **Huddles.** Joining a huddle needs write access in the huddle channel **and** in its parent channel. The relay checks both before the join. When it commits the join, it applies the same rule again while it holds both channels' membership locks: a member needs a role that can post, and a non-member needs an open channel whose `join_role` is `member`. A guest in either channel cannot join. A join is also refused when the joiner loses membership or the channel's `join_role` changes before the commit. - **One lock order.** Each writer that takes more than one of a channel's locks takes them in this order: membership lock, TTL lock, channel row. Settings changes, roster publication, TTL refresh and huddle joins all use this order. Before this change, a `join_role` change on an ephemeral channel at the same time as a roster publication could deadlock. - **Workflows.** Saving a workflow (kind:30620) skips the generic write check, so it now checks the sender's role itself and needs a writing role before anything is stored. Every path that starts a workflow run, including the manual trigger (kind:46020), needs the workflow's owner to hold a writing role now (and an elevated role for an elevated workflow). So a workflow saved while its owner was a member stops running after the owner is made a guest. - **Channel names are checked before storage.** kind:9002 and kind:9007 refuse a name longer than the `channels.name` column (255 characters) before the event is stored. Before this, the relay accepted the event, then the name update failed, and the rest of the update (for example `join_role`) was silently skipped. This PR only adds this check. Storing the event and applying the update in one transaction is a larger change, and it is not in this PR. - **Changing the setting.** Owners and admins send a channel-metadata update (kind:9002) with `["join_role", "guest"]` or `["join_role", "member"]`. Buzz applies these updates as partial updates; a missing tag means "no change". The relay posts a `join_role_changed` system message in the channel. - **What clients see.** The relay signs a channel description event (kind:39000) that clients read. One shared builder now writes it for both the relay and the `buzz-admin` backfill, which had a copy that had drifted from the relay's. It always publishes an explicit `["join_role", …]` tag, plus the standard NIP-29 group access flags: | `visibility` | `join_role` | `public` / `private` | `restricted` | `closed` | | --- | --- | --- | --- | --- | | open | `member` | public | | | | open | `guest` | public | ✓ | | | private | either | private | ✓ | ✓ | This also fixes an old bug: `closed` ("join requests are ignored") was published for every channel, even open channels that accept joins. - **CLI and SDK.** `buzz channels update --join-role guest|member`. `buzz_sdk::build_update_channel` takes a new `join_role` argument and always writes it as an explicit tag. - **Docs.** `NOSTR.md` has an "Announce channels" section with the role table and the flag table. - **Tests.** Relay end-to-end tests, run in the CI relay E2E step: - `test_nip29_announce_channel_wire`: who can set `join_role`, the kind:39000 flags, joining as a guest, refused guest and non-member posts, reactions and adds, member posts, a member making a guest a member who then posts, changing the setting back without changing roles, and leaving. - `test_nip29_member_raises_guest_agent`: a member who is not the agent's owner can make a guest agent a member. - `test_nip29_announce_channel_wire_workflow_send_needs_write_role`: a guest's workflow message is refused; a member's is accepted. - `test_nip29_departure_wire_archived_channel_allows_self_leave`: guests and members can leave an archived channel. - `test_private_channel_any_member_can_invite` now expects a private-channel guest to be refused when it adds someone (it used to expect success). - `test_nip29_announce_channel_wire_workflow_commands_need_write_role`: saving and triggering a workflow, by a member and by a guest, in announce and normal channels; a guest cannot run a workflow saved while it was a member. - `test_nip29_announce_channel_wire_overlong_name_is_refused_before_storage`: a kind:9002 with an overlong name and `join_role` is refused, and kind:39000 still shows the old settings. - `test_nip29_announce_channel_wire_agent_owner_exception`: an agent's owner, as a guest and as a non-member, can edit and delete the agent's messages, while ordinary guests are still refused. - `test_nip29_guest_is_read_only_in_normal_channel`: a guest in an ordinary channel cannot write, and joining an ordinary channel still gives `member`. Unit tables cover the self-join rule for each `join_role`, and every actor, current role and requested role for the role-change rule. Database tests check the admission rules in `put_member` (`put_member_enforces_announce_admission`), that an add which waits on an uncommitted change to `guest` is decided on the new setting (`put_member_waits_for_a_concurrent_join_role_change`), and that a member can make a guest a member but not an admin. Unit tests cover the name limit and the workflow owner rule (`owner_authority_denies_roles_that_cannot_write`). A relay test covers huddle joins with different roles in the huddle and its parent, and a commit after a demotion, a `join_role` change or a lost membership (`huddle_join_needs_a_write_role_in_the_huddle_and_its_parent`). Lock-order tests: `join_role_change_waits_for_a_roster_publication_on_an_ephemeral_channel` reproduced a real deadlock (`40P01`) against the old order. `f2d_join_lock_order_serializes_membership_and_settings_writers` checks that membership and settings writers wait for a join and then succeed. `removed_creator_cannot_rejoin_a_private_channel` checks that `put_member` refuses a removed creator on a private channel, and `removed_creator_join_racing_a_private_switch_is_refused` holds the membership lock so a removed creator's kind:9021 passes the open-channel check, then makes the channel private before the join continues. Each new test was run against the old code and failed. ## Rollout 1. **Before the deploy, count guest rows** (`SELECT count(*) FROM channel_members WHERE role = 'guest' AND removed_at IS NULL`). We expect none. Any guest that exists loses the ability to post, change the topic and add people when this ships. If some exist, decide first whether to make them members. 2. Deploy. Every channel stays `join_role = member`, so nothing else changes. 3. **Do not set any channel to `join_role = guest` until no old relay is running.** Old relays ignore the column, so they would let guests and non-members write in that channel. 4. Rerun the `buzz-admin` channel reconcile so open channels drop the wrong `closed` flag. ## Migration and rollback - Migration `0067` adds `channels.join_role TEXT NOT NULL DEFAULT 'member'` with a CHECK constraint. Postgres stores a constant default in table metadata, so existing rows are not rewritten and there is no backfill. The relay runs the migration at startup. - Existing channels keep the old `closed` flag until their next change, or until the reconcile in Rollout step 4. - **Before rolling back the relay**, set every announce channel back to `join_role = member`. An older relay ignores the column and does not stop guests from writing, so those channels would accept posts from their guests and give `member` to new joiners again. ## Not in this PR Client UI: a Follow button, hiding the composer for guests, and an admin toggle. Clients that ignore the new tag keep working. A guest who tries to post sees the `restricted` error. ## Stack 1. #8143 (this PR): announce channels 2. #8494: store the bot role only for keys with a recorded agent owner --------- Signed-off-by: Logan Johnson <[email protected]> Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
1 parent 1a54eec commit d97f6b4

27 files changed

Lines changed: 3780 additions & 569 deletions

File tree

‎.github/workflows/_ci-relay.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,10 @@ jobs:
627627
cargo test -p buzz-test-client --test e2e_relay invite -- --ignored --nocapture
628628
cargo test -p buzz-test-client --test e2e_relay nip43_membership_snapshots_are_rejected -- --ignored --nocapture
629629
cargo test -p buzz-test-client --test e2e_relay nip29_departure_wire -- --ignored --nocapture
630+
cargo test -p buzz-test-client --test e2e_relay nip29_announce_channel_wire -- --ignored --nocapture
631+
cargo test -p buzz-test-client --test e2e_relay nip29_member_raises_guest_agent -- --ignored --nocapture
632+
cargo test -p buzz-test-client --test e2e_relay nip29_guest_is_read_only_in_normal_channel -- --ignored --nocapture
633+
cargo test -p buzz-test-client --test e2e_relay nip29_relay_rejects_role_change_by_unprivileged_actor -- --ignored --nocapture
630634
env:
631635
RELAY_URL: ws://localhost:3000
632636
GIT_CREDENTIAL_NOSTR_BIN: ${{ github.workspace }}/target/ci/git-credential-nostr

‎NOSTR.md‎

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ PGPASSWORD=buzz_dev psql -h localhost -U buzz -d buzz -c \
5151
| **Deletions (kind:5)** | ✅ | Standard NIP-09; self-authored only. `#h` optional, `#e` required |
5252
| **User profiles (kind:0)** | ✅ | NIP-01 metadata; synced to users table (display_name, avatar, about, NIP-05). NIP-05 handles must canonicalize to this relay's domain — off-domain or invalid handles are silently cleared. If a NIP-05 handle collides with another user's (UNIQUE constraint), the handle is skipped but other profile fields (display_name, avatar, about) are still synced. |
5353
| **Group creation (kind:9007)** | ✅ | NIP-29; include `name` tag, optional `visibility`, `channel_type` and label `t` tags |
54-
| **Add user (kind:9000)** | ✅ | Open: any user, subject to target's `channel_add_policy` (`owner_only`/`nobody` can block). Private: owner/admin only. Self-add bypasses agent policy but not private-channel auth. |
54+
| **Add user (kind:9000)** | ✅ | Open: any user, subject to target's `channel_add_policy` (`owner_only`/`nobody` can block). Private: owner/admin only. Self-add bypasses agent policy but not private-channel auth. A guest cannot add anyone. A new member with no role tag gets the channel's `join_role`; a non-member adding themselves may ask for `join_role` or a lower role. |
5555
| **Remove user (kind:9001)** | ✅ | Self-remove allowed (with last-owner guard). Removing others: owner/admin only. |
56-
| **Edit group metadata (kind:9002)** | ✅ | `name`/`about`/label `t` tags: owner/admin. `topic`/`purpose` tags: any member. |
56+
| **Edit group metadata (kind:9002)** | ✅ | `name`/`about`/label `t`/`visibility`/`ttl`/`archived`/`join_role` tags: owner/admin. `topic`/`purpose` tags: any member except a guest. Buzz applies 9002 as a partial update: an absent tag leaves that setting unchanged. |
5757
| **Admin delete event (kind:9005)** | ✅ | Event author can always delete own. Otherwise owner/admin required. Target must be in same channel. |
5858
| **Group deletion (kind:9008)** | ✅ | Owner only. |
5959
| **Leave group (kind:9022)** | ✅ | Any member. Last-owner guard prevents orphaned groups. |
60-
| **Group metadata (kind:39000)** | ✅ | Relay-signed; always `d`, `name`, `closed`, `["t", <channel_type>]`, `["P", <creator>]` and `["created_at", <unix seconds>]` tags; `about` only if description non-empty; `private` if applicable; `hidden` for DM channels and private system channels |
60+
| **Group metadata (kind:39000)** | ✅ | Relay-signed; always `d`, `name`, `t`, `P`, `created_at`, `join_role`; `public` or `private`; `restricted` and `closed` per the access flags below; `about` only if description non-empty; `hidden` for DM channels and private system channels |
6161
| **Group admins (kind:39001)** | ✅ | Relay-signed; `d`, channel type `t` and creator `P` tags + `p` tags with roles (`owner`, `admin`) |
6262
| **Group members (kind:39002)** | ✅ | Relay-signed; `d`, channel type `t` and creator `P` tags + `p` tags for all members |
6363
| **Membership notifications** | ✅ | kind:44100 (added) / kind:44101 (removed); relay-signed, community-global scope (`channel_id=None` inside the connected community) |
@@ -71,7 +71,7 @@ PGPASSWORD=buzz_dev psql -h localhost -U buzz -d buzz -c \
7171
| **NIP-10 threads** | ✅ | WS-submitted replies with `["e","<root>","","reply"]` tags create `thread_metadata` atomically. Visible in REST thread queries. Unknown parents rejected. |
7272
| **NIP-17 DMs (gift wrap)** | ✅ | kind:1059 accepted with ephemeral signing keys. Stored community-globally (`channel_id=None` inside the connected community). Delivered via `#p`-filtered subscriptions. Not indexed in search. |
7373
| **DM discovery** | ✅ | DM creation emits kind:39000 (with `hidden` tag) + kind:44100 membership notifications. NIP-29 clients discover DMs via standard group discovery flow. |
74-
| **Join request (kind:9021)** | ✅ | Open channels only. Adds member, emits system message + group discovery events + kind:44100 membership notification. Private channels rejected at ingest. |
74+
| **Join request (kind:9021)** | ✅ | Open channels only. Adds the joiner with the channel's `join_role` (`member` by default), emits system message + group discovery events + kind:44100 membership notification. Private channels rejected at ingest. |
7575
| **Edits (kind:40003)** | ⚠️ | Works on the wire but Buzz-only — no standard NIP-29 client renders these |
7676
| **Rich content (kind:40002)** | ⚠️ | Works on the wire but Buzz-only — no standard NIP-29 client renders these |
7777

@@ -100,6 +100,61 @@ relay to specific external Nostr identities without granting full access.
100100
SELECT encode(pubkey, 'hex'), added_at, note FROM pubkey_allowlist;
101101
```
102102

103+
### Announce channels
104+
105+
Roles have the same permissions in every channel. A channel's settings
106+
decide only who can join and which role a new person gets:
107+
108+
- `visibility` (`open` | `private`) decides who can find, join and read.
109+
- `join_role` (`member` | `guest`) is the role a person gets when nobody
110+
picks one: a self-join (kind:9021, or a kind:9000 self-add), or a kind:9000
111+
add with no `role` tag. The default, `member`, keeps today's behavior.
112+
113+
An open channel with `join_role = guest` is an **announce channel**: anyone
114+
can find, read and join it, but people who join are guests and cannot write.
115+
116+
What each role can do:
117+
118+
| Action | Guest | Member or bot | Admin / owner |
119+
|--------|-------|---------------|---------------|
120+
| Read, leave | Yes | Yes | Yes |
121+
| Post, reply, edit, delete own, react, artifacts, canvas, forum, pins, typing, workflow messages, huddles | No | Yes | Yes |
122+
| Topic, purpose (kind:9002) | No | Yes | Yes |
123+
| Add people (kind:9000) | No | Yes, as member, guest or bot | Yes, any role |
124+
| Push to the channel's git repositories | No | Yes | Yes |
125+
| Name, about, visibility, TTL, `join_role` | No | No | Yes |
126+
127+
A non-member may write only where joining would give a role that can write:
128+
an open channel with `join_role = member`. A refused write gets
129+
`restricted: only members can post in this channel`.
130+
131+
Other rules:
132+
133+
- A non-member adding themselves with kind:9000 may ask for `join_role` or a
134+
lower role. A higher role is refused.
135+
- Any member who can write (member, bot, owner or admin) can make a guest a
136+
member with kind:9000 (`role` `member`). This is the same for a person and
137+
an agent. Only owners and admins can make any other role change.
138+
- The human owner of an agent can edit (kind:40003) and delete (kind:9005)
139+
that agent's messages, also as a guest or a non-member. This is existing
140+
behavior. It lets a person correct or remove what their agent posted; it
141+
does not let them post.
142+
- Owners and admins change the setting with kind:9002
143+
`["join_role", "guest"]` or `["join_role", "member"]`. A missing tag means
144+
"no change". Changing it does not change anyone's role: existing members
145+
can still write after a change to `guest`, and existing guests stay
146+
read-only after a change to `member`. A stored value the relay does not
147+
know is treated as `guest`.
148+
149+
kind:39000 publishes the NIP-29 access flags from these settings, and an
150+
explicit `["join_role", ...]` tag so clients can tell what joining gives:
151+
152+
| `visibility` | `join_role` | `private` | `public` | `restricted` | `closed` |
153+
|--------------|-------------|-----------|----------|--------------|----------|
154+
| open | `member` | | ✓ | | |
155+
| open | `guest` | | ✓ | ✓ | |
156+
| private | either | ✓ | | ✓ | ✓ |
157+
103158
### Group Discovery
104159

105160
The relay emits NIP-29 group state events when channels are created, updated, or membership changes.
@@ -109,7 +164,7 @@ All discovery events include a `d` tag set to the channel UUID (NIP-29 addressab
109164

110165
| Kind | Tags | Content |
111166
|------|------|---------|
112-
| **39000** | `d=<uuid>`, `name`, `closed`, `t=<channel_type>`, `P=<creator>`, `created_at=<unix seconds>` (always); `about` (if description non-empty); `private` (if applicable); `hidden` (DM channels and private system channels) | Group metadata. **Note:** `closed` is always emitted per NIP-29 convention (Buzz channels require explicit membership), but open channels are still readable/writable by non-members at runtime. The tag reflects the membership model, not access enforcement. |
167+
| **39000** | `d=<uuid>`, `name`, `t=<channel_type>`, `P=<creator>`, `created_at=<unix seconds>`, `join_role` (always); `public` or `private`; `restricted` (private channels, and `join_role=guest`); `closed` (private channels only); `about` (if description non-empty); `hidden` (DM channels and private system channels) | Group metadata. The access flags follow the channel settings (see [Announce channels](#announce-channels)). |
113168
| **39001** | `d=<uuid>`, `t=<channel_type>`, `P=<creator>`, `p` tags with role label (`owner`, `admin`) | Admin list |
114169
| **39002** | `d=<uuid>`, `t=<channel_type>`, `P=<creator>`, `p` tags for all members | Member list |
115170

‎crates/buzz-admin/src/main.rs‎

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ async fn reconcile_channels(
716716
channel_arg: Option<String>,
717717
relay_key_arg: Option<String>,
718718
) -> Result<()> {
719-
use buzz_core::channel::{channel_created_at_tag, group_state_identity_tags};
719+
use buzz_core::channel::group_state_identity_tags;
720720
use buzz_core::kind::KIND_NIP29_GROUP_ADMINS;
721721
use buzz_db::event::EventQuery;
722722

@@ -801,31 +801,10 @@ async fn reconcile_channels(
801801
if target_channel.is_none() {
802802
// kind:39000 — channel metadata
803803
{
804-
let mut tags: Vec<Tag> = vec![Tag::parse(["d", &channel_id_str])?];
805-
tags.push(Tag::parse(["name", &channel.name])?);
806-
if let Some(ref desc) = channel.description {
807-
if !desc.is_empty() {
808-
tags.push(Tag::parse(["about", desc])?);
809-
}
810-
}
811-
if channel.visibility == "private" {
812-
tags.push(Tag::parse(["private"])?);
813-
} else {
814-
tags.push(Tag::parse(["public"])?);
815-
}
816-
if channel.channel_type == "dm"
817-
|| (channel.channel_type == "system" && channel.visibility == "private")
818-
{
819-
tags.push(Tag::parse(["hidden"])?);
820-
}
821-
tags.push(Tag::parse(["closed"])?);
822-
tags.extend(group_state_identity_tags(
823-
&channel.channel_type,
824-
&channel.labels,
825-
&channel.created_by,
826-
)?);
827-
tags.push(channel_created_at_tag(channel.created_at.timestamp())?);
828-
804+
let tags = buzz_db::channel::group_metadata_tags(channel, &members)
805+
.into_iter()
806+
.map(Tag::parse)
807+
.collect::<Result<Vec<_>, _>>()?;
829808
let event = EventBuilder::new(Kind::Custom(39000), "")
830809
.tags(tags)
831810
.sign_with_keys(&relay_keys)

‎crates/buzz-cli/src/commands/channels.rs‎

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,16 +1598,23 @@ fn validate_update_channel_fields(
15981598
description: Option<&str>,
15991599
visibility: Option<&str>,
16001600
ttl_change: Option<Option<i32>>,
1601+
join_role: Option<buzz_sdk::ChannelJoinRole>,
16011602
) -> Result<(), CliError> {
1602-
if name.is_none() && description.is_none() && visibility.is_none() && ttl_change.is_none() {
1603+
if name.is_none()
1604+
&& description.is_none()
1605+
&& visibility.is_none()
1606+
&& ttl_change.is_none()
1607+
&& join_role.is_none()
1608+
{
16031609
return Err(CliError::Usage(
1604-
"at least one field required (--name, --description, --visibility, --ttl, --no-ttl)"
1610+
"at least one field required (--name, --description, --visibility, --ttl, --no-ttl, --join-role)"
16051611
.into(),
16061612
));
16071613
}
16081614
Ok(())
16091615
}
16101616

1617+
#[allow(clippy::too_many_arguments)]
16111618
pub async fn cmd_update_channel(
16121619
client: &BuzzClient,
16131620
channel_id: &str,
@@ -1616,6 +1623,7 @@ pub async fn cmd_update_channel(
16161623
visibility: Option<&str>,
16171624
ttl: Option<i64>,
16181625
no_ttl: bool,
1626+
join_role: Option<buzz_sdk::ChannelJoinRole>,
16191627
) -> Result<(), CliError> {
16201628
// Outer Option: None leaves TTL unchanged. Inner: Some(secs) sets it,
16211629
// None (from --no-ttl) clears it, making the channel permanent.
@@ -1625,12 +1633,18 @@ pub async fn cmd_update_channel(
16251633
(None, false) => None,
16261634
};
16271635

1628-
validate_update_channel_fields(name, description, visibility, ttl_change)?;
1636+
validate_update_channel_fields(name, description, visibility, ttl_change, join_role)?;
16291637
let channel_uuid = parse_uuid(channel_id)?;
16301638

1631-
let builder =
1632-
buzz_sdk::build_update_channel(channel_uuid, name, description, visibility, ttl_change)
1633-
.map_err(|e| CliError::Other(format!("build_update_channel failed: {e}")))?;
1639+
let builder = buzz_sdk::build_update_channel(
1640+
channel_uuid,
1641+
name,
1642+
description,
1643+
visibility,
1644+
ttl_change,
1645+
join_role,
1646+
)
1647+
.map_err(|e| CliError::Other(format!("build_update_channel failed: {e}")))?;
16341648

16351649
let event = client.sign_event(builder)?;
16361650
let resp = client.submit_event(event).await?;
@@ -1931,6 +1945,7 @@ pub async fn dispatch(
19311945
visibility,
19321946
ttl,
19331947
no_ttl,
1948+
join_role,
19341949
} => {
19351950
let visibility = visibility.as_ref().map(|v| v.to_string());
19361951
cmd_update_channel(
@@ -1941,6 +1956,7 @@ pub async fn dispatch(
19411956
visibility.as_deref(),
19421957
ttl,
19431958
no_ttl,
1959+
join_role.map(Into::into),
19441960
)
19451961
.await
19461962
}
@@ -2130,7 +2146,7 @@ mod tests {
21302146

21312147
#[test]
21322148
fn update_channel_fields_rejects_empty_update() {
2133-
let result = validate_update_channel_fields(None, None, None, None);
2149+
let result = validate_update_channel_fields(None, None, None, None, None);
21342150
assert!(matches!(result, Err(CliError::Usage(_))));
21352151
let msg = result.unwrap_err().to_string();
21362152
assert!(msg.contains("at least one field required"));
@@ -2139,7 +2155,7 @@ mod tests {
21392155

21402156
#[test]
21412157
fn update_channel_fields_accepts_visibility_only_update() {
2142-
let result = validate_update_channel_fields(None, None, Some("open"), None);
2158+
let result = validate_update_channel_fields(None, None, Some("open"), None, None);
21432159
assert!(result.is_ok(), "visibility-only update should be accepted");
21442160
}
21452161

‎crates/buzz-cli/src/lib.rs‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,27 @@ impl std::fmt::Display for ChannelVisibility {
191191
}
192192
}
193193

194+
/// The role a new person gets in a channel (`join_role`).
195+
#[derive(Clone, Copy, clap::ValueEnum)]
196+
pub enum ChannelJoinRoleArg {
197+
/// New people become members (default).
198+
#[value(name = "member")]
199+
Member,
200+
/// New people become guests, who can read but not write. On an open
201+
/// channel this makes an announce channel.
202+
#[value(name = "guest")]
203+
Guest,
204+
}
205+
206+
impl From<ChannelJoinRoleArg> for buzz_sdk::ChannelJoinRole {
207+
fn from(value: ChannelJoinRoleArg) -> Self {
208+
match value {
209+
ChannelJoinRoleArg::Member => Self::Member,
210+
ChannelJoinRoleArg::Guest => Self::Guest,
211+
}
212+
}
213+
}
214+
194215
#[derive(Clone, clap::ValueEnum)]
195216
pub enum PresenceStatus {
196217
#[value(name = "online")]
@@ -671,9 +692,9 @@ pub enum ChannelsCmd {
671692
#[arg(long, value_name = "PATH")]
672693
templates_file: Option<String>,
673694
},
674-
/// Update channel name, description, visibility, or ephemeral TTL
695+
/// Update channel name, description, visibility, join role, or ephemeral TTL
675696
#[command(
676-
after_help = "Examples:\n buzz channels update --channel <uuid> --name general\n buzz channels update --channel <uuid> --visibility open\n buzz channels update --channel <uuid> --visibility private"
697+
after_help = "Examples:\n buzz channels update --channel <uuid> --name general\n buzz channels update --channel <uuid> --visibility open\n buzz channels update --channel <uuid> --visibility private\n buzz channels update --channel <uuid> --join-role guest"
677698
)]
678699
Update {
679700
/// Channel UUID
@@ -695,6 +716,11 @@ pub enum ChannelsCmd {
695716
/// Clear an existing TTL, making the channel permanent.
696717
#[arg(long)]
697718
no_ttl: bool,
719+
/// The role a new person gets when nobody picks one. `guest` on an
720+
/// open channel makes an announce channel: people who join can read
721+
/// but not write. Does not change existing members. Owner/admin only.
722+
#[arg(long, value_enum)]
723+
join_role: Option<ChannelJoinRoleArg>,
698724
},
699725
/// Set the channel topic
700726
Topic {

0 commit comments

Comments
 (0)