Skip to content

Commit 8dcd8aa

Browse files
committed
api: add JSON-RPC API to get past members
1 parent 65a9c4b commit 8dcd8aa

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

deltachat-jsonrpc/src/api.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,13 @@ impl CommandApi {
836836
Ok(contacts.iter().map(|id| id.to_u32()).collect::<Vec<u32>>())
837837
}
838838

839+
/// Returns contact IDs of the past chat members.
840+
async fn get_past_chat_contacts(&self, account_id: u32, chat_id: u32) -> Result<Vec<u32>> {
841+
let ctx = self.get_context(account_id).await?;
842+
let contacts = chat::get_past_chat_contacts(&ctx, ChatId::new(chat_id)).await?;
843+
Ok(contacts.iter().map(|id| id.to_u32()).collect::<Vec<u32>>())
844+
}
845+
839846
/// Create a new group chat.
840847
///
841848
/// After creation,

deltachat-jsonrpc/src/api/types/chat.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::time::{Duration, SystemTime};
22

33
use anyhow::{bail, Context as _, Result};
4-
use deltachat::chat::{self, get_chat_contacts, ChatVisibility};
4+
use deltachat::chat::{self, get_chat_contacts, get_past_chat_contacts, ChatVisibility};
55
use deltachat::chat::{Chat, ChatId};
66
use deltachat::constants::Chattype;
77
use deltachat::contact::{Contact, ContactId};
@@ -39,6 +39,10 @@ pub struct FullChat {
3939
is_self_talk: bool,
4040
contacts: Vec<ContactObject>,
4141
contact_ids: Vec<u32>,
42+
43+
/// Contact IDs of the past chat members.
44+
past_contact_ids: Vec<u32>,
45+
4246
color: String,
4347
fresh_message_counter: usize,
4448
// is_group - please check over chat.type in frontend instead
@@ -59,6 +63,7 @@ impl FullChat {
5963
let chat = Chat::load_from_db(context, rust_chat_id).await?;
6064

6165
let contact_ids = get_chat_contacts(context, rust_chat_id).await?;
66+
let past_contact_ids = get_past_chat_contacts(context, rust_chat_id).await?;
6267

6368
let mut contacts = Vec::with_capacity(contact_ids.len());
6469

@@ -111,6 +116,7 @@ impl FullChat {
111116
is_self_talk: chat.is_self_talk(),
112117
contacts,
113118
contact_ids: contact_ids.iter().map(|id| id.to_u32()).collect(),
119+
past_contact_ids: past_contact_ids.iter().map(|id| id.to_u32()).collect(),
114120
color,
115121
fresh_message_counter,
116122
is_contact_request: chat.is_contact_request(),

deltachat-rpc-client/src/deltachat_rpc_client/chat.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ def get_contacts(self) -> list[Contact]:
238238
contacts = self._rpc.get_chat_contacts(self.account.id, self.id)
239239
return [Contact(self.account, contact_id) for contact_id in contacts]
240240

241+
def get_past_contacts(self) -> list[Contact]:
242+
"""Get past contacts for this chat."""
243+
past_contacts = self._rpc.get_past_chat_contacts(self.account.id, self.id)
244+
return [Contact(self.account, contact_id) for contact_id in past_contacts]
245+
241246
def set_image(self, path: str) -> None:
242247
"""Set profile image of this chat.
243248

deltachat-rpc-client/tests/test_something.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ def test_chat(acfactory) -> None:
231231
group.get_fresh_message_count()
232232
group.mark_noticed()
233233
assert group.get_contacts()
234-
group.remove_contact(alice_chat_bob)
234+
assert group.get_past_contacts() == []
235+
group.remove_contact(alice_contact_bob)
236+
assert len(group.get_past_contacts()) == 1
235237
group.get_locations()
236238

237239

0 commit comments

Comments
 (0)