slop slop slop sahuuuurrr
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix getAuthorFeed

dawn 034a37ce 0966b6b0

+32 -12
+32 -12
src/main.rs
··· 824 824 limit: Option<usize>, 825 825 #[serde(default)] 826 826 cursor: Option<String>, 827 + #[serde(default)] 828 + filter: Option<String>, 827 829 } 828 830 829 831 async fn get_author_feed( ··· 894 896 895 897 let mut all_items = Vec::new(); 896 898 for rec in posts_list.records { 897 - all_items.push((rec.rkey.as_str().to_string(), "post", rec)); 899 + let val_json = serde_json::to_value(&rec.value).unwrap_or(serde_json::json!({})); 900 + let created_at = val_json 901 + .get("createdAt") 902 + .and_then(|v| v.as_str()) 903 + .unwrap_or("") 904 + .to_string(); 905 + 906 + // Filter logic 907 + let filter = params.filter.as_deref().unwrap_or("posts_with_replies"); 908 + if filter == "posts_no_replies" && val_json.get("reply").is_some() { 909 + continue; 910 + } 911 + 912 + all_items.push((created_at, "post", rec)); 898 913 } 899 914 for rec in reposts_list.records { 900 - all_items.push((rec.rkey.as_str().to_string(), "repost", rec)); 915 + let val_json = serde_json::to_value(&rec.value).unwrap_or(serde_json::json!({})); 916 + let created_at = val_json 917 + .get("createdAt") 918 + .and_then(|v| v.as_str()) 919 + .unwrap_or("") 920 + .to_string(); 921 + all_items.push((created_at, "repost", rec)); 901 922 } 902 923 903 - // Sort by rkey (roughly chronological) descending 924 + // Sort by createdAt descending 904 925 all_items.sort_by(|a, b| b.0.cmp(&a.0)); 905 926 all_items.truncate(limit); 906 927 907 928 let mut feed = Vec::new(); 908 - for (rkey, kind, rec) in &all_items { 929 + for (created_at, kind, rec) in &all_items { 909 930 if *kind == "post" { 910 - let uri = format!("at://{}/app.bsky.feed.post/{}", did.as_str(), rkey); 931 + let uri = format!( 932 + "at://{}/app.bsky.feed.post/{}", 933 + did.as_str(), 934 + rec.rkey.as_str() 935 + ); 911 936 let post = match get_post_view(&app_state, &uri, viewer_did.as_deref()).await { 912 937 Ok(mut p) => { 913 938 p["author"] = author_profile.clone(); ··· 974 999 "reason": { 975 1000 "$type": "app.bsky.feed.defs#reasonRepost", 976 1001 "by": author_profile.clone(), 977 - "indexedAt": val_json.get("createdAt").and_then(|c| c.as_str()).map(|s| s.to_string()).unwrap_or_else(|| chrono::Utc::now().to_rfc3339()), 1002 + "indexedAt": created_at, 978 1003 } 979 1004 })); 980 1005 } ··· 982 1007 } 983 1008 } 984 1009 985 - let next_cursor = if posts_list.cursor.is_some() || reposts_list.cursor.is_some() { 986 - // This is a naive cursor but works for now as long as we sort by rkey 987 - all_items.last().map(|i| i.0.clone()) 988 - } else { 989 - None 990 - }; 1010 + let next_cursor = all_items.last().map(|i| i.0.clone()); 991 1011 992 1012 Ok(Json(serde_json::json!({ 993 1013 "feed": feed,