feat: order chats by most recent message
This commit is contained in:
parent
9baf682466
commit
b81f7f5bb4
|
@ -4,9 +4,9 @@
|
|||
|
||||
## TODO:
|
||||
|
||||
- [ ] how to know if stanza has been sent
|
||||
- [x] how to know if stanza has been sent
|
||||
- [ ] error states for all negotiation parts
|
||||
- [ ] better errors
|
||||
- [x] better errors
|
||||
- [x] rename structs
|
||||
- [x] remove commented code
|
||||
- [ ] asynchronous connect (with take_mut?)
|
||||
|
@ -16,7 +16,7 @@
|
|||
### specs:
|
||||
|
||||
- [x] rfc 6120: core
|
||||
- [ ] rfc 6121: im
|
||||
- [x] rfc 6121: im
|
||||
- [x] rfc 7590: tls
|
||||
- [x] xep-0368: srv records for xmpp over tls
|
||||
- [ ] server side downgrade protection for sasl
|
||||
|
|
22
TODO.md
22
TODO.md
|
@ -3,18 +3,7 @@
|
|||
## next
|
||||
|
||||
feat(luz): everything in rfc6120 and rfc6121
|
||||
feat(luz): handle_online
|
||||
feat(luz): handle_offline
|
||||
feat(luz): handle_stanza
|
||||
feat(luz): database
|
||||
feat(luz): error handling on stream according to rfc6120
|
||||
feat(luz): send message
|
||||
feat(luz): receive message
|
||||
feat(luz): retreive messages stored in database
|
||||
feat(luz): get roster (online and offline)
|
||||
feat(luz): set roster
|
||||
feat(luz): reconnect supervisorcommand
|
||||
feat: thiserror everywhere
|
||||
feat(luz): proper stanza ids
|
||||
test: proper tests
|
||||
ci: doc generation
|
||||
|
@ -35,3 +24,14 @@ feature: sasl
|
|||
feature: resource binding
|
||||
feature: jabber client connection
|
||||
feature: jid
|
||||
feat: thiserror everywhere
|
||||
feat(luz): handle_online
|
||||
feat(luz): handle_offline
|
||||
feat(luz): handle_stanza
|
||||
feat(luz): database
|
||||
feat(luz): send message
|
||||
feat(luz): receive message
|
||||
feat(luz): retreive messages stored in database
|
||||
feat(luz): get roster (online and offline)
|
||||
feat(luz): set roster
|
||||
feat(luz): reconnect supervisorcommand
|
||||
|
|
|
@ -11,7 +11,7 @@ async-recursion = "1.0.4"
|
|||
async-trait = "0.1.68"
|
||||
lazy_static = "1.4.0"
|
||||
nanoid = "0.4.0"
|
||||
# TODO: remove unneeded features
|
||||
# TODO: remove unneeded features and dependencies
|
||||
rsasl = { version = "2.0.1", default_features = false, features = [
|
||||
"provider_base64",
|
||||
"plain",
|
||||
|
|
|
@ -31,10 +31,15 @@ pub struct Body {
|
|||
#[derive(sqlx::FromRow, Debug, Clone)]
|
||||
pub struct Chat {
|
||||
pub correspondent: JID,
|
||||
// pub unread_messages: i32,
|
||||
// pub latest_message: Message,
|
||||
// when a new message is received, the chat should be updated, and the new message should be delivered too.
|
||||
// message history is not stored in chat, retreived separately.
|
||||
// pub message_history: Vec<Message>,
|
||||
}
|
||||
|
||||
pub enum ChatUpdate {}
|
||||
|
||||
impl Chat {
|
||||
pub fn new(correspondent: JID) -> Self {
|
||||
Self { correspondent }
|
||||
|
|
|
@ -129,12 +129,11 @@ impl Db {
|
|||
}
|
||||
|
||||
pub(crate) async fn read_contact_opt(&self, contact: &JID) -> Result<Option<Contact>, Error> {
|
||||
let contact: Option<Contact> = sqlx::query_as(
|
||||
"select * from roster full outer join users on jid = user_jid where jid = ?",
|
||||
)
|
||||
.bind(contact)
|
||||
.fetch_optional(&self.db)
|
||||
.await?;
|
||||
let contact: Option<Contact> =
|
||||
sqlx::query_as("select * from roster join users on jid = user_jid where jid = ?")
|
||||
.bind(contact)
|
||||
.fetch_optional(&self.db)
|
||||
.await?;
|
||||
if let Some(mut contact) = contact {
|
||||
#[derive(sqlx::FromRow)]
|
||||
struct Row {
|
||||
|
@ -325,6 +324,15 @@ impl Db {
|
|||
Ok(chats)
|
||||
}
|
||||
|
||||
/// chats ordered by date of last message
|
||||
// greatest-n-per-group
|
||||
pub(crate) async fn read_chats_ordered(&self) -> Result<Vec<Chat>, Error> {
|
||||
let chats = sqlx::query_as("select c.*, m.* from chats c join (select chat_id, max(timestamp) max_timestamp from messages group by chat_id) max_timestamps on c.id = max_timestamps.chat_id join messages m on max_timestamps.chat_id = m.chat_id and max_timestamps.max_timestamp = m.timestamp order by m.timestamp desc")
|
||||
.fetch_all(&self.db)
|
||||
.await?;
|
||||
Ok(chats)
|
||||
}
|
||||
|
||||
async fn read_chat_id(&self, chat: JID) -> Result<Uuid, Error> {
|
||||
#[derive(sqlx::FromRow)]
|
||||
struct Row {
|
||||
|
|
|
@ -323,7 +323,7 @@ impl CommandMessage {
|
|||
}
|
||||
}
|
||||
CommandMessage::GetChats(sender) => {
|
||||
let chats = db.read_chats().await.map_err(|e| e.into());
|
||||
let chats = db.read_chats_ordered().await.map_err(|e| e.into());
|
||||
sender.send(chats);
|
||||
}
|
||||
CommandMessage::GetChat(jid, sender) => {
|
||||
|
@ -509,7 +509,7 @@ impl CommandMessage {
|
|||
}
|
||||
}
|
||||
CommandMessage::GetChats(sender) => {
|
||||
let chats = db.read_chats().await.map_err(|e| e.into());
|
||||
let chats = db.read_chats_ordered().await.map_err(|e| e.into());
|
||||
sender.send(chats);
|
||||
}
|
||||
CommandMessage::GetChat(jid, sender) => {
|
||||
|
|
Loading…
Reference in New Issue