@@ -701,14 +701,7 @@ const UNLISTED_EXTENSION: &str = "buzz-unlisted-channels";
701701/// ignores `unlisted`, so an open channel would end up listed. Call it before
702702/// anything is written.
703703async fn require_unlisted_support ( client : & BuzzClient ) -> Result < ( ) , CliError > {
704- let raw = client. get_public ( "/info" ) . await ?;
705- let info: serde_json:: Value = serde_json:: from_str ( & raw)
706- . map_err ( |e| CliError :: Other ( format ! ( "invalid NIP-11 response: {e}" ) ) ) ?;
707- let supported = info
708- . get ( "supported_extensions" )
709- . and_then ( |v| v. as_array ( ) )
710- . is_some_and ( |exts| exts. iter ( ) . any ( |e| e. as_str ( ) == Some ( UNLISTED_EXTENSION ) ) ) ;
711- if supported {
704+ if relay_supports_extension ( client, UNLISTED_EXTENSION ) . await ? {
712705 Ok ( ( ) )
713706 } else {
714707 Err ( CliError :: Other ( format ! (
@@ -717,6 +710,18 @@ async fn require_unlisted_support(client: &BuzzClient) -> Result<(), CliError> {
717710 }
718711}
719712
713+ const OFFICIAL_EXTENSION : & str = "buzz-official-channels" ;
714+
715+ async fn relay_supports_extension ( client : & BuzzClient , extension : & str ) -> Result < bool , CliError > {
716+ let raw = client. get_public ( "/info" ) . await ?;
717+ let info: serde_json:: Value = serde_json:: from_str ( & raw)
718+ . map_err ( |e| CliError :: Other ( format ! ( "invalid NIP-11 response: {e}" ) ) ) ?;
719+ Ok ( info
720+ . get ( "supported_extensions" )
721+ . and_then ( |v| v. as_array ( ) )
722+ . is_some_and ( |exts| exts. iter ( ) . any ( |e| e. as_str ( ) == Some ( extension) ) ) )
723+ }
724+
720725pub async fn cmd_create_channel (
721726 client : & BuzzClient ,
722727 name : & str ,
@@ -1671,6 +1676,7 @@ fn validate_ttl_seconds(secs: i64) -> Result<i32, CliError> {
16711676 . map_err ( |_| CliError :: Usage ( format ! ( "--ttl is too large (max {} seconds)" , i32 :: MAX ) ) )
16721677}
16731678
1679+ #[ allow( clippy:: too_many_arguments) ]
16741680fn validate_update_channel_fields (
16751681 name : Option < & str > ,
16761682 description : Option < & str > ,
@@ -1679,6 +1685,7 @@ fn validate_update_channel_fields(
16791685 join_role : Option < buzz_sdk:: ChannelJoinRole > ,
16801686 unlisted : Option < bool > ,
16811687 auto_join : Option < bool > ,
1688+ official : Option < bool > ,
16821689) -> Result < ( ) , CliError > {
16831690 if name. is_none ( )
16841691 && description. is_none ( )
@@ -1687,9 +1694,10 @@ fn validate_update_channel_fields(
16871694 && join_role. is_none ( )
16881695 && unlisted. is_none ( )
16891696 && auto_join. is_none ( )
1697+ && official. is_none ( )
16901698 {
16911699 return Err ( CliError :: Usage (
1692- "at least one field required (--name, --description, --visibility, --ttl, --no-ttl, --join-role, --unlisted, --auto-join)"
1700+ "at least one field required (--name, --description, --visibility, --ttl, --no-ttl, --join-role, --unlisted, --auto-join, --official )"
16931701 . into ( ) ,
16941702 ) ) ;
16951703 }
@@ -1708,6 +1716,7 @@ pub async fn cmd_update_channel(
17081716 join_role : Option < buzz_sdk:: ChannelJoinRole > ,
17091717 unlisted : Option < bool > ,
17101718 auto_join : Option < bool > ,
1719+ official : Option < bool > ,
17111720) -> Result < ( ) , CliError > {
17121721 // Outer Option: None leaves TTL unchanged. Inner: Some(secs) sets it,
17131722 // None (from --no-ttl) clears it, making the channel permanent.
@@ -1725,6 +1734,7 @@ pub async fn cmd_update_channel(
17251734 join_role,
17261735 unlisted,
17271736 auto_join,
1737+ official,
17281738 ) ?;
17291739 let channel_uuid = parse_uuid ( channel_id) ?;
17301740 // `--unlisted false` needs no check: a relay without the extension lists
@@ -1733,7 +1743,13 @@ pub async fn cmd_update_channel(
17331743 require_unlisted_support ( client) . await ?;
17341744 }
17351745
1736- let builder = buzz_sdk:: build_update_channel (
1746+ if official. is_some ( ) && !relay_supports_extension ( client, OFFICIAL_EXTENSION ) . await ? {
1747+ return Err ( CliError :: Other ( format ! (
1748+ "this relay does not support Official channels (missing \" {OFFICIAL_EXTENSION}\" in supported_extensions)"
1749+ ) ) ) ;
1750+ }
1751+
1752+ let builder = buzz_sdk:: build_update_channel_with_official (
17371753 channel_uuid,
17381754 name,
17391755 description,
@@ -1742,6 +1758,7 @@ pub async fn cmd_update_channel(
17421758 join_role,
17431759 unlisted,
17441760 auto_join,
1761+ official,
17451762 )
17461763 . map_err ( |e| CliError :: Other ( format ! ( "build_update_channel failed: {e}" ) ) ) ?;
17471764
@@ -2295,6 +2312,7 @@ pub async fn dispatch(
22952312 join_role,
22962313 unlisted,
22972314 auto_join,
2315+ official,
22982316 } => {
22992317 let visibility = visibility. as_ref ( ) . map ( |v| v. to_string ( ) ) ;
23002318 cmd_update_channel (
@@ -2308,6 +2326,7 @@ pub async fn dispatch(
23082326 join_role. map ( Into :: into) ,
23092327 unlisted,
23102328 auto_join,
2329+ official,
23112330 )
23122331 . await
23132332 }
@@ -2655,7 +2674,7 @@ mod tests {
26552674
26562675 #[ test]
26572676 fn update_channel_fields_rejects_empty_update ( ) {
2658- let result = validate_update_channel_fields ( None , None , None , None , None , None , None ) ;
2677+ let result = validate_update_channel_fields ( None , None , None , None , None , None , None , None ) ;
26592678 assert ! ( matches!( result, Err ( CliError :: Usage ( _) ) ) ) ;
26602679 let msg = result. unwrap_err ( ) . to_string ( ) ;
26612680 assert ! ( msg. contains( "at least one field required" ) ) ;
@@ -2665,7 +2684,7 @@ mod tests {
26652684 #[ test]
26662685 fn update_channel_fields_accepts_visibility_only_update ( ) {
26672686 let result =
2668- validate_update_channel_fields ( None , None , Some ( "open" ) , None , None , None , None ) ;
2687+ validate_update_channel_fields ( None , None , Some ( "open" ) , None , None , None , None , None ) ;
26692688 assert ! ( result. is_ok( ) , "visibility-only update should be accepted" ) ;
26702689 }
26712690
@@ -5357,6 +5376,7 @@ mod unlisted_support_tests {
53575376 None ,
53585377 Some ( true ) ,
53595378 None ,
5379+ None ,
53605380 )
53615381 . await
53625382 . unwrap_err ( ) ;
@@ -5384,6 +5404,7 @@ mod unlisted_support_tests {
53845404 None ,
53855405 Some ( true ) ,
53865406 None ,
5407+ None ,
53875408 )
53885409 . await
53895410 . unwrap ( ) ;
@@ -5393,6 +5414,43 @@ mod unlisted_support_tests {
53935414 assert ! ( submitted. iter( ) . all( has_unlisted_true) ) ;
53945415 }
53955416
5417+ #[ tokio:: test]
5418+ async fn official_updates_require_relay_support ( ) {
5419+ for ( extensions, supported) in [ ( r#"[]"# , false ) , ( r#"["buzz-official-channels"]"# , true ) ] {
5420+ let ( url, submitted) = relay ( extensions) . await ;
5421+ let result = cmd_update_channel (
5422+ & client ( & url) ,
5423+ CHANNEL ,
5424+ None ,
5425+ None ,
5426+ None ,
5427+ None ,
5428+ false ,
5429+ None ,
5430+ None ,
5431+ None ,
5432+ Some ( true ) ,
5433+ )
5434+ . await ;
5435+ let submitted = submitted. lock ( ) . unwrap ( ) ;
5436+ if supported {
5437+ result. expect ( "official update" ) ;
5438+ assert_eq ! ( submitted. len( ) , 1 ) ;
5439+ assert ! ( submitted[ 0 ] [ "tags" ]
5440+ . as_array( )
5441+ . unwrap( )
5442+ . iter( )
5443+ . any( |tag| tag[ 0 ] == "official" && tag[ 1 ] == "true" ) ) ;
5444+ } else {
5445+ assert ! ( result
5446+ . unwrap_err( )
5447+ . to_string( )
5448+ . contains( "buzz-official-channels" ) ) ;
5449+ assert ! ( submitted. is_empty( ) ) ;
5450+ }
5451+ }
5452+ }
5453+
53965454 #[ tokio:: test]
53975455 async fn listed_writes_skip_the_check ( ) {
53985456 // The relay advertises no extensions, so a check would fail the command.
@@ -5413,6 +5471,7 @@ mod unlisted_support_tests {
54135471 None ,
54145472 Some ( false ) ,
54155473 None ,
5474+ None ,
54165475 )
54175476 . await
54185477 . unwrap ( ) ;
0 commit comments