diff --git a/CHANGELOG.md b/CHANGELOG.md index 957ff1f93..66f8ef02c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +### Added +- jsonrpc: `ChatListItemFetchResult` gets new properties: `summary_preview_image`, `last_message_type` and `last_message_id` + ### Changes - BREAKING: jsonrpc: - `get_chatlist_items_by_entries` now takes only chatids instead of `ChatListEntries` diff --git a/deltachat-jsonrpc/src/api/types/chat_list.rs b/deltachat-jsonrpc/src/api/types/chat_list.rs index f9fb5ae8d..5c63b5def 100644 --- a/deltachat-jsonrpc/src/api/types/chat_list.rs +++ b/deltachat-jsonrpc/src/api/types/chat_list.rs @@ -12,6 +12,7 @@ use serde::Serialize; use typescript_type_def::TypeDef; use super::color_int_to_hex_string; +use super::message::MessageViewtype; #[derive(Serialize, TypeDef)] #[serde(tag = "type")] @@ -26,6 +27,8 @@ pub enum ChatListItemFetchResult { summary_text1: String, summary_text2: String, summary_status: u32, + /// showing preview if last chat message is image + summary_preview_image: Option, is_protected: bool, is_group: bool, fresh_message_counter: usize, @@ -42,6 +45,8 @@ pub enum ChatListItemFetchResult { /// contact id if this is a dm chat (for view profile entry in context menu) dm_chat_contact: Option, was_seen_recently: bool, + last_message_type: Option, + last_message_id: Option, }, #[serde(rename_all = "camelCase")] ArchiveLink { fresh_message_counter: usize }, @@ -72,6 +77,8 @@ pub(crate) async fn get_chat_list_item_by_id( let summary_text1 = summary.prefix.map_or_else(String::new, |s| s.to_string()); let summary_text2 = summary.text.to_owned(); + let summary_preview_image = summary.thumbnail_path; + let visibility = chat.get_visibility(); let avatar_path = chat @@ -79,12 +86,15 @@ 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 = match last_msgid { + 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_timestamp() * 1000), + Some(last_message.get_viewtype().into()), + ) } - None => None, + None => (None, None), }; let chat_contacts = get_chat_contacts(ctx, chat_id).await?; @@ -119,6 +129,7 @@ pub(crate) async fn get_chat_list_item_by_id( summary_text1, summary_text2, summary_status: summary.state.to_u32().expect("impossible"), // idea and a function to transform the constant to strings? or return string enum + summary_preview_image, is_protected: chat.is_protected(), is_group: chat.get_type() == Chattype::Group, fresh_message_counter, @@ -133,5 +144,7 @@ pub(crate) async fn get_chat_list_item_by_id( is_broadcast: chat.get_type() == Chattype::Broadcast, dm_chat_contact, was_seen_recently, + last_message_type: message_type, + last_message_id: last_msgid.map(|id| id.to_u32()), }) } diff --git a/src/summary.rs b/src/summary.rs index 8a22b4b54..d27bf9aa0 100644 --- a/src/summary.rs +++ b/src/summary.rs @@ -50,6 +50,9 @@ pub struct Summary { /// Message state. pub state: MessageState, + + /// Message preview image path + pub thumbnail_path: Option, } impl Summary { @@ -90,11 +93,22 @@ impl Summary { text = stock_str::reply_noun(context).await } + let thumbnail_path = if msg.viewtype == Viewtype::Image + || msg.viewtype == Viewtype::Gif + || msg.viewtype == Viewtype::Sticker + { + msg.get_file(context) + .and_then(|path| path.to_str().map(|p| p.to_owned())) + } else { + None + }; + Self { prefix, text, timestamp: msg.get_timestamp(), state: msg.state, + thumbnail_path, } }