diff --git a/deltachat-jsonrpc/src/api/mod.rs b/deltachat-jsonrpc/src/api/mod.rs index 48ba56b74..0bfe14693 100644 --- a/deltachat-jsonrpc/src/api/mod.rs +++ b/deltachat-jsonrpc/src/api/mod.rs @@ -239,6 +239,38 @@ impl CommandApi { Ok(()) } + /// Returns the message IDs of all _fresh_ messages of any chat. + /// Typically used for implementing notification summaries + /// or badge counters e.g. on the app icon. + /// The list is already sorted and starts with the most recent fresh message. + /// + /// Messages belonging to muted chats or to the contact requests are not returned; + /// these messages should not be notified + /// and also badge counters should not include these messages. + /// + /// To get the number of fresh messages for a single chat, muted or not, + /// use `get_fresh_msg_cnt()`. + async fn get_fresh_msgs(&self, account_id: u32) -> Result> { + let ctx = self.get_context(account_id).await?; + Ok(ctx + .get_fresh_msgs() + .await? + .iter() + .map(|msg_id| msg_id.to_u32()) + .collect()) + } + + /// Get the number of _fresh_ messages in a chat. + /// Typically used to implement a badge with a number in the chatlist. + /// + /// If the specified chat is muted, + /// the UI should show the badge counter "less obtrusive", + /// e.g. using "gray" instead of "red" color. + async fn get_fresh_msg_cnt(&self, account_id: u32, chat_id: u32) -> Result { + let ctx = self.get_context(account_id).await?; + ChatId::new(chat_id).get_fresh_msg_cnt(&ctx).await + } + // --------------------------------------------- // autocrypt // --------------------------------------------- diff --git a/deltachat-jsonrpc/typescript/generated/client.ts b/deltachat-jsonrpc/typescript/generated/client.ts index 4317c1e8f..26008653d 100644 --- a/deltachat-jsonrpc/typescript/generated/client.ts +++ b/deltachat-jsonrpc/typescript/generated/client.ts @@ -147,6 +147,35 @@ export class RawClient { return (this._transport.request('stop_ongoing_process', [accountId] as RPC.Params)) as Promise; } + /** + * Returns the message IDs of all _fresh_ messages of any chat. + * Typically used for implementing notification summaries + * or badge counters e.g. on the app icon. + * The list is already sorted and starts with the most recent fresh message. + * + * Messages belonging to muted chats or to the contact requests are not returned; + * these messages should not be notified + * and also badge counters should not include these messages. + * + * To get the number of fresh messages for a single chat, muted or not, + * use `get_fresh_msg_cnt()`. + */ + public getFreshMsgs(accountId: T.U32): Promise<(T.U32)[]> { + return (this._transport.request('get_fresh_msgs', [accountId] as RPC.Params)) as Promise<(T.U32)[]>; + } + + /** + * Get the number of _fresh_ messages in a chat. + * Typically used to implement a badge with a number in the chatlist. + * + * If the specified chat is muted, + * the UI should show the badge counter "less obtrusive", + * e.g. using "gray" instead of "red" color. + */ + public getFreshMsgCnt(accountId: T.U32, chatId: T.U32): Promise { + return (this._transport.request('get_fresh_msg_cnt', [accountId, chatId] as RPC.Params)) as Promise; + } + public autocryptInitiateKeyTransfer(accountId: T.U32): Promise { return (this._transport.request('autocrypt_initiate_key_transfer', [accountId] as RPC.Params)) as Promise; diff --git a/deltachat-jsonrpc/typescript/generated/types.ts b/deltachat-jsonrpc/typescript/generated/types.ts index 852c4c433..f5722e47e 100644 --- a/deltachat-jsonrpc/typescript/generated/types.ts +++ b/deltachat-jsonrpc/typescript/generated/types.ts @@ -3,13 +3,13 @@ export type U32=number; export type Account=(({"type":"Configured";}&{"id":U32;"display_name":(string|null);"addr":(string|null);"profile_image":(string|null);"color":string;})|({"type":"Unconfigured";}&{"id":U32;})); export type ProviderInfo={"before_login_hint":string;"overview_page":string;"status":U32;}; +export type Usize=number; export type ChatListEntry=[U32,U32]; export type I64=number; -export type Usize=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;})|{"type":"ArchiveLink";}|({"type":"Error";}&{"id":U32;"error":string;})); export type Contact={"address":string;"color":string;"auth_name":string;"status":string;"display_name":string;"id":U32;"name":string;"profile_image":(string|null);"name_and_addr":string;"is_blocked":boolean;"is_verified":boolean;}; export type FullChat={"id":U32;"name":string;"is_protected":boolean;"profile_image":(string|null);"archived":boolean;"chat_type":U32;"is_unpromoted":boolean;"is_self_talk":boolean;"contacts":(Contact)[];"contact_ids":(U32)[];"color":string;"fresh_message_counter":Usize;"is_contact_request":boolean;"is_device_chat":boolean;"self_in_group":boolean;"is_muted":boolean;"ephemeral_timer":U32;"can_send":boolean;}; export type I32=number; export type U64=number; export type Message={"id":U32;"chat_id":U32;"from_id":U32;"quoted_text":(string|null);"quoted_message_id":(U32|null);"text":(string|null);"has_location":boolean;"has_html":boolean;"view_type":U32;"state":U32;"timestamp":I64;"sort_timestamp":I64;"received_timestamp":I64;"has_deviating_timestamp":boolean;"subject":string;"show_padlock":boolean;"is_setupmessage":boolean;"is_info":boolean;"is_forwarded":boolean;"duration":I32;"dimensions_height":I32;"dimensions_width":I32;"videochat_type":(U32|null);"videochat_url":(string|null);"override_sender_name":(string|null);"sender":Contact;"setup_code_begin":(string|null);"file":(string|null);"file_mime":(string|null);"file_bytes":U64;"file_name":(string|null);}; -export type __AllTyps=[string,boolean,Record,U32,U32,null,(U32)[],U32,null,(U32|null),(Account)[],U32,Account,U32,string,(ProviderInfo|null),U32,boolean,U32,Record,U32,string,(string|null),null,U32,Record,null,U32,string,null,U32,string,(string|null),U32,(string)[],Record,U32,null,U32,null,U32,string,U32,U32,string,null,U32,(U32|null),(string|null),(U32|null),(ChatListEntry)[],U32,(ChatListEntry)[],Record,U32,U32,FullChat,U32,U32,null,U32,U32,null,U32,string,string,U32,U32,U32,U32,(U32)[],U32,U32,Message,U32,(U32)[],Record,U32,U32,Contact,U32,string,(string|null),U32,U32,U32,U32,U32,U32,null,U32,U32,null,U32,(Contact)[],U32,U32,(string|null),(U32)[],U32,U32,(string|null),(Contact)[],U32,(U32)[],Record,U32,string,U32,U32]; +export type __AllTyps=[string,boolean,Record,U32,U32,null,(U32)[],U32,null,(U32|null),(Account)[],U32,Account,U32,string,(ProviderInfo|null),U32,boolean,U32,Record,U32,string,(string|null),null,U32,Record,null,U32,string,null,U32,string,(string|null),U32,(string)[],Record,U32,null,U32,null,U32,(U32)[],U32,U32,Usize,U32,string,U32,U32,string,null,U32,(U32|null),(string|null),(U32|null),(ChatListEntry)[],U32,(ChatListEntry)[],Record,U32,U32,FullChat,U32,U32,null,U32,U32,null,U32,string,string,U32,U32,U32,U32,(U32)[],U32,U32,Message,U32,(U32)[],Record,U32,U32,Contact,U32,string,(string|null),U32,U32,U32,U32,U32,U32,null,U32,U32,null,U32,(Contact)[],U32,U32,(string|null),(U32)[],U32,U32,(string|null),(Contact)[],U32,(U32)[],Record,U32,string,U32,U32];