mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 21:06:31 +03:00
add thumbnail for image in chatlist item (#4311)
* add thumbnail for image in chatlist item * added preview for stickers and gifs also * added last_message_type and last_message_id to ChatListItemFetchResult addresses link2ext comment * code optimization fixes: https://github.com/deltachat/deltachat-core-rust/pull/4311#discussion_r1162791672 * code formatting * fix clippy * add changelog entry --------- Co-authored-by: meganoahj <s3ccg@testrun.org> Co-authored-by: Simon Laux <mobile.info@simonlaux.de>
This commit is contained in:
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- jsonrpc: `ChatListItemFetchResult` gets new properties: `summary_preview_image`, `last_message_type` and `last_message_id`
|
||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
- BREAKING: jsonrpc:
|
- BREAKING: jsonrpc:
|
||||||
- `get_chatlist_items_by_entries` now takes only chatids instead of `ChatListEntries`
|
- `get_chatlist_items_by_entries` now takes only chatids instead of `ChatListEntries`
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ use serde::Serialize;
|
|||||||
use typescript_type_def::TypeDef;
|
use typescript_type_def::TypeDef;
|
||||||
|
|
||||||
use super::color_int_to_hex_string;
|
use super::color_int_to_hex_string;
|
||||||
|
use super::message::MessageViewtype;
|
||||||
|
|
||||||
#[derive(Serialize, TypeDef)]
|
#[derive(Serialize, TypeDef)]
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
@@ -26,6 +27,8 @@ pub enum ChatListItemFetchResult {
|
|||||||
summary_text1: String,
|
summary_text1: String,
|
||||||
summary_text2: String,
|
summary_text2: String,
|
||||||
summary_status: u32,
|
summary_status: u32,
|
||||||
|
/// showing preview if last chat message is image
|
||||||
|
summary_preview_image: Option<String>,
|
||||||
is_protected: bool,
|
is_protected: bool,
|
||||||
is_group: bool,
|
is_group: bool,
|
||||||
fresh_message_counter: usize,
|
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)
|
/// contact id if this is a dm chat (for view profile entry in context menu)
|
||||||
dm_chat_contact: Option<u32>,
|
dm_chat_contact: Option<u32>,
|
||||||
was_seen_recently: bool,
|
was_seen_recently: bool,
|
||||||
|
last_message_type: Option<MessageViewtype>,
|
||||||
|
last_message_id: Option<u32>,
|
||||||
},
|
},
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
ArchiveLink { fresh_message_counter: usize },
|
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_text1 = summary.prefix.map_or_else(String::new, |s| s.to_string());
|
||||||
let summary_text2 = summary.text.to_owned();
|
let summary_text2 = summary.text.to_owned();
|
||||||
|
|
||||||
|
let summary_preview_image = summary.thumbnail_path;
|
||||||
|
|
||||||
let visibility = chat.get_visibility();
|
let visibility = chat.get_visibility();
|
||||||
|
|
||||||
let avatar_path = chat
|
let avatar_path = chat
|
||||||
@@ -79,12 +86,15 @@ pub(crate) async fn get_chat_list_item_by_id(
|
|||||||
.await?
|
.await?
|
||||||
.map(|path| path.to_str().unwrap_or("invalid/path").to_owned());
|
.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) => {
|
Some(id) => {
|
||||||
let last_message = deltachat::message::Message::load_from_db(ctx, id).await?;
|
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?;
|
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_text1,
|
||||||
summary_text2,
|
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_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_protected: chat.is_protected(),
|
||||||
is_group: chat.get_type() == Chattype::Group,
|
is_group: chat.get_type() == Chattype::Group,
|
||||||
fresh_message_counter,
|
fresh_message_counter,
|
||||||
@@ -133,5 +144,7 @@ pub(crate) async fn get_chat_list_item_by_id(
|
|||||||
is_broadcast: chat.get_type() == Chattype::Broadcast,
|
is_broadcast: chat.get_type() == Chattype::Broadcast,
|
||||||
dm_chat_contact,
|
dm_chat_contact,
|
||||||
was_seen_recently,
|
was_seen_recently,
|
||||||
|
last_message_type: message_type,
|
||||||
|
last_message_id: last_msgid.map(|id| id.to_u32()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,9 @@ pub struct Summary {
|
|||||||
|
|
||||||
/// Message state.
|
/// Message state.
|
||||||
pub state: MessageState,
|
pub state: MessageState,
|
||||||
|
|
||||||
|
/// Message preview image path
|
||||||
|
pub thumbnail_path: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Summary {
|
impl Summary {
|
||||||
@@ -90,11 +93,22 @@ impl Summary {
|
|||||||
text = stock_str::reply_noun(context).await
|
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 {
|
Self {
|
||||||
prefix,
|
prefix,
|
||||||
text,
|
text,
|
||||||
timestamp: msg.get_timestamp(),
|
timestamp: msg.get_timestamp(),
|
||||||
state: msg.state,
|
state: msg.state,
|
||||||
|
thumbnail_path,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user