api(jsonrpc): return only chat IDs for similar chats

This is already the way `get_chatlist_entries` works.

`get_similar_chatlist_entries` is renamed into
`get_similar_chat_ids` because return values are not entries anymore.
This commit is contained in:
link2xt
2023-09-08 17:54:05 +00:00
parent 0562e23ee0
commit 2939de013b
2 changed files with 11 additions and 19 deletions

View File

@@ -39,7 +39,6 @@ pub mod types;
use num_traits::FromPrimitive; use num_traits::FromPrimitive;
use types::account::Account; use types::account::Account;
use types::chat::FullChat; use types::chat::FullChat;
use types::chat_list::ChatListEntry;
use types::contact::ContactObject; use types::contact::ContactObject;
use types::events::Event; use types::events::Event;
use types::http::HttpResponse; use types::http::HttpResponse;
@@ -568,22 +567,18 @@ impl CommandApi {
} }
/// Returns chats similar to the given one. /// Returns chats similar to the given one.
async fn get_similar_chatlist_entries( ///
&self, /// Experimental API, subject to change without notice.
account_id: u32, async fn get_similar_chat_ids(&self, account_id: u32, chat_id: u32) -> Result<Vec<u32>> {
chat_id: u32,
) -> Result<Vec<ChatListEntry>> {
let ctx = self.get_context(account_id).await?; let ctx = self.get_context(account_id).await?;
let chat_id = ChatId::new(chat_id); let chat_id = ChatId::new(chat_id);
let list = chat_id.get_similar_chatlist(&ctx).await?; let list = chat_id
let mut l: Vec<ChatListEntry> = Vec::with_capacity(list.len()); .get_similar_chat_ids(&ctx)
for i in 0..list.len() { .await?
l.push(ChatListEntry( .into_iter()
list.get_chat_id(i)?.to_u32(), .map(|(chat_id, _metric)| chat_id.to_u32())
list.get_msg_id(i)?.unwrap_or_default().to_u32(), .collect();
)); Ok(list)
}
Ok(l)
} }
async fn get_chatlist_items_by_entries( async fn get_chatlist_items_by_entries(

View File

@@ -8,15 +8,12 @@ use deltachat::{
chatlist::Chatlist, chatlist::Chatlist,
}; };
use num_traits::cast::ToPrimitive; use num_traits::cast::ToPrimitive;
use serde::{Deserialize, Serialize}; 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; use super::message::MessageViewtype;
#[derive(Deserialize, Serialize, TypeDef, schemars::JsonSchema)]
pub struct ChatListEntry(pub u32, pub u32);
#[derive(Serialize, TypeDef, schemars::JsonSchema)] #[derive(Serialize, TypeDef, schemars::JsonSchema)]
#[serde(tag = "type")] #[serde(tag = "type")]
pub enum ChatListItemFetchResult { pub enum ChatListItemFetchResult {