@@ -1210,8 +1210,8 @@ pub async fn get_members_bulk(
12101210/// Only legacy channel types are in either half
12111211/// ([`buzz_core::channel::LEGACY_CHANNEL_TYPES`]): this is the implicit scope
12121212/// of queries that do not name a channel, so system channels and any type
1213- /// added later stay out. A query that names a system channel, or opts in to
1214- /// them , adds them from [`get_readable_system_channel_ids `].
1213+ /// added later stay out. A query that names such a channel, or opts in to
1214+ /// system channels , adds them from [`get_readable_named_only_channels `].
12151215pub async fn get_accessible_channel_ids (
12161216 pool : & PgPool ,
12171217 community_id : CommunityId ,
@@ -1253,24 +1253,30 @@ pub async fn get_accessible_channel_ids(
12531253 . collect ( )
12541254}
12551255
1256- /// Get the system channels a pubkey can read: those where it is an active
1257- /// member, and every open system channel. Uncached, so a caller can trust it
1258- /// for a channel the request names.
1259- pub async fn get_readable_system_channel_ids (
1256+ /// The channels of non-legacy types (system channels, and any type added
1257+ /// later) that a pubkey can read: those where it is an active member, and
1258+ /// every open one. Each comes with its type. Uncached, so a caller can trust
1259+ /// it for a channel the request names.
1260+ ///
1261+ /// These are the channels that [`get_accessible_channel_ids`] leaves out. A
1262+ /// read reaches one only by naming it, or, for system channels, by opting in
1263+ /// to them.
1264+ pub async fn get_readable_named_only_channels (
12601265 pool : & PgPool ,
12611266 community_id : CommunityId ,
12621267 pubkey : & [ u8 ] ,
1263- ) -> Result < Vec < Uuid > > {
1268+ ) -> Result < Vec < ( Uuid , String ) > > {
12641269 let mut connection = crate :: observability:: acquire_writer (
12651270 pool,
12661271 crate :: observability:: WriterOperation :: Authorization ,
12671272 )
12681273 . await ?;
1269- let rows = sqlx :: query (
1274+ let sql = format ! (
12701275 r#"
1271- SELECT c.id AS channel_id
1276+ SELECT c.id AS channel_id, c.channel_type::text AS channel_type
12721277 FROM channels c
1273- WHERE c.community_id = $1 AND c.deleted_at IS NULL AND c.channel_type = 'system'
1278+ WHERE c.community_id = $1 AND c.deleted_at IS NULL
1279+ AND NOT {legacy_types}
12741280 AND (
12751281 c.visibility = 'open'
12761282 OR EXISTS (
@@ -1280,17 +1286,17 @@ pub async fn get_readable_system_channel_ids(
12801286 )
12811287 )
12821288 "# ,
1283- )
1284- . bind ( community_id. as_uuid ( ) )
1285- . bind ( pubkey)
1286- . fetch_all ( & mut * connection)
1287- . await ?;
1289+ legacy_types = crate :: store:: channel:: legacy_channel_type_sql( "c.channel_type" ) ,
1290+ ) ;
1291+ // Built only from the constant type list.
1292+ let rows = sqlx:: query ( sqlx:: AssertSqlSafe ( sql) )
1293+ . bind ( community_id. as_uuid ( ) )
1294+ . bind ( pubkey)
1295+ . fetch_all ( & mut * connection)
1296+ . await ?;
12881297
12891298 rows. into_iter ( )
1290- . map ( |r| {
1291- let id: Uuid = r. try_get ( "channel_id" ) ?;
1292- Ok ( id)
1293- } )
1299+ . map ( |r| Ok ( ( r. try_get ( "channel_id" ) ?, r. try_get ( "channel_type" ) ?) ) )
12941300 . collect ( )
12951301}
12961302
@@ -1340,14 +1346,15 @@ pub async fn system_channel_ids_among(
13401346 . await ?)
13411347}
13421348
1343- /// The IDs in `channel_ids` whose type is not a legacy type
1344- /// ([`buzz_core::channel::LEGACY_CHANNEL_TYPES`]), deleted or not: system
1345- /// channels and any type added later. A filter reads them only by naming them.
1346- pub async fn non_legacy_channel_ids_among (
1349+ /// The channels in `channel_ids` whose type is not a legacy type
1350+ /// ([`buzz_core::channel::LEGACY_CHANNEL_TYPES`]), deleted or not, each with
1351+ /// its type: system channels and any type added later. A filter reads them
1352+ /// only by naming them.
1353+ pub async fn named_only_channels_among (
13471354 pool : & PgPool ,
13481355 community_id : CommunityId ,
13491356 channel_ids : & [ Uuid ] ,
1350- ) -> Result < Vec < Uuid > > {
1357+ ) -> Result < Vec < ( Uuid , String ) > > {
13511358 if channel_ids. is_empty ( ) {
13521359 return Ok ( Vec :: new ( ) ) ;
13531360 }
@@ -1357,10 +1364,11 @@ pub async fn non_legacy_channel_ids_among(
13571364 )
13581365 . await ?;
13591366 let sql = format ! (
1360- "SELECT id FROM channels WHERE community_id = $1 AND id = ANY($2) AND NOT {}" ,
1367+ "SELECT id, channel_type::text FROM channels \
1368+ WHERE community_id = $1 AND id = ANY($2) AND NOT {}",
13611369 crate :: store:: channel:: legacy_channel_type_sql( "channel_type" )
13621370 ) ;
1363- Ok ( sqlx:: query_scalar ( sqlx:: AssertSqlSafe ( sql) )
1371+ Ok ( sqlx:: query_as ( sqlx:: AssertSqlSafe ( sql) )
13641372 . bind ( community_id. as_uuid ( ) )
13651373 . bind ( channel_ids)
13661374 . fetch_all ( & mut * connection)
@@ -1999,14 +2007,15 @@ impl Db {
19992007 get_accessible_channel_ids ( & self . pool , community_id, pubkey) . await
20002008 }
20012009
2002- /// Get the system channels a pubkey can read (member, or open).
2003- #[ datastore_span( name = "get_readable_system_channel_ids" , system = "postgresql" ) ]
2004- pub async fn get_readable_system_channel_ids (
2010+ /// The channels of non-legacy types a pubkey can read (member, or open),
2011+ /// each with its type.
2012+ #[ datastore_span( name = "get_readable_named_only_channels" , system = "postgresql" ) ]
2013+ pub async fn get_readable_named_only_channels (
20052014 & self ,
20062015 community_id : CommunityId ,
20072016 pubkey : & [ u8 ] ,
2008- ) -> Result < Vec < Uuid > > {
2009- get_readable_system_channel_ids ( & self . pool , community_id, pubkey) . await
2017+ ) -> Result < Vec < ( Uuid , String ) > > {
2018+ get_readable_named_only_channels ( & self . pool , community_id, pubkey) . await
20102019 }
20112020
20122021 /// The type of channel `channel_id`, deleted or not, or `None` when no
@@ -2030,15 +2039,15 @@ impl Db {
20302039 system_channel_ids_among ( & self . pool , community_id, channel_ids) . await
20312040 }
20322041
2033- /// The IDs in `channel_ids` whose type is not a legacy type, deleted or
2034- /// not.
2035- #[ datastore_span( name = "non_legacy_channel_ids_among " , system = "postgresql" ) ]
2036- pub async fn non_legacy_channel_ids_among (
2042+ /// The channels in `channel_ids` whose type is not a legacy type, deleted
2043+ /// or not, each with its type .
2044+ #[ datastore_span( name = "named_only_channels_among " , system = "postgresql" ) ]
2045+ pub async fn named_only_channels_among (
20372046 & self ,
20382047 community_id : CommunityId ,
20392048 channel_ids : & [ Uuid ] ,
2040- ) -> Result < Vec < Uuid > > {
2041- non_legacy_channel_ids_among ( & self . pool , community_id, channel_ids) . await
2049+ ) -> Result < Vec < ( Uuid , String ) > > {
2050+ named_only_channels_among ( & self . pool , community_id, channel_ids) . await
20422051 }
20432052
20442053 /// Returns large active-channel rosters whose relay-authored snapshots differ.
0 commit comments