Change back to linear feed for now

This commit is contained in:
Mike Dilger 2022-12-22 06:22:54 +13:00
parent 8a46e2d5fe
commit bd592aacc7
2 changed files with 27 additions and 6 deletions

View File

@ -61,7 +61,7 @@ lazy_static! {
#[allow(dead_code)] #[allow(dead_code)]
pub async fn get_feed() -> Vec<Id> { pub async fn get_feed() -> Vec<Id> {
let mut feed: Vec<FeedEvent> = GLOBALS let feed: Vec<FeedEvent> = GLOBALS
.feed_events .feed_events
.lock() .lock()
.await .await
@ -71,13 +71,13 @@ pub async fn get_feed() -> Vec<Id> {
.filter(|e| e.in_reply_to.is_none()) // only root events .filter(|e| e.in_reply_to.is_none()) // only root events
.cloned() .cloned()
.collect(); .collect();
feed.sort_unstable_by(|a, b| a.last_reply_at.cmp(&b.last_reply_at));
feed.iter().map(|e| e.id).collect() sort_feed(feed)
} }
#[allow(dead_code)] #[allow(dead_code)]
pub fn blocking_get_feed() -> Vec<Id> { pub fn blocking_get_feed() -> Vec<Id> {
let mut feed: Vec<FeedEvent> = GLOBALS let feed: Vec<FeedEvent> = GLOBALS
.feed_events .feed_events
.blocking_lock() .blocking_lock()
.iter() .iter()
@ -86,7 +86,28 @@ pub fn blocking_get_feed() -> Vec<Id> {
//.filter(|e| e.in_reply_to.is_none()) // only root events //.filter(|e| e.in_reply_to.is_none()) // only root events
.cloned() .cloned()
.collect(); .collect();
feed.sort_unstable_by(|a, b| a.last_reply_at.cmp(&b.last_reply_at));
sort_feed(feed)
}
fn sort_feed(mut feed: Vec<FeedEvent>) -> Vec<Id> {
// Threaded, TBD:
// feed.sort_unstable_by(|a, b| a.last_reply_at.cmp(&b.last_reply_at));
// Linear sort neweset first:
feed.sort_unstable_by(|a, b| {
if a.event.is_some() && b.event.is_some() {
b.event.as_ref().unwrap().created_at.cmp(
&a.event.as_ref().unwrap().created_at)
} else if a.event.is_some() {
std::cmp::Ordering::Greater
} else if b.event.is_some() {
std::cmp::Ordering::Less
} else {
std::cmp::Ordering::Equal
}
});
feed.iter().map(|e| e.id).collect() feed.iter().map(|e| e.id).collect()
} }

View File

@ -8,7 +8,7 @@ pub(super) fn update(_app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fr
let screen_rect = ctx.input().screen_rect; // Rect let screen_rect = ctx.input().screen_rect; // Rect
ScrollArea::vertical().show(ui, |ui| { ScrollArea::vertical().show(ui, |ui| {
for id in feed.iter().rev() { for id in feed.iter() {
// Stop rendering at the bottom of the window: // Stop rendering at the bottom of the window:
let pos2 = ui.next_widget_position(); let pos2 = ui.next_widget_position();
if pos2.y > screen_rect.max.y { if pos2.y > screen_rect.max.y {