diff --git a/deltachat-jsonrpc/src/api.rs b/deltachat-jsonrpc/src/api.rs index cb6260d1c..704a8b9dd 100644 --- a/deltachat-jsonrpc/src/api.rs +++ b/deltachat-jsonrpc/src/api.rs @@ -836,6 +836,13 @@ impl CommandApi { Ok(contacts.iter().map(|id| id.to_u32()).collect::>()) } + /// Returns contact IDs of the past chat members. + async fn get_past_chat_contacts(&self, account_id: u32, chat_id: u32) -> Result> { + let ctx = self.get_context(account_id).await?; + let contacts = chat::get_past_chat_contacts(&ctx, ChatId::new(chat_id)).await?; + Ok(contacts.iter().map(|id| id.to_u32()).collect::>()) + } + /// Create a new group chat. /// /// After creation, diff --git a/deltachat-jsonrpc/src/api/types/chat.rs b/deltachat-jsonrpc/src/api/types/chat.rs index 9c3c4cd98..b1ee3802c 100644 --- a/deltachat-jsonrpc/src/api/types/chat.rs +++ b/deltachat-jsonrpc/src/api/types/chat.rs @@ -1,7 +1,7 @@ use std::time::{Duration, SystemTime}; use anyhow::{bail, Context as _, Result}; -use deltachat::chat::{self, get_chat_contacts, ChatVisibility}; +use deltachat::chat::{self, get_chat_contacts, get_past_chat_contacts, ChatVisibility}; use deltachat::chat::{Chat, ChatId}; use deltachat::constants::Chattype; use deltachat::contact::{Contact, ContactId}; @@ -39,6 +39,10 @@ pub struct FullChat { is_self_talk: bool, contacts: Vec, contact_ids: Vec, + + /// Contact IDs of the past chat members. + past_contact_ids: Vec, + color: String, fresh_message_counter: usize, // is_group - please check over chat.type in frontend instead @@ -59,6 +63,7 @@ impl FullChat { let chat = Chat::load_from_db(context, rust_chat_id).await?; let contact_ids = get_chat_contacts(context, rust_chat_id).await?; + let past_contact_ids = get_past_chat_contacts(context, rust_chat_id).await?; let mut contacts = Vec::with_capacity(contact_ids.len()); @@ -111,6 +116,7 @@ impl FullChat { is_self_talk: chat.is_self_talk(), contacts, contact_ids: contact_ids.iter().map(|id| id.to_u32()).collect(), + past_contact_ids: past_contact_ids.iter().map(|id| id.to_u32()).collect(), color, fresh_message_counter, is_contact_request: chat.is_contact_request(), diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/chat.py b/deltachat-rpc-client/src/deltachat_rpc_client/chat.py index 49e8120ff..9d33a5a0f 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/chat.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/chat.py @@ -238,6 +238,11 @@ class Chat: contacts = self._rpc.get_chat_contacts(self.account.id, self.id) return [Contact(self.account, contact_id) for contact_id in contacts] + def get_past_contacts(self) -> list[Contact]: + """Get past contacts for this chat.""" + past_contacts = self._rpc.get_past_chat_contacts(self.account.id, self.id) + return [Contact(self.account, contact_id) for contact_id in past_contacts] + def set_image(self, path: str) -> None: """Set profile image of this chat. diff --git a/deltachat-rpc-client/tests/test_something.py b/deltachat-rpc-client/tests/test_something.py index cf1d422f2..f91ce9076 100644 --- a/deltachat-rpc-client/tests/test_something.py +++ b/deltachat-rpc-client/tests/test_something.py @@ -231,7 +231,9 @@ def test_chat(acfactory) -> None: group.get_fresh_message_count() group.mark_noticed() assert group.get_contacts() - group.remove_contact(alice_chat_bob) + assert group.get_past_contacts() == [] + group.remove_contact(alice_contact_bob) + assert len(group.get_past_contacts()) == 1 group.get_locations()