diff --git a/src/main.rs b/src/main.rs index 38104d7..74cd1fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -824,6 +824,8 @@ struct GetAuthorFeedParams { limit: Option, #[serde(default)] cursor: Option, + #[serde(default)] + filter: Option, } async fn get_author_feed( @@ -894,20 +896,43 @@ async fn get_author_feed( let mut all_items = Vec::new(); for rec in posts_list.records { - all_items.push((rec.rkey.as_str().to_string(), "post", rec)); + let val_json = serde_json::to_value(&rec.value).unwrap_or(serde_json::json!({})); + let created_at = val_json + .get("createdAt") + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_string(); + + // Filter logic + let filter = params.filter.as_deref().unwrap_or("posts_with_replies"); + if filter == "posts_no_replies" && val_json.get("reply").is_some() { + continue; + } + + all_items.push((created_at, "post", rec)); } for rec in reposts_list.records { - all_items.push((rec.rkey.as_str().to_string(), "repost", rec)); + let val_json = serde_json::to_value(&rec.value).unwrap_or(serde_json::json!({})); + let created_at = val_json + .get("createdAt") + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_string(); + all_items.push((created_at, "repost", rec)); } - // Sort by rkey (roughly chronological) descending + // Sort by createdAt descending all_items.sort_by(|a, b| b.0.cmp(&a.0)); all_items.truncate(limit); let mut feed = Vec::new(); - for (rkey, kind, rec) in &all_items { + for (created_at, kind, rec) in &all_items { if *kind == "post" { - let uri = format!("at://{}/app.bsky.feed.post/{}", did.as_str(), rkey); + let uri = format!( + "at://{}/app.bsky.feed.post/{}", + did.as_str(), + rec.rkey.as_str() + ); let post = match get_post_view(&app_state, &uri, viewer_did.as_deref()).await { Ok(mut p) => { p["author"] = author_profile.clone(); @@ -974,7 +999,7 @@ async fn get_author_feed( "reason": { "$type": "app.bsky.feed.defs#reasonRepost", "by": author_profile.clone(), - "indexedAt": val_json.get("createdAt").and_then(|c| c.as_str()).map(|s| s.to_string()).unwrap_or_else(|| chrono::Utc::now().to_rfc3339()), + "indexedAt": created_at, } })); } @@ -982,12 +1007,7 @@ async fn get_author_feed( } } - let next_cursor = if posts_list.cursor.is_some() || reposts_list.cursor.is_some() { - // This is a naive cursor but works for now as long as we sort by rkey - all_items.last().map(|i| i.0.clone()) - } else { - None - }; + let next_cursor = all_items.last().map(|i| i.0.clone()); Ok(Json(serde_json::json!({ "feed": feed,