diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fa26cd69..e80fd112c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ - `setStockStrings()` - `exportSelfKeys()` - `importSelfKeys()` +- breaking: jsonrpc: remove function `messageListGetMessageIds()`, it is replaced by `getMessageIds()` and `getMessageListEntries()` the latter returns a new `MessageListItem` type, which is the now prefered way of using the message list. - jsonrpc: add type: #3641, #3645 - `MessageSearchResult` - `Location` diff --git a/deltachat-jsonrpc/src/api/mod.rs b/deltachat-jsonrpc/src/api/mod.rs index 1ce7e6788..db4c9c519 100644 --- a/deltachat-jsonrpc/src/api/mod.rs +++ b/deltachat-jsonrpc/src/api/mod.rs @@ -6,6 +6,7 @@ use deltachat::{ }, chatlist::Chatlist, config::Config, + constants::DC_MSG_ID_DAYMARKER, contact::{may_be_valid_addr, Contact, ContactId, Origin}, context::get_info, ephemeral::Timer, @@ -46,7 +47,9 @@ use types::webxdc::WebxdcMessageInfo; use self::types::{ chat::{BasicChat, JSONRPCChatVisibility, MuteDuration}, location::JsonrpcLocation, - message::{MessageNotificationInfo, MessageSearchResult, MessageViewtype}, + message::{ + JSONRPCMessageListItem, MessageNotificationInfo, MessageSearchResult, MessageViewtype, + }, }; use num_traits::FromPrimitive; @@ -831,23 +834,34 @@ impl CommandApi { markseen_msgs(&ctx, msg_ids.into_iter().map(MsgId::new).collect()).await } - async fn message_list_get_message_ids( - &self, - account_id: u32, - chat_id: u32, - flags: u32, - ) -> Result> { + async fn get_message_ids(&self, account_id: u32, chat_id: u32, flags: u32) -> Result> { let ctx = self.get_context(account_id).await?; let msg = get_chat_msgs(&ctx, ChatId::new(chat_id), flags).await?; Ok(msg .iter() - .filter_map(|chat_item| match chat_item { - deltachat::chat::ChatItem::Message { msg_id } => Some(msg_id.to_u32()), - _ => None, + .map(|chat_item| -> u32 { + match chat_item { + deltachat::chat::ChatItem::Message { msg_id } => msg_id.to_u32(), + deltachat::chat::ChatItem::DayMarker { .. } => DC_MSG_ID_DAYMARKER, + } }) .collect()) } + async fn get_message_list_entries( + &self, + account_id: u32, + chat_id: u32, + flags: u32, + ) -> Result> { + let ctx = self.get_context(account_id).await?; + let msg = get_chat_msgs(&ctx, ChatId::new(chat_id), flags).await?; + Ok(msg + .iter() + .map(|chat_item| (*chat_item).into()) + .collect::>()) + } + async fn message_get_message(&self, account_id: u32, message_id: u32) -> Result { let ctx = self.get_context(account_id).await?; MessageObject::from_message_id(&ctx, message_id).await diff --git a/deltachat-jsonrpc/src/api/types/message.rs b/deltachat-jsonrpc/src/api/types/message.rs index bb5f15107..c7fdc17b5 100644 --- a/deltachat-jsonrpc/src/api/types/message.rs +++ b/deltachat-jsonrpc/src/api/types/message.rs @@ -1,5 +1,6 @@ use anyhow::{anyhow, Result}; use deltachat::chat::Chat; +use deltachat::chat::ChatItem; use deltachat::constants::Chattype; use deltachat::contact::Contact; use deltachat::context::Context; @@ -385,3 +386,29 @@ impl MessageSearchResult { }) } } + +#[derive(Serialize, TypeDef)] +#[serde(rename_all = "camelCase", rename = "MessageListItem")] +pub enum JSONRPCMessageListItem { + Message { + msg_id: u32, + }, + + /// Day marker, separating messages that correspond to different + /// days according to local time. + DayMarker { + /// Marker timestamp, for day markers + timestamp: i64, + }, +} + +impl From for JSONRPCMessageListItem { + fn from(item: ChatItem) -> Self { + match item { + ChatItem::Message { msg_id } => JSONRPCMessageListItem::Message { + msg_id: msg_id.to_u32(), + }, + ChatItem::DayMarker { timestamp } => JSONRPCMessageListItem::DayMarker { timestamp }, + } + } +} diff --git a/deltachat-jsonrpc/typescript/example/example.ts b/deltachat-jsonrpc/typescript/example/example.ts index c3cfeead4..951703fde 100644 --- a/deltachat-jsonrpc/typescript/example/example.ts +++ b/deltachat-jsonrpc/typescript/example/example.ts @@ -73,7 +73,7 @@ async function run() { chatId ); write($main, `

${chat.name}

`); - const messageIds = await client.rpc.messageListGetMessageIds( + const messageIds = await client.rpc.getMessageIds( selectedAccount, chatId, 0 diff --git a/deltachat-jsonrpc/typescript/generated/client.ts b/deltachat-jsonrpc/typescript/generated/client.ts index fa1e35302..d4b5e095d 100644 --- a/deltachat-jsonrpc/typescript/generated/client.ts +++ b/deltachat-jsonrpc/typescript/generated/client.ts @@ -536,8 +536,13 @@ export class RawClient { } - public messageListGetMessageIds(accountId: T.U32, chatId: T.U32, flags: T.U32): Promise<(T.U32)[]> { - return (this._transport.request('message_list_get_message_ids', [accountId, chatId, flags] as RPC.Params)) as Promise<(T.U32)[]>; + public getMessageIds(accountId: T.U32, chatId: T.U32, flags: T.U32): Promise<(T.U32)[]> { + return (this._transport.request('get_message_ids', [accountId, chatId, flags] as RPC.Params)) as Promise<(T.U32)[]>; + } + + + public getMessageListEntries(accountId: T.U32, chatId: T.U32, flags: T.U32): Promise<(T.MessageListItem)[]> { + return (this._transport.request('get_message_list_entries', [accountId, chatId, flags] as RPC.Params)) as Promise<(T.MessageListItem)[]>; } diff --git a/deltachat-jsonrpc/typescript/generated/types.ts b/deltachat-jsonrpc/typescript/generated/types.ts index 55146d3b4..e368cea0f 100644 --- a/deltachat-jsonrpc/typescript/generated/types.ts +++ b/deltachat-jsonrpc/typescript/generated/types.ts @@ -52,6 +52,16 @@ export type BasicChat= {"id":U32;"name":string;"isProtected":boolean;"profileImage":(string|null);"archived":boolean;"chatType":U32;"isUnpromoted":boolean;"isSelfTalk":boolean;"color":string;"isContactRequest":boolean;"isDeviceChat":boolean;"isMuted":boolean;}; export type ChatVisibility=("Normal"|"Archived"|"Pinned"); export type MuteDuration=("NotMuted"|"Forever"|{"Until":I64;}); +export type MessageListItem=({"message":{"msg_id":U32;};}|{ +/** + * Day marker, separating messages that correspond to different + * days according to local time. + */ +"dayMarker":{ +/** + * Marker timestamp, for day markers + */ +"timestamp":I64;};}); export type MessageQuote=(({"kind":"JustText";}&{"text":string;})|({"kind":"WithMessage";}&{"text":string;"messageId":U32;"authorDisplayName":string;"authorDisplayColor":string;"overrideSenderName":(string|null);"image":(string|null);"isForwarded":boolean;})); export type Viewtype=("Unknown"| /** @@ -150,4 +160,4 @@ export type MessageNotificationInfo={"id":U32;"chatId":U32;"accountId":U32;"imag export type MessageSearchResult={"id":U32;"authorProfileImage":(string|null);"authorName":string;"authorColor":string;"chatName":(string|null);"message":string;"timestamp":I64;}; export type F64=number; export type Location={"locationId":U32;"isIndependent":boolean;"latitude":F64;"longitude":F64;"accuracy":F64;"timestamp":I64;"contactId":U32;"msgId":U32;"chatId":U32;"marker":(string|null);}; -export type __AllTyps=[string,boolean,Record,U32,U32,null,(U32)[],U32,null,(U32|null),(Account)[],U32,Account,U32,U64,U32,string,(ProviderInfo|null),U32,boolean,U32,Record,U32,string,(string|null),null,U32,Record,null,U32,string,null,U32,string,Qr,U32,string,(string|null),U32,(string)[],Record,Record,null,U32,null,U32,null,U32,string,(string|null),null,U32,string,(string|null),null,U32,(U32)[],U32,U32,Usize,U32,boolean,I64,Usize,U32,string,U32,U32,string,null,U32,(U32|null),(string|null),(U32|null),(ChatListEntry)[],U32,(ChatListEntry)[],Record,U32,U32,FullChat,U32,U32,BasicChat,U32,U32,null,U32,U32,null,U32,U32,null,U32,U32,string,U32,(U32|null),[string,string],U32,U32,null,U32,U32,U32,null,U32,U32,U32,null,U32,U32,(U32)[],U32,string,boolean,U32,U32,U32,U32,U32,string,null,U32,U32,(string|null),null,U32,U32,ChatVisibility,null,U32,U32,U32,null,U32,U32,U32,U32,string,string,U32,U32,U32,null,U32,U32,(U32|null),U32,U32,MuteDuration,null,U32,U32,boolean,U32,(U32)[],null,U32,U32,U32,(U32)[],U32,U32,Message,U32,(U32)[],Record,U32,U32,MessageNotificationInfo,U32,(U32)[],null,U32,U32,string,U32,U32,null,U32,string,(U32|null),(U32)[],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,U32,string,U32,string,(U32|null),U32,(U32|null),Viewtype,(Viewtype|null),(Viewtype|null),(U32)[],U32,U32,Viewtype,(Viewtype|null),(Viewtype|null),[(U32|null),(U32|null)],null,U32,U32,U32,string,U32,(U32|null),(U32|null),I64,I64,(Location)[],U32,U32,string,string,null,U32,U32,U32,string,U32,U32,WebxdcMessageInfo,U32,(U32)[],U32,null,U32,U32,null,U32,U32,(Message|null),U32,U32,U32,U32,string,U32,U32,U32,U32,(string|null),(string|null),([F64,F64]|null),(U32|null),[U32,Message],U32,U32,(string|null),(string|null),(U32|null),null]; +export type __AllTyps=[string,boolean,Record,U32,U32,null,(U32)[],U32,null,(U32|null),(Account)[],U32,Account,U32,U64,U32,string,(ProviderInfo|null),U32,boolean,U32,Record,U32,string,(string|null),null,U32,Record,null,U32,string,null,U32,string,Qr,U32,string,(string|null),U32,(string)[],Record,Record,null,U32,null,U32,null,U32,string,(string|null),null,U32,string,(string|null),null,U32,(U32)[],U32,U32,Usize,U32,boolean,I64,Usize,U32,string,U32,U32,string,null,U32,(U32|null),(string|null),(U32|null),(ChatListEntry)[],U32,(ChatListEntry)[],Record,U32,U32,FullChat,U32,U32,BasicChat,U32,U32,null,U32,U32,null,U32,U32,null,U32,U32,string,U32,(U32|null),[string,string],U32,U32,null,U32,U32,U32,null,U32,U32,U32,null,U32,U32,(U32)[],U32,string,boolean,U32,U32,U32,U32,U32,string,null,U32,U32,(string|null),null,U32,U32,ChatVisibility,null,U32,U32,U32,null,U32,U32,U32,U32,string,string,U32,U32,U32,null,U32,U32,(U32|null),U32,U32,MuteDuration,null,U32,U32,boolean,U32,(U32)[],null,U32,U32,U32,(U32)[],U32,U32,U32,(MessageListItem)[],U32,U32,Message,U32,(U32)[],Record,U32,U32,MessageNotificationInfo,U32,(U32)[],null,U32,U32,string,U32,U32,null,U32,string,(U32|null),(U32)[],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,U32,string,U32,string,(U32|null),U32,(U32|null),Viewtype,(Viewtype|null),(Viewtype|null),(U32)[],U32,U32,Viewtype,(Viewtype|null),(Viewtype|null),[(U32|null),(U32|null)],null,U32,U32,U32,string,U32,(U32|null),(U32|null),I64,I64,(Location)[],U32,U32,string,string,null,U32,U32,U32,string,U32,U32,WebxdcMessageInfo,U32,(U32)[],U32,null,U32,U32,null,U32,U32,(Message|null),U32,U32,U32,U32,string,U32,U32,U32,U32,(string|null),(string|null),([F64,F64]|null),(U32|null),[U32,Message],U32,U32,(string|null),(string|null),(U32|null),null]; diff --git a/deltachat-jsonrpc/typescript/test/online.ts b/deltachat-jsonrpc/typescript/test/online.ts index ba8b50673..b80f4599a 100644 --- a/deltachat-jsonrpc/typescript/test/online.ts +++ b/deltachat-jsonrpc/typescript/test/online.ts @@ -98,7 +98,7 @@ describe("online tests", function () { await dc.rpc.miscSendTextMessage(accountId1, "Hello", chatId); const { field1: chatIdOnAccountB } = await eventPromise; await dc.rpc.acceptChat(accountId2, chatIdOnAccountB); - const messageList = await dc.rpc.messageListGetMessageIds( + const messageList = await dc.rpc.getMessageIds( accountId2, chatIdOnAccountB, 0 @@ -134,7 +134,7 @@ describe("online tests", function () { const { field1: chatIdOnAccountB } = event; await dc.rpc.acceptChat(accountId2, chatIdOnAccountB); - const messageList = await dc.rpc.messageListGetMessageIds( + const messageList = await dc.rpc.getMessageIds( accountId2, chatIdOnAccountB, 0 @@ -154,7 +154,7 @@ describe("online tests", function () { await eventPromise2; const messageId = ( - await dc.rpc.messageListGetMessageIds(accountId1, chatId, 0) + await dc.rpc.getMessageIds(accountId1, chatId, 0) ).reverse()[0]; const message2 = await dc.rpc.messageGetMessage(accountId1, messageId); expect(message2.text).equal("super secret message");