Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions crates/buzz-cli/src/commands/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,15 @@ fn format_events(normalized: &str, format: &crate::OutputFormat) -> String {
}
}

#[allow(clippy::too_many_arguments)]
pub async fn cmd_get_messages(
client: &BuzzClient,
channel_id: &str,
limit: Option<u32>,
before: Option<i64>,
since: Option<i64>,
kinds: Option<&str>,
include_aux: bool,
format: &crate::OutputFormat,
) -> Result<(), CliError> {
validate_uuid(channel_id)?;
Expand All @@ -385,6 +387,9 @@ pub async fn cmd_get_messages(
if let Some(s) = since {
filter["since"] = serde_json::json!(s);
}
if include_aux {
filter["include_aux"] = serde_json::json!(true);
}

let resp = client.query(&filter).await?;
let mut events: Vec<serde_json::Value> = serde_json::from_str(&resp).unwrap_or_default();
Expand Down Expand Up @@ -424,6 +429,7 @@ pub async fn cmd_get_thread(
expected_root_id: Option<&str>,
limit: Option<u32>,
depth_limit: Option<u32>,
include_aux: bool,
format: &crate::OutputFormat,
) -> Result<(), CliError> {
let expected_channel_id = parse_uuid(channel_id)?;
Expand All @@ -446,6 +452,9 @@ pub async fn cmd_get_thread(
if let Some(d) = depth_limit {
reply_filter["depth_limit"] = serde_json::json!(d);
}
if include_aux {
reply_filter["include_aux"] = serde_json::json!(true);
}
let root_filter = serde_json::json!({
"ids": [root_event_id.as_str()],
"#h": [channel_id],
Expand Down Expand Up @@ -1015,6 +1024,7 @@ pub async fn dispatch(
before,
since,
kinds,
include_aux,
} => {
cmd_get_messages(
client,
Expand All @@ -1023,6 +1033,7 @@ pub async fn dispatch(
before,
since,
kinds.as_deref(),
include_aux,
format,
)
.await
Expand All @@ -1033,6 +1044,7 @@ pub async fn dispatch(
link,
limit,
depth_limit,
include_aux,
} => {
let (channel, event, expected_root) =
match link {
Expand All @@ -1055,6 +1067,7 @@ pub async fn dispatch(
expected_root.as_deref(),
limit,
depth_limit,
include_aux,
format,
)
.await
Expand Down
8 changes: 7 additions & 1 deletion crates/buzz-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ pub enum MessagesCmd {
},
/// Retrieve messages from a channel
#[command(
after_help = "Examples:\n buzz messages get --channel <UUID>\n buzz messages get --channel <UUID> --limit 50 --kinds 1,1984"
after_help = "Examples:\n buzz messages get --channel <UUID>\n buzz messages get --channel <UUID> --limit 50 --kinds 1,1984\n buzz messages get --channel <UUID> --include-aux"
)]
Get {
/// Channel UUID
Expand All @@ -482,6 +482,9 @@ pub enum MessagesCmd {
/// Comma-separated event kinds to filter (e.g. 1,1984)
#[arg(long)]
kinds: Option<String>,
/// Include reactions, deletions, and edits attached to returned messages
#[arg(long)]
include_aux: bool,
},
/// Get the containing thread for a message or Buzz message link
#[command(
Expand All @@ -503,6 +506,9 @@ pub enum MessagesCmd {
/// Maximum reply nesting depth to include
#[arg(long)]
depth_limit: Option<u32>,
/// Include reactions, deletions, and edits attached to returned messages
#[arg(long)]
include_aux: bool,
},
/// Full-text search across messages
#[command(
Expand Down
50 changes: 50 additions & 0 deletions crates/buzz-relay/src/api/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,56 @@ async fn query_events_authed(
return Err(internal_error(&format!("query error: {e}")));
}
}

// Aux closure for the catch-all path: include reactions, deletions,
// and edits targeting the returned events, plus deletions targeting
// those aux events. This covers `messages get` (no top_level, no
// depth_limit) and the root-event filter in `messages thread` (an
// `ids` filter that falls through to catch-all).
if extension_flag(&raw_filters[idx], "include_aux") {
let result_ids: Vec<String> = events
.iter()
.filter_map(|e| e.get("id").and_then(|v| v.as_str()).map(String::from))
.collect();
if !result_ids.is_empty() {
let mut seen_aux = std::collections::HashSet::new();
let mut hop_ids = result_ids;
for hop_kinds in [&WINDOW_AUX_KINDS[..], &WINDOW_AUX_DELETE_KINDS[..]] {
let aux_query = build_aux_query(
tenant.community(),
std::mem::take(&mut hop_ids),
hop_kinds,
);
let aux_events = query_all_pages(
aux_query,
AUX_PAGE_LIMIT,
&mut AuxReader::Routed(&state.db, "bridge_catchall_aux"),
)
.await
.map_err(|e| {
internal_error(&format!("catch-all aux query error: {e}"))
})?;
for se in aux_events {
if !seen_aux.insert(se.event.id)
|| !event_in_accessible_channel(&se, &accessible_channels)
|| !crate::handlers::req::event_visible_to_reader(
&se.event,
&pubkey_bytes,
)
{
continue;
}
hop_ids.push(se.event.id.to_hex());
if let Ok(value) = serde_json::to_value(&se.event) {
events.push(value);
}
}
if hop_ids.is_empty() {
break;
}
}
}
}
}

Ok(Json(Value::Array(events)))
Expand Down