Skip to content

Commit c6ca9d9

Browse files
klopez4212Princess Donut
andauthored
Show status and huddle indicators beside names (block#7112)
## Summary - show status and huddle emoji beside names in DMs and message rows - provide accessible tooltips, fallback status emoji, and profile-menu icon replacement - add the desktop status editor with preset durations, a ShadCN calendar, and a capped half-hour time menu ## Validation - desktop checks, typecheck, and file-size guard - 5,802 desktop tests - focused Playwright coverage (3 passed) - E2E build and native Builderlab staging verification Updated visual snapshots are attached in the PR comments. --------- Signed-off-by: kenny lopez <[email protected]> Signed-off-by: Princess Donut <b238ea756dee4d98afa5883fc7f1de61eeabe65bf700e3a5a5a80db5e42e2c2b@buzz.block.builderlab.xyz> Co-authored-by: Princess Donut <b238ea756dee4d98afa5883fc7f1de61eeabe65bf700e3a5a5a80db5e42e2c2b@buzz.block.builderlab.xyz>
1 parent 6f5ec4a commit c6ca9d9

46 files changed

Lines changed: 6332 additions & 251 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎crates/buzz-core/src/kind.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@ pub const KIND_HUDDLE_PARTICIPANT_JOINED: u32 = 48101;
594594
pub const KIND_HUDDLE_PARTICIPANT_LEFT: u32 = 48102;
595595
/// A huddle ended.
596596
pub const KIND_HUDDLE_ENDED: u32 = 48103;
597+
/// Relay-synthesized authoritative liveness for an active huddle session.
598+
pub const KIND_HUDDLE_LIVENESS: u32 = 48104;
597599
/// Huddle channel guidelines/rules document.
598600
pub const KIND_HUDDLE_GUIDELINES: u32 = 48106;
599601

@@ -750,6 +752,7 @@ pub const ALL_KINDS: &[u32] = &[
750752
KIND_HUDDLE_PARTICIPANT_JOINED,
751753
KIND_HUDDLE_PARTICIPANT_LEFT,
752754
KIND_HUDDLE_ENDED,
755+
KIND_HUDDLE_LIVENESS,
753756
KIND_HUDDLE_GUIDELINES,
754757
KIND_MEDIA_UPLOAD,
755758
KIND_GIT_REPO_ANNOUNCEMENT,

‎crates/buzz-db/src/store/event.rs‎

Lines changed: 118 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,68 @@ fn huddle_started_content_links(content: &str, ephemeral_channel_id: Uuid) -> bo
221221
.is_some_and(|id| id == ephemeral_channel_id)
222222
}
223223

224-
/// Return whether `parent_channel_id` has a creator-signed huddle-start event
225-
/// that links to `ephemeral_channel_id`.
224+
/// Resolve creator-authenticated parent links for a bounded set of huddle sessions.
226225
///
227226
/// The creator constraint matters: a member of some unrelated channel can post
228227
/// their own kind:48100 event there, but they cannot sign as the creator of the
229-
/// target ephemeral channel.
228+
/// target ephemeral channel. One set-based query replaces the liveness
229+
/// endpoint's former session × parent lookup loop. Malformed historical start
230+
/// content is ignored rather than aborting the complete liveness snapshot.
231+
pub async fn huddle_started_links(
232+
pool: &PgPool,
233+
community_id: CommunityId,
234+
parent_channel_ids: &[Uuid],
235+
ephemeral_channel_ids: &[Uuid],
236+
) -> Result<Vec<(Uuid, Uuid, Vec<u8>)>> {
237+
if parent_channel_ids.is_empty() || ephemeral_channel_ids.is_empty() {
238+
return Ok(Vec::new());
239+
}
240+
let rows = sqlx::query(
241+
r#"
242+
SELECT DISTINCT ON (backing.id)
243+
backing.id AS session_id,
244+
start.channel_id AS parent_channel_id,
245+
backing.created_by
246+
FROM events start
247+
JOIN channels backing
248+
ON backing.community_id = start.community_id
249+
AND backing.id::text = CASE
250+
WHEN start.content IS JSON OBJECT
251+
THEN (start.content::json ->> 'ephemeral_channel_id')
252+
ELSE NULL
253+
END
254+
AND backing.deleted_at IS NULL
255+
WHERE start.deleted_at IS NULL
256+
AND start.community_id = $1
257+
AND start.channel_id = ANY($2)
258+
AND start.kind = $3
259+
AND octet_length(start.content) <= $5
260+
AND backing.id = ANY($4)
261+
AND start.pubkey = backing.created_by
262+
ORDER BY backing.id, start.created_at DESC, start.id ASC
263+
"#,
264+
)
265+
.bind(community_id.as_uuid())
266+
.bind(parent_channel_ids)
267+
.bind(KIND_HUDDLE_STARTED as i32)
268+
.bind(ephemeral_channel_ids)
269+
.bind(HUDDLE_LINK_CONTENT_MAX_BYTES)
270+
.fetch_all(pool)
271+
.await?;
272+
273+
rows.into_iter()
274+
.map(|row| {
275+
Ok((
276+
row.try_get("session_id")?,
277+
row.try_get("parent_channel_id")?,
278+
row.try_get("created_by")?,
279+
))
280+
})
281+
.collect()
282+
}
283+
284+
/// Return whether a creator-signed huddle-start event links a parent channel
285+
/// to the requested ephemeral huddle channel.
230286
pub async fn huddle_started_link_exists(
231287
pool: &PgPool,
232288
community_id: CommunityId,
@@ -1702,8 +1758,25 @@ impl Db {
17021758
}
17031759
}
17041760

1761+
/// Resolve creator-signed huddle-start links for bounded parent/session sets.
1762+
#[datastore_span(name = "huddle_started_links", system = "postgresql")]
1763+
pub async fn huddle_started_links(
1764+
&self,
1765+
community_id: CommunityId,
1766+
parent_channel_ids: &[Uuid],
1767+
ephemeral_channel_ids: &[Uuid],
1768+
) -> Result<Vec<(Uuid, Uuid, Vec<u8>)>> {
1769+
crate::event::huddle_started_links(
1770+
&self.pool,
1771+
community_id,
1772+
parent_channel_ids,
1773+
ephemeral_channel_ids,
1774+
)
1775+
.await
1776+
}
1777+
17051778
/// Return whether a creator-signed huddle-start event links a parent
1706-
/// channel to an ephemeral huddle channel.
1779+
/// channel to the requested ephemeral huddle channel.
17071780
#[datastore_span(name = "huddle_started_link_exists", system = "postgresql")]
17081781
pub async fn huddle_started_link_exists(
17091782
&self,
@@ -2723,6 +2796,47 @@ mod postgres_tests {
27232796
);
27242797
}
27252798

2799+
#[tokio::test]
2800+
#[ignore = "requires Postgres"]
2801+
async fn huddle_started_links_batches_valid_creator_links_and_ignores_malformed_content() {
2802+
let pool = setup_pool().await;
2803+
let community_uuid = make_test_community(&pool).await;
2804+
let community = CommunityId::from_uuid(community_uuid);
2805+
let parent = make_test_channel(&pool, community_uuid, None).await;
2806+
let session = make_test_channel(&pool, community_uuid, Some(60)).await;
2807+
let creator = vec![7_u8; 32];
2808+
2809+
for (index, content) in [
2810+
"not-json".to_owned(),
2811+
serde_json::json!({ "ephemeral_channel_id": session }).to_string(),
2812+
]
2813+
.into_iter()
2814+
.enumerate()
2815+
{
2816+
sqlx::query(
2817+
"INSERT INTO events \
2818+
(community_id, id, pubkey, created_at, kind, tags, content, sig, channel_id) \
2819+
VALUES ($1, $2, $3, NOW() + make_interval(secs => $4), $5, '[]', $6, $7, $8)",
2820+
)
2821+
.bind(community_uuid)
2822+
.bind(vec![(index + 1) as u8; 32])
2823+
.bind(&creator)
2824+
.bind(index as f64)
2825+
.bind(KIND_HUDDLE_STARTED as i32)
2826+
.bind(content)
2827+
.bind(vec![0_u8; 64])
2828+
.bind(parent)
2829+
.execute(&pool)
2830+
.await
2831+
.expect("insert huddle-start candidate");
2832+
}
2833+
2834+
let links = huddle_started_links(&pool, community, &[parent], &[session])
2835+
.await
2836+
.expect("batch huddle links");
2837+
assert_eq!(links, vec![(session, parent, creator)]);
2838+
}
2839+
27262840
#[test]
27272841
fn huddle_started_content_requires_matching_ephemeral_field() {
27282842
let channel_id = Uuid::new_v4();

‎crates/buzz-relay/src/audio/handler.rs‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,11 @@ async fn handle_active_audio_connection(
383383
}
384384
}
385385

386+
let lifecycle_generation = pending_remote
387+
.as_ref()
388+
.map(|outcome| outcome.generation().to_string())
389+
.unwrap_or_else(|| state.huddle_liveness_generation.to_string());
390+
386391
let room = state
387392
.audio_rooms
388393
.get_or_create(tenant.community(), channel_id);
@@ -709,6 +714,7 @@ async fn handle_active_audio_connection(
709714
participant_pubkey: &pubkey_hex,
710715
roster_revision: Some(lifecycle_revision),
711716
admission_id: Some(peer_id),
717+
generation: &lifecycle_generation,
712718
},
713719
)
714720
.await;
@@ -914,6 +920,7 @@ async fn handle_active_audio_connection(
914920
participant_pubkey: &pubkey_hex,
915921
roster_revision: removal_revision,
916922
admission_id: Some(peer_id),
923+
generation: &lifecycle_generation,
917924
},
918925
)
919926
.await;
@@ -947,6 +954,7 @@ async fn handle_active_audio_connection(
947954
participant_pubkey: &pubkey_hex,
948955
roster_revision: None,
949956
admission_id: None,
957+
generation: &lifecycle_generation,
950958
},
951959
)
952960
.await;
@@ -1349,6 +1357,7 @@ struct ParticipantLifecycle<'a> {
13491357
participant_pubkey: &'a str,
13501358
roster_revision: Option<u64>,
13511359
admission_id: Option<Uuid>,
1360+
generation: &'a str,
13521361
}
13531362

13541363
async fn emit_participant_event(
@@ -1363,22 +1372,29 @@ async fn emit_participant_event(
13631372
participant_pubkey,
13641373
roster_revision,
13651374
admission_id,
1375+
generation,
13661376
} = lifecycle;
13671377
let content = match (roster_revision, admission_id) {
13681378
(Some(revision), Some(admission_id)) => serde_json::json!({
13691379
"ephemeral_channel_id": channel_id.to_string(),
13701380
"roster_revision": revision,
13711381
"admission_id": admission_id.to_string(),
1382+
"generation": generation,
13721383
}),
13731384
(Some(revision), None) => serde_json::json!({
13741385
"ephemeral_channel_id": channel_id.to_string(),
13751386
"roster_revision": revision,
1387+
"generation": generation,
13761388
}),
13771389
(None, Some(admission_id)) => serde_json::json!({
13781390
"ephemeral_channel_id": channel_id.to_string(),
13791391
"admission_id": admission_id.to_string(),
1392+
"generation": generation,
1393+
}),
1394+
(None, None) => serde_json::json!({
1395+
"ephemeral_channel_id": channel_id.to_string(),
1396+
"generation": generation,
13801397
}),
1381-
(None, None) => serde_json::json!({"ephemeral_channel_id": channel_id.to_string()}),
13821398
}
13831399
.to_string();
13841400

‎crates/buzz-relay/src/audio/join.rs‎

Lines changed: 90 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,15 @@ pub enum JoinOutcome {
265265
}
266266

267267
impl JoinOutcome {
268+
/// Fenced generation carried by both local- and remote-owner outcomes.
269+
#[must_use]
270+
pub const fn generation(&self) -> u64 {
271+
match *self {
272+
JoinOutcome::LocalOwner { generation }
273+
| JoinOutcome::RemoteOwner { generation, .. } => generation,
274+
}
275+
}
276+
268277
/// The fenced header for frames this join produces, given the huddle's
269278
/// session id (its channel id) and resolved owner. For a local-owner join
270279
/// the owner is this pod (`local_runtime_id`); for a remote-owner join it
@@ -1101,6 +1110,29 @@ impl<D: HuddleDirectory + ?Sized> HuddleControlAcceptor<D> {
11011110
.await
11021111
}
11031112

1113+
/// Remove one peer admitted by a remote control stream and perform the
1114+
/// same authoritative room-empty teardown as the local owner WebSocket
1115+
/// path. The owner-registry release is generation-fenced, so a late close
1116+
/// from an old stream cannot cancel a newly acquired lease epoch.
1117+
fn remove_remote_peer(
1118+
&self,
1119+
community: CommunityId,
1120+
session_id: Uuid,
1121+
generation: u64,
1122+
peer_id: Uuid,
1123+
) {
1124+
let Some(room) = self.rooms.get(community, session_id) else {
1125+
return;
1126+
};
1127+
let Some((delta, should_end)) = room.remove_peer_and_check_ended(peer_id) else {
1128+
return;
1129+
};
1130+
broadcast_peer_left(&room, delta, session_id);
1131+
if should_end && self.rooms.cleanup_if_empty(community, session_id) {
1132+
self.owners.release(session_id, generation);
1133+
}
1134+
}
1135+
11041136
/// Serve register/unregister frames for one non-owner pod's stream.
11051137
///
11061138
/// The community is learned from the first `RegisterPeer` frame and latched
@@ -1297,13 +1329,13 @@ impl<D: HuddleDirectory + ?Sized> HuddleControlAcceptor<D> {
12971329
}
12981330
HuddleControlMsg::UnregisterPeer { pubkey } => {
12991331
if let Some(peer_id) = registered.remove(&pubkey) {
1300-
if let Some(room) = stream_community.and_then(|community_id| {
1301-
self.rooms
1302-
.get(CommunityId::from_uuid(community_id), session_id)
1303-
}) {
1304-
if let Some(delta) = room.remove_peer(peer_id) {
1305-
broadcast_peer_left(&room, delta, session_id);
1306-
}
1332+
if let Some(community_id) = stream_community {
1333+
self.remove_remote_peer(
1334+
CommunityId::from_uuid(community_id),
1335+
session_id,
1336+
fenced.generation,
1337+
peer_id,
1338+
);
13071339
}
13081340
}
13091341
}
@@ -1347,14 +1379,10 @@ impl<D: HuddleDirectory + ?Sized> HuddleControlAcceptor<D> {
13471379
// Teardown: drop every peer this stream registered, regardless of how
13481380
// the loop ended. Dropping the peer drops its `audio_tx`, which ends the
13491381
// matching `spawn_remote_peer_sink` task.
1350-
if let Some(room) = stream_community.and_then(|community_id| {
1351-
self.rooms
1352-
.get(CommunityId::from_uuid(community_id), session_id)
1353-
}) {
1382+
if let Some(community_id) = stream_community {
1383+
let community = CommunityId::from_uuid(community_id);
13541384
for (_pubkey, peer_id) in registered {
1355-
if let Some(delta) = room.remove_peer(peer_id) {
1356-
broadcast_peer_left(&room, delta, session_id);
1357-
}
1385+
self.remove_remote_peer(community, session_id, fenced.generation, peer_id);
13581386
}
13591387
}
13601388
result
@@ -2411,6 +2439,54 @@ mod tests {
24112439
assert_eq!(room.peer_pubkeys(), vec![("owner-local".into(), 0)]);
24122440
}
24132441

2442+
#[tokio::test]
2443+
async fn remote_only_stream_close_releases_owner_room_and_lease() {
2444+
let owner_rt = rt(1);
2445+
let from = rt(2);
2446+
let session_id = Uuid::new_v4();
2447+
let fenced = fenced_owned_by(owner_rt, session_id);
2448+
let rooms = Arc::new(AudioRoomManager::new());
2449+
let dir = Arc::new(FakeDir::default());
2450+
let owners = Arc::new(HuddleOwnerRegistry::new());
2451+
owners.attach_signals(session_id, Arc::clone(&dir), lease_for(session_id, 7));
2452+
2453+
let acceptor = HuddleControlAcceptor::new(
2454+
Arc::clone(&rooms),
2455+
Arc::new(NullTransport) as Arc<dyn RelayPeerTransport>,
2456+
Arc::clone(&dir),
2457+
owner_rt,
2458+
Arc::clone(&owners),
2459+
);
2460+
let (owner_stream, mut client) = stream_pair();
2461+
let hello = huddle_hello(from, fenced);
2462+
let served =
2463+
tokio::spawn(async move { acceptor.accept_inbound(from, hello, owner_stream).await });
2464+
2465+
client
2466+
.send_frame(MeshStreamFrame::Data {
2467+
fenced,
2468+
payload: encode_control(&HuddleControlMsg::RegisterPeer {
2469+
community_id: *community().as_uuid(),
2470+
pubkey: "remote-only".into(),
2471+
protocol_version: 2,
2472+
})
2473+
.unwrap(),
2474+
})
2475+
.await
2476+
.unwrap();
2477+
let registered = client.recv_frame().await.unwrap().unwrap();
2478+
assert!(matches!(registered, MeshStreamFrame::Data { .. }));
2479+
assert!(rooms.get(community(), session_id).is_some());
2480+
assert!(owners.lost_for(session_id).is_some());
2481+
2482+
drop(client);
2483+
served.await.unwrap().unwrap();
2484+
2485+
assert!(rooms.get(community(), session_id).is_none());
2486+
assert!(owners.lost_for(session_id).is_none());
2487+
await_release_calls(&dir, 1).await;
2488+
}
2489+
24142490
/// A `RegisterPeer` whose fence is rejected (wrong community keys a lease
24152491
/// Redis never wrote) yields a `RegisterRejected(Fenced(..))` reply — no
24162492
/// peer admitted — and the stream stays alive for the client to close.

0 commit comments

Comments
 (0)