jsonrpc: add was_seen_recently property

to `ChatListItemFetchResult`, `FullChat` and `Contact`
This commit is contained in:
Simon Laux
2022-09-06 22:20:18 +02:00
committed by Simon Laux
parent 96ce8eb851
commit 33b18e3014
6 changed files with 41 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
use anyhow::{anyhow, Result};
use deltachat::chat::get_chat_contacts;
use deltachat::chat::{Chat, ChatId};
use deltachat::constants::Chattype;
use deltachat::contact::{Contact, ContactId};
use deltachat::context::Context;
use num_traits::cast::ToPrimitive;
@@ -33,6 +34,7 @@ pub struct FullChat {
is_muted: bool,
ephemeral_timer: u32, //TODO look if there are more important properties in newer core versions
can_send: bool,
was_seen_recently: bool,
}
impl FullChat {
@@ -65,6 +67,17 @@ impl FullChat {
let can_send = chat.can_send(context).await?;
let was_seen_recently = if chat.get_type() == Chattype::Single {
match contact_ids.get(0) {
Some(contact) => Contact::load_from_db(context, *contact)
.await?
.was_seen_recently(),
None => false,
}
} else {
false
};
Ok(FullChat {
id: chat_id,
name: chat.name.clone(),
@@ -87,6 +100,7 @@ impl FullChat {
is_muted: chat.is_muted(),
ephemeral_timer,
can_send,
was_seen_recently,
})
}
}

View File

@@ -1,6 +1,6 @@
use anyhow::Result;
use deltachat::constants::*;
use deltachat::contact::ContactId;
use deltachat::contact::{Contact, ContactId};
use deltachat::{
chat::{get_chat_contacts, ChatVisibility},
chatlist::Chatlist,
@@ -46,6 +46,7 @@ pub enum ChatListItemFetchResult {
is_broadcast: bool,
/// contact id if this is a dm chat (for view profile entry in context menu)
dm_chat_contact: Option<u32>,
was_seen_recently: bool,
},
ArchiveLink,
#[serde(rename_all = "camelCase")]
@@ -94,10 +95,20 @@ pub(crate) async fn get_chat_list_item_by_id(
let self_in_group = chat_contacts.contains(&ContactId::SELF);
let dm_chat_contact = if chat.get_type() == Chattype::Single {
chat_contacts.get(0).map(|contact_id| contact_id.to_u32())
let (dm_chat_contact, was_seen_recently) = if chat.get_type() == Chattype::Single {
let contact = chat_contacts.get(0);
let was_seen_recently = match contact {
Some(contact) => Contact::load_from_db(ctx, *contact)
.await?
.was_seen_recently(),
None => false,
};
(
contact.map(|contact_id| contact_id.to_u32()),
was_seen_recently,
)
} else {
None
(None, false)
};
let fresh_message_counter = chat_id.get_fresh_msg_cnt(ctx).await?;
@@ -125,5 +136,6 @@ pub(crate) async fn get_chat_list_item_by_id(
is_contact_request: chat.is_contact_request(),
is_broadcast: chat.get_type() == Chattype::Broadcast,
dm_chat_contact,
was_seen_recently,
})
}

View File

@@ -20,6 +20,7 @@ pub struct ContactObject {
name_and_addr: String,
is_blocked: bool,
is_verified: bool,
was_seen_recently: bool,
}
impl ContactObject {
@@ -45,6 +46,7 @@ impl ContactObject {
name_and_addr: contact.get_name_n_addr(),
is_blocked: contact.is_blocked(),
is_verified,
was_seen_recently: contact.was_seen_recently(),
})
}
}