mirror of
https://github.com/chatmail/core.git
synced 2026-05-06 16:36:59 +03:00
api!: Remove msg_id (last message ID) from Chatlist::get_summary2() (#3071)
`Chatlist::get_summary2()` is used in the jsonrpc API. CFFI uses `Chatlist::get_summary()` which logic is preserved (it uses message ids cached in the `Chatlist`). The motivation for this change is that jsonrpc API uses `get_last_message_for_chat()` returning the message id + `Chatlist::get_summary2()` taking the message id when building a chatlist, but if the message is ephemeral, the id can expire and building the chatlist would fail. The solution is to return a summary for the last message (if any) in the chat from `Chatlist::get_summary2()` so the call to `get_last_message_for_chat()` goes away (and two SQL queries are just merged into one) and overall the API is easier to use. Also this change extends `struct Summary` with the message viewtype (so an extra call to `Message::load_from_db()` goes away) and the message id in case if it's needed for any purposes beyond building the chatlist.
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
use anyhow::{Context, Result};
|
||||
use deltachat::chat::{get_chat_contacts, ChatVisibility};
|
||||
use deltachat::chat::{Chat, ChatId};
|
||||
use deltachat::chatlist::get_last_message_for_chat;
|
||||
use deltachat::chatlist::Chatlist;
|
||||
use deltachat::constants::*;
|
||||
use deltachat::contact::{Contact, ContactId};
|
||||
use deltachat::{
|
||||
chat::{get_chat_contacts, ChatVisibility},
|
||||
chatlist::Chatlist,
|
||||
};
|
||||
use num_traits::cast::ToPrimitive;
|
||||
use serde::Serialize;
|
||||
use typescript_type_def::TypeDef;
|
||||
@@ -67,10 +64,8 @@ pub(crate) async fn get_chat_list_item_by_id(
|
||||
});
|
||||
}
|
||||
|
||||
let last_msgid = get_last_message_for_chat(ctx, chat_id).await?;
|
||||
|
||||
let chat = Chat::load_from_db(ctx, chat_id).await.context("chat")?;
|
||||
let summary = Chatlist::get_summary2(ctx, chat_id, last_msgid, Some(&chat))
|
||||
let summary = Chatlist::get_summary2(ctx, chat_id, Some(&chat))
|
||||
.await
|
||||
.context("summary")?;
|
||||
|
||||
@@ -86,15 +81,12 @@ pub(crate) async fn get_chat_list_item_by_id(
|
||||
.await?
|
||||
.map(|path| path.to_str().unwrap_or("invalid/path").to_owned());
|
||||
|
||||
let (last_updated, message_type) = match last_msgid {
|
||||
Some(id) => {
|
||||
let last_message = deltachat::message::Message::load_from_db(ctx, id).await?;
|
||||
(
|
||||
Some(last_message.get_timestamp() * 1000),
|
||||
Some(last_message.get_viewtype().into()),
|
||||
)
|
||||
}
|
||||
let (last_updated, message_type) = match summary.id {
|
||||
None => (None, None),
|
||||
Some(_) => (
|
||||
Some(summary.timestamp * 1000),
|
||||
Some(summary.viewtype.into()),
|
||||
),
|
||||
};
|
||||
|
||||
let chat_contacts = get_chat_contacts(ctx, chat_id).await?;
|
||||
@@ -145,6 +137,6 @@ pub(crate) async fn get_chat_list_item_by_id(
|
||||
dm_chat_contact,
|
||||
was_seen_recently,
|
||||
last_message_type: message_type,
|
||||
last_message_id: last_msgid.map(|id| id.to_u32()),
|
||||
last_message_id: summary.id.map(|id| id.to_u32()),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user