feat: sort inbox by time after added new messages
This commit is contained in:
@@ -75,7 +75,7 @@ impl ChatRegistry {
|
|||||||
|
|
||||||
fn new(_cx: &mut Context<Self>) -> Self {
|
fn new(_cx: &mut Context<Self>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
rooms: Vec::with_capacity(5),
|
rooms: vec![],
|
||||||
is_loading: true,
|
is_loading: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -186,6 +186,12 @@ impl ChatRegistry {
|
|||||||
});
|
});
|
||||||
cx.notify();
|
cx.notify();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Re sort rooms by last seen
|
||||||
|
self.rooms
|
||||||
|
.sort_by_key(|room| Reverse(room.read(cx).last_seen()));
|
||||||
|
|
||||||
|
cx.notify();
|
||||||
} else {
|
} else {
|
||||||
let room = cx.new(|cx| Room::parse(&event, cx));
|
let room = cx.new(|cx| Room::parse(&event, cx));
|
||||||
self.rooms.insert(0, room);
|
self.rooms.insert(0, room);
|
||||||
|
|||||||
@@ -124,6 +124,10 @@ impl Room {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn last_seen(&self) -> &LastSeen {
|
||||||
|
&self.last_seen
|
||||||
|
}
|
||||||
|
|
||||||
/// Get all public keys from current room
|
/// Get all public keys from current room
|
||||||
pub fn pubkeys(&self) -> Vec<PublicKey> {
|
pub fn pubkeys(&self) -> Vec<PublicKey> {
|
||||||
let mut pubkeys: Vec<_> = self.members.iter().map(|m| m.public_key()).collect();
|
let mut pubkeys: Vec<_> = self.members.iter().map(|m| m.public_key()).collect();
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use chrono::{Datelike, Local, TimeZone};
|
|||||||
use gpui::SharedString;
|
use gpui::SharedString;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct LastSeen(pub Timestamp);
|
pub struct LastSeen(pub Timestamp);
|
||||||
|
|
||||||
impl LastSeen {
|
impl LastSeen {
|
||||||
|
|||||||
Reference in New Issue
Block a user