From aa212b2b7ecb7279dbccc847176e3eec80fa93a8 Mon Sep 17 00:00:00 2001 From: Simon Laux Date: Tue, 9 May 2023 12:22:32 +0200 Subject: [PATCH] jsonrpc: `MessageSearchResult`, always include `chat_name`(not an option anymore), also add `author_id` and `chat_type` (#4374) * jsonrpc: `MessageSearchResult`, always include `chat_name`(not an option anymore), also add `author_id` and `chat_type` * replace .ok_or_else with anyhow context --- CHANGELOG.md | 6 ++++ deltachat-jsonrpc/src/api/types/chat.rs | 12 ++----- deltachat-jsonrpc/src/api/types/message.rs | 40 +++++++++++++++++----- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4980a1f1..0d834be66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,13 +10,19 @@ - `get_chatlist_items_by_entries` now takes only chatids instead of `ChatListEntries` - `get_chatlist_entries` now returns `Vec` of chatids instead of `ChatListEntries` - `Event`: `context_id` property is now called `contextId` +- jsonrpc: expand `MessageSearchResult`: + - always include `chat_name`(not an option anymore) + - add `author_id`, `chat_type`, `chat_color`, `is_chat_protected`, `is_chat_contact_request`, `is_chat_archived` + - `author_name` now contains the overridden sender name. - JSON-RPC: add API to get reactions outside the message snapshot + ### Fixes - Make the bots automatically accept group chat contact requests. #4377 ### Fixes - jsonrpc: typescript client: fix types of events in event emitter + ## [1.114.0] - 2023-04-24 ### Changes diff --git a/deltachat-jsonrpc/src/api/types/chat.rs b/deltachat-jsonrpc/src/api/types/chat.rs index 277817b8f..a658e26f3 100644 --- a/deltachat-jsonrpc/src/api/types/chat.rs +++ b/deltachat-jsonrpc/src/api/types/chat.rs @@ -1,6 +1,6 @@ use std::time::{Duration, SystemTime}; -use anyhow::{anyhow, bail, Context as _, Result}; +use anyhow::{bail, Context as _, Result}; use deltachat::chat::{self, get_chat_contacts, ChatVisibility}; use deltachat::chat::{Chat, ChatId}; use deltachat::constants::Chattype; @@ -92,10 +92,7 @@ impl FullChat { is_protected: chat.is_protected(), profile_image, //BLOBS ? archived: chat.get_visibility() == chat::ChatVisibility::Archived, - chat_type: chat - .get_type() - .to_u32() - .ok_or_else(|| anyhow!("unknown chat type id"))?, // TODO get rid of this unwrap? + chat_type: chat.get_type().to_u32().context("unknown chat type id")?, is_unpromoted: chat.is_unpromoted(), is_self_talk: chat.is_self_talk(), contacts, @@ -158,10 +155,7 @@ impl BasicChat { is_protected: chat.is_protected(), profile_image, //BLOBS ? archived: chat.get_visibility() == chat::ChatVisibility::Archived, - chat_type: chat - .get_type() - .to_u32() - .ok_or_else(|| anyhow!("unknown chat type id"))?, // TODO get rid of this unwrap? + chat_type: chat.get_type().to_u32().context("unknown chat type id")?, is_unpromoted: chat.is_unpromoted(), is_self_talk: chat.is_self_talk(), color, diff --git a/deltachat-jsonrpc/src/api/types/message.rs b/deltachat-jsonrpc/src/api/types/message.rs index 44d2a1f05..13cb3cbd4 100644 --- a/deltachat-jsonrpc/src/api/types/message.rs +++ b/deltachat-jsonrpc/src/api/types/message.rs @@ -1,7 +1,7 @@ -use anyhow::{anyhow, Result}; +use anyhow::{anyhow, Context as _, Result}; use deltachat::chat::Chat; use deltachat::chat::ChatItem; -use deltachat::constants::Chattype; +use deltachat::chat::ChatVisibility; use deltachat::contact::Contact; use deltachat::context::Context; use deltachat::download; @@ -443,9 +443,17 @@ impl MessageNotificationInfo { pub struct MessageSearchResult { id: u32, author_profile_image: Option, + /// if sender name if overridden it will show it as ~alias author_name: String, author_color: String, - chat_name: Option, + author_id: u32, + chat_profile_image: Option, + chat_color: String, + chat_name: String, + chat_type: u32, + is_chat_protected: bool, + is_chat_contact_request: bool, + is_chat_archived: bool, message: String, timestamp: i64, } @@ -460,17 +468,31 @@ impl MessageSearchResult { Some(path_buf) => path_buf.to_str().map(|s| s.to_owned()), None => None, }; + let chat_profile_image = match chat.get_profile_image(context).await? { + Some(path_buf) => path_buf.to_str().map(|s| s.to_owned()), + None => None, + }; + + let author_name = if let Some(name) = message.get_override_sender_name() { + format!("~{name}") + } else { + sender.get_display_name().to_owned() + }; + let chat_color = color_int_to_hex_string(chat.get_color(context).await?); Ok(Self { id: msg_id.to_u32(), author_profile_image: profile_image, - author_name: sender.get_display_name().to_owned(), + author_name, author_color: color_int_to_hex_string(sender.get_color()), - chat_name: if chat.get_type() == Chattype::Single { - Some(chat.get_name().to_owned()) - } else { - None - }, + author_id: sender.id.to_u32(), + chat_name: chat.get_name().to_owned(), + chat_color, + chat_type: chat.get_type().to_u32().context("unknown chat type id")?, + chat_profile_image, + is_chat_protected: chat.is_protected(), + is_chat_contact_request: chat.is_contact_request(), + is_chat_archived: chat.get_visibility() == ChatVisibility::Archived, message: message.get_text().unwrap_or_default(), timestamp: message.get_timestamp(), })