diff --git a/hive-matrix-mcp/src/handlers.rs b/hive-matrix-mcp/src/handlers.rs index eff7bda9..e8095458 100644 --- a/hive-matrix-mcp/src/handlers.rs +++ b/hive-matrix-mcp/src/handlers.rs @@ -134,15 +134,6 @@ fn extract_body_sync(event: &matrix_sdk::ruma::events::AnySyncTimelineEvent) -> } } -/// Human-facing label for a room: its canonical alias when set, -/// otherwise the raw room id. Used wherever a room is named in -/// agent-facing text (wake bodies, loose-ends, the unread guard). -#[must_use] -pub fn room_label(room: &matrix_sdk::Room) -> String { - room.canonical_alias() - .map_or_else(|| room.room_id().to_string(), |a| a.to_string()) -} - /// Refuse to post into a room the agent hasn't caught up on. Returns /// `Some(error)` with a helpful hint when the room still has unread /// notifications (the agent must `read_room` then `mark_read` the @@ -158,7 +149,9 @@ fn unread_guard(room: &matrix_sdk::Room) -> Option { if count == 0 { return None; } - let label = room_label(room); + let label = room + .canonical_alias() + .map_or_else(|| room.room_id().to_string(), |a| a.to_string()); Some(DaemonResponse::error(format!( "refusing to send: {count} unread message(s) in {label}. \ use read_room to view them, then mark_read the latest event before \ @@ -364,7 +357,9 @@ pub async fn refresh_invite_loose_ends(client: &Client) { let items: Vec = invites .iter() .map(|room| { - let label = room_label(room); + let label = room + .canonical_alias() + .map_or_else(|| room.room_id().to_string(), |a| a.to_string()); format!( "[matrix] pending invite: {label} — use list_invites to see, resolve_invite to accept or reject" ) @@ -552,7 +547,9 @@ pub async fn collect_unread(client: &Client) -> Vec if count == 0 { continue; } - let label = room_label(&room); + let label = room + .canonical_alias() + .map_or_else(|| room.room_id().to_string(), |a| a.to_string()); let (last_body, last_sender) = if count == 1 { fetch_last_message(client, &room).await } else { diff --git a/hive-matrix-mcp/src/timeline.rs b/hive-matrix-mcp/src/timeline.rs index 41553827..763582c0 100644 --- a/hive-matrix-mcp/src/timeline.rs +++ b/hive-matrix-mcp/src/timeline.rs @@ -77,8 +77,10 @@ pub fn install_message_handler(client: &Client, hyperhive_socket: PathBuf) { MessageType::Emote(e) => format!("* {}", e.body), _ => format!("[{}]", event.content.msgtype()), }; - let label = handlers::room_label(&room); - wake::format_wake_body(event.sender.as_str(), &label, &text) + let room_label = room + .canonical_alias() + .map_or_else(|| room.room_id().to_string(), |a| a.to_string()); + wake::format_wake_body(event.sender.as_str(), &room_label, &text) } else { wake::format_unread_summary(&unread) };