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

@@ -12,6 +12,7 @@
`dc_accounts_event_emitter_unref`. `dc_accounts_event_emitter_unref`.
- add `dc_contact_was_seen_recently()` #3560 - add `dc_contact_was_seen_recently()` #3560
- jsonrpc: add `is_broadcast` property to `ChatListItemFetchResult` - jsonrpc: add `is_broadcast` property to `ChatListItemFetchResult`
- jsonrpc: add `was_seen_recently` property to `ChatListItemFetchResult`, `FullChat` and `Contact`
### Changes ### Changes
- order contact lists by "last seen"; - order contact lists by "last seen";

View File

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

View File

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

View File

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

View File

@@ -8,12 +8,16 @@ export type Usize=number;
export type ChatListEntry=[U32,U32]; export type ChatListEntry=[U32,U32];
export type I64=number; export type I64=number;
export type ChatListItemFetchResult=(({"type":"ChatListItem";}&{"id":U32;"name":string;"avatarPath":(string|null);"color":string;"lastUpdated":(I64|null);"summaryText1":string;"summaryText2":string;"summaryStatus":U32;"isProtected":boolean;"isGroup":boolean;"freshMessageCounter":Usize;"isSelfTalk":boolean;"isDeviceTalk":boolean;"isSendingLocation":boolean;"isSelfInGroup":boolean;"isArchived":boolean;"isPinned":boolean;"isMuted":boolean;"isContactRequest":boolean; export type ChatListItemFetchResult=(({"type":"ChatListItem";}&{"id":U32;"name":string;"avatarPath":(string|null);"color":string;"lastUpdated":(I64|null);"summaryText1":string;"summaryText2":string;"summaryStatus":U32;"isProtected":boolean;"isGroup":boolean;"freshMessageCounter":Usize;"isSelfTalk":boolean;"isDeviceTalk":boolean;"isSendingLocation":boolean;"isSelfInGroup":boolean;"isArchived":boolean;"isPinned":boolean;"isMuted":boolean;"isContactRequest":boolean;
/**
* true when chat is a broadcastlist
*/
"isBroadcast":boolean;
/** /**
* contact id if this is a dm chat (for view profile entry in context menu) * contact id if this is a dm chat (for view profile entry in context menu)
*/ */
"dmChatContact":(U32|null);})|{"type":"ArchiveLink";}|({"type":"Error";}&{"id":U32;"error":string;})); "dmChatContact":(U32|null);"wasSeenRecently":boolean;})|{"type":"ArchiveLink";}|({"type":"Error";}&{"id":U32;"error":string;}));
export type Contact={"address":string;"color":string;"authName":string;"status":string;"displayName":string;"id":U32;"name":string;"profileImage":(string|null);"nameAndAddr":string;"isBlocked":boolean;"isVerified":boolean;}; export type Contact={"address":string;"color":string;"authName":string;"status":string;"displayName":string;"id":U32;"name":string;"profileImage":(string|null);"nameAndAddr":string;"isBlocked":boolean;"isVerified":boolean;"wasSeenRecently":boolean;};
export type FullChat={"id":U32;"name":string;"isProtected":boolean;"profileImage":(string|null);"archived":boolean;"chatType":U32;"isUnpromoted":boolean;"isSelfTalk":boolean;"contacts":(Contact)[];"contactIds":(U32)[];"color":string;"freshMessageCounter":Usize;"isContactRequest":boolean;"isDeviceChat":boolean;"selfInGroup":boolean;"isMuted":boolean;"ephemeralTimer":U32;"canSend":boolean;}; export type FullChat={"id":U32;"name":string;"isProtected":boolean;"profileImage":(string|null);"archived":boolean;"chatType":U32;"isUnpromoted":boolean;"isSelfTalk":boolean;"contacts":(Contact)[];"contactIds":(U32)[];"color":string;"freshMessageCounter":Usize;"isContactRequest":boolean;"isDeviceChat":boolean;"selfInGroup":boolean;"isMuted":boolean;"ephemeralTimer":U32;"canSend":boolean;"wasSeenRecently":boolean;};
export type Viewtype=("Unknown"| export type Viewtype=("Unknown"|
/** /**
* Text message. * Text message.