From 6bb316d8f565cd582009cd759d33aad045d97a71 Mon Sep 17 00:00:00 2001 From: Orual Date: Sun, 12 Apr 2026 15:55:34 -0400 Subject: [PATCH] fix: remove dead import, fix facets serialization semantics, HashMap, fix stray use keyword --- src/catalog.rs | 57 ++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/src/catalog.rs b/src/catalog.rs index 5f6da06..cd594b6 100644 --- a/src/catalog.rs +++ b/src/catalog.rs @@ -160,9 +160,9 @@ pub enum Shape { pub struct HydrateQueryResponse { pub output: Data, #[serde(default)] - pub records: std::collections::BTreeMap>, + pub records: BTreeMap>, #[serde(default)] - pub identifiers: std::collections::BTreeMap>, + pub identifiers: BTreeMap>, } #[derive(Serialize, Deserialize, Debug, Clone)] @@ -245,17 +245,15 @@ use { jacquard_common::types::ident::AtIdentifier, mini_moka_wasm::sync::Cache as MokaCache, std::collections::HashMap, + std::sync::Arc, std::sync::OnceLock, + std::time::Duration, tracing::warn, vodplace_api::app_bsky::actor::get_profile::GetProfile, vodplace_api::place_stream::livestream::Livestream, }; -#[cfg(feature = "server")] -use std::sync::Arc; -#[cfg(feature = "server")] -use std::time::Duration; - +use std::collections::BTreeMap; #[cfg(feature = "server")] #[derive(Debug, thiserror::Error)] enum ThumbnailError { @@ -1201,14 +1199,14 @@ pub async fn get_chat_messages( .collect() }; - let mut handle_map: HashMap = HashMap::new(); + let mut handle_map: HashMap = HashMap::new(); { let handle_futures = unique_dids.iter().map(|did| { let client = client.clone(); let did = did.clone(); async move { match crate::identity::resolve_handle_for_did(&*client, &did).await { - Ok(handle) => Some((did.as_str().to_string(), handle)), + Ok(handle) => Some((did, handle)), Err(e) => { warn!(did = %did.as_str(), "handle resolution failed: {e}"); None @@ -1216,8 +1214,8 @@ pub async fn get_chat_messages( } } }); - for result in join_all(handle_futures).await.into_iter().flatten() { - handle_map.insert(result.0, result.1); + for (did, handle) in join_all(handle_futures).await.into_iter().flatten() { + handle_map.insert(did, handle); } } @@ -1231,8 +1229,12 @@ pub async fn get_chat_messages( let messages: Vec = cached .iter() .map(|msg| { + let author_did: Did = msg + .author_did + .parse() + .unwrap_or_else(|_| "did:plc:invalid".parse().unwrap()); let author_handle = handle_map - .get(&msg.author_did) + .get(&author_did) .cloned() .unwrap_or_else(|| fallback_handle.clone()); @@ -1252,15 +1254,13 @@ pub async fn get_chat_messages( // Build reply snippet if this message is a reply let reply_snippet = msg.reply_parent_uri.as_deref().and_then(|parent_uri_str| { - // Extract rkey from the parent AT URI let parent_rkey = parent_uri_str.rsplit('/').next()?; - // Look up parent in current batch let parent_msg = msg_by_rkey.get(parent_rkey)?; + let parent_did: Did = parent_msg.author_did.parse().ok()?; let parent_handle = handle_map - .get(&parent_msg.author_did) + .get(&parent_did) .cloned() .unwrap_or_else(|| fallback_handle.clone()); - let parent_did: Did = parent_msg.author_did.parse().ok()?; Some(ReplySnippet { author_did: parent_did, author_handle: parent_handle, @@ -1272,10 +1272,7 @@ pub async fn get_chat_messages( ChatMessageView { tid: SmolStr::new(&msg.rkey), text: SmolStr::new(&msg.text), - author_did: msg - .author_did - .parse() - .unwrap_or_else(|_| "did:plc:unknown".parse().expect("valid fallback DID")), + author_did: author_did.clone(), author_handle, vod_relative_ms: vod_relative, reply_snippet, @@ -1386,7 +1383,6 @@ async fn fetch_via_slingshot( reverse: bool, cursor: Option<&str>, ) -> Result<(Vec, Option), String> { - use crate::chat::datetime_to_ms; use crate::chat_cache::CachedChatMessage; use jacquard::types::value::{from_data, to_data}; use vodplace_api::place_stream::chat::message::Message as ChatMessage; @@ -1510,11 +1506,19 @@ async fn fetch_via_slingshot( let (author_did, rkey) = match parse_at_uri_parts(at_uri.as_str()) { Some(parts) => parts, None => { - warn!("failed to parse AT URI parts from pending record: {}", at_uri.as_str()); + warn!( + "failed to parse AT URI parts from pending record: {}", + at_uri.as_str() + ); return None; } }; - Some(message_to_cached(&chat_msg, &streamer_did, &author_did, &rkey)) + Some(message_to_cached( + &chat_msg, + &streamer_did, + &author_did, + &rkey, + )) }) }); @@ -1557,12 +1561,15 @@ fn message_to_cached( rkey: rkey.to_string(), created_at_ms: datetime_to_ms(&msg.created_at), text: msg.text.to_string(), - reply_parent_uri: msg.reply.as_ref().map(|r| r.parent.uri.as_ref().to_string()), + reply_parent_uri: msg + .reply + .as_ref() + .map(|r| r.parent.uri.as_ref().to_string()), reply_root_uri: msg.reply.as_ref().map(|r| r.root.uri.as_ref().to_string()), facets_json: msg .facets .as_ref() - .map(|f| serde_json::to_string(f).unwrap_or_default()), + .and_then(|f| serde_json::to_string(f).ok()), } } -- knotmirror 0.0.1