mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
fix(acp): address thread context review findings
Signed-off-by: Larry <8cf5a83f590ec0955b11647d1c88f796a98e088c30a492c58e0e46c3026ae7a4@buzz.block.builderlab.xyz>
This commit is contained in:
@@ -391,6 +391,20 @@ pub async fn cmd_get_messages(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn thread_query_filters(
|
||||
channel_id: &str,
|
||||
event_id: &str,
|
||||
limit: u32,
|
||||
depth_limit: Option<u32>,
|
||||
) -> [serde_json::Value; 2] {
|
||||
let mut replies = serde_json::json!({"kinds": [9, 40002, 40003, 40008, 45003], "#h": [channel_id], "#e": [event_id], "limit": limit});
|
||||
if let Some(depth) = depth_limit {
|
||||
replies["depth_limit"] = serde_json::json!(depth);
|
||||
}
|
||||
let root = serde_json::json!({"ids": [event_id], "#h": [channel_id], "limit": 1});
|
||||
[replies, root]
|
||||
}
|
||||
|
||||
pub async fn cmd_get_thread(
|
||||
client: &BuzzClient,
|
||||
channel_id: &str,
|
||||
@@ -403,23 +417,8 @@ pub async fn cmd_get_thread(
|
||||
validate_hex64(event_id)?;
|
||||
let limit = limit.unwrap_or(100).min(500);
|
||||
|
||||
// Two filters ORed in a single HTTP call:
|
||||
// 1. Replies referencing this event via e-tag (no kind restriction)
|
||||
// 2. The root event itself by ID
|
||||
let mut reply_filter = serde_json::json!({
|
||||
"kinds": [9, 40002, 40003, 40008, 45003],
|
||||
"#h": [channel_id],
|
||||
"#e": [event_id],
|
||||
"limit": limit
|
||||
});
|
||||
if let Some(d) = depth_limit {
|
||||
reply_filter["depth_limit"] = serde_json::json!(d);
|
||||
}
|
||||
let root_filter = serde_json::json!({
|
||||
"ids": [event_id],
|
||||
"limit": 1
|
||||
});
|
||||
let resp = client.query_multi(&[reply_filter, root_filter]).await?;
|
||||
let filters = thread_query_filters(channel_id, event_id, limit, depth_limit);
|
||||
let resp = client.query_multi(&filters).await?;
|
||||
let mut events: Vec<serde_json::Value> = serde_json::from_str(&resp).unwrap_or_default();
|
||||
events.sort_by_key(|e| e.get("created_at").and_then(|v| v.as_u64()).unwrap_or(0));
|
||||
let normalized = normalize_events(&events);
|
||||
@@ -995,13 +994,23 @@ mod tests {
|
||||
use super::{
|
||||
event_mention_pubkeys, find_root_from_tags, match_profiles_by_name, merge_message_mentions,
|
||||
missing_members, normalize_explicit_mentions, parse_member_pubkeys,
|
||||
resolve_names_to_pubkeys,
|
||||
resolve_names_to_pubkeys, thread_query_filters,
|
||||
};
|
||||
use buzz_sdk::mentions::{
|
||||
extract_at_mentions_with_known, extract_at_names, match_names_to_profiles, MentionProfile,
|
||||
};
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn thread_root_query_is_scoped_to_requested_channel() {
|
||||
let channel = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
|
||||
let event = "11".repeat(32);
|
||||
let [replies, root] = thread_query_filters(channel, &event, 50, Some(3));
|
||||
assert_eq!(replies["#h"], json!([channel]));
|
||||
assert_eq!(root["#h"], json!([channel]));
|
||||
assert_eq!(root["ids"], json!([event]));
|
||||
}
|
||||
|
||||
const ID_A: &str = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
||||
const ID_B: &str = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
|
||||
const PUBKEY: &str = "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc";
|
||||
|
||||
Reference in New Issue
Block a user