mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 08:56:30 +03:00
api: add JSON-RPC API to get past members
This commit is contained in:
@@ -836,6 +836,13 @@ impl CommandApi {
|
|||||||
Ok(contacts.iter().map(|id| id.to_u32()).collect::<Vec<u32>>())
|
Ok(contacts.iter().map(|id| id.to_u32()).collect::<Vec<u32>>())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns contact IDs of the past chat members.
|
||||||
|
async fn get_past_chat_contacts(&self, account_id: u32, chat_id: u32) -> Result<Vec<u32>> {
|
||||||
|
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::<Vec<u32>>())
|
||||||
|
}
|
||||||
|
|
||||||
/// Create a new group chat.
|
/// Create a new group chat.
|
||||||
///
|
///
|
||||||
/// After creation,
|
/// After creation,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
|
|
||||||
use anyhow::{bail, Context as _, Result};
|
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::chat::{Chat, ChatId};
|
||||||
use deltachat::constants::Chattype;
|
use deltachat::constants::Chattype;
|
||||||
use deltachat::contact::{Contact, ContactId};
|
use deltachat::contact::{Contact, ContactId};
|
||||||
@@ -39,6 +39,10 @@ pub struct FullChat {
|
|||||||
is_self_talk: bool,
|
is_self_talk: bool,
|
||||||
contacts: Vec<ContactObject>,
|
contacts: Vec<ContactObject>,
|
||||||
contact_ids: Vec<u32>,
|
contact_ids: Vec<u32>,
|
||||||
|
|
||||||
|
/// Contact IDs of the past chat members.
|
||||||
|
past_contact_ids: Vec<u32>,
|
||||||
|
|
||||||
color: String,
|
color: String,
|
||||||
fresh_message_counter: usize,
|
fresh_message_counter: usize,
|
||||||
// is_group - please check over chat.type in frontend instead
|
// 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 chat = Chat::load_from_db(context, rust_chat_id).await?;
|
||||||
|
|
||||||
let contact_ids = get_chat_contacts(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());
|
let mut contacts = Vec::with_capacity(contact_ids.len());
|
||||||
|
|
||||||
@@ -111,6 +116,7 @@ impl FullChat {
|
|||||||
is_self_talk: chat.is_self_talk(),
|
is_self_talk: chat.is_self_talk(),
|
||||||
contacts,
|
contacts,
|
||||||
contact_ids: contact_ids.iter().map(|id| id.to_u32()).collect(),
|
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,
|
color,
|
||||||
fresh_message_counter,
|
fresh_message_counter,
|
||||||
is_contact_request: chat.is_contact_request(),
|
is_contact_request: chat.is_contact_request(),
|
||||||
|
|||||||
@@ -238,6 +238,11 @@ class Chat:
|
|||||||
contacts = self._rpc.get_chat_contacts(self.account.id, self.id)
|
contacts = self._rpc.get_chat_contacts(self.account.id, self.id)
|
||||||
return [Contact(self.account, contact_id) for contact_id in contacts]
|
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:
|
def set_image(self, path: str) -> None:
|
||||||
"""Set profile image of this chat.
|
"""Set profile image of this chat.
|
||||||
|
|
||||||
|
|||||||
@@ -231,7 +231,9 @@ def test_chat(acfactory) -> None:
|
|||||||
group.get_fresh_message_count()
|
group.get_fresh_message_count()
|
||||||
group.mark_noticed()
|
group.mark_noticed()
|
||||||
assert group.get_contacts()
|
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()
|
group.get_locations()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user