diff --git a/CHANGELOG.md b/CHANGELOG.md index 21e3da55a..c425a6fc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### API-Changes - jsonrpc: add `mailingListAddress` property to `FullChat` #3607 - jsonrpc: add `MessageNotificationInfo` & `messageGetNotificationInfo()` #3614 +- jsonrpc: add `chat_get_neighboring_media` function #3610 ### Changes - truncate incoming messages by lines instead of just length #3480 diff --git a/deltachat-jsonrpc/src/api/mod.rs b/deltachat-jsonrpc/src/api/mod.rs index 410b7123f..037e2ad2d 100644 --- a/deltachat-jsonrpc/src/api/mod.rs +++ b/deltachat-jsonrpc/src/api/mod.rs @@ -850,6 +850,51 @@ impl CommandApi { Ok(media.iter().map(|msg_id| msg_id.to_u32()).collect()) } + /// Search next/previous message based on a given message and a list of types. + /// Typically used to implement the "next" and "previous" buttons + /// in a gallery or in a media player. + /// + /// one combined call for getting chat::get_next_media for both directions + /// the manual chat::get_next_media in only one direction is not exposed by the jsonrpc yet + async fn chat_get_neighboring_media( + &self, + account_id: u32, + msg_id: u32, + message_type: MessageViewtype, + or_message_type2: Option, + or_message_type3: Option, + ) -> Result<(Option, Option)> { + let ctx = self.get_context(account_id).await?; + + let msg_type: Viewtype = message_type.into(); + let msg_type2: Viewtype = or_message_type2.map(|v| v.into()).unwrap_or_default(); + let msg_type3: Viewtype = or_message_type3.map(|v| v.into()).unwrap_or_default(); + + let prev = chat::get_next_media( + &ctx, + MsgId::new(msg_id), + chat::Direction::Backward, + msg_type, + msg_type2, + msg_type3, + ) + .await? + .map(|id| id.to_u32()); + + let next = chat::get_next_media( + &ctx, + MsgId::new(msg_id), + chat::Direction::Forward, + msg_type, + msg_type2, + msg_type3, + ) + .await? + .map(|id| id.to_u32()); + + Ok((prev, next)) + } + // --------------------------------------------- // connectivity // --------------------------------------------- diff --git a/deltachat-jsonrpc/typescript/generated/client.ts b/deltachat-jsonrpc/typescript/generated/client.ts index be8be28b1..9b28600ae 100644 --- a/deltachat-jsonrpc/typescript/generated/client.ts +++ b/deltachat-jsonrpc/typescript/generated/client.ts @@ -403,8 +403,8 @@ export class RawClient { /** * Fetch info desktop needs for creating a notification for a message */ - public messageGetNotificationInfo(accountId: T.U32, messageId: T.U32): Promise { - return (this._transport.request('message_get_notification_info', [accountId, messageId] as RPC.Params)) as Promise; + public messageGetNotificationInfo(accountId: T.U32, messageId: T.U32): Promise { + return (this._transport.request('message_get_notification_info', [accountId, messageId] as RPC.Params)) as Promise; } /** @@ -506,6 +506,18 @@ export class RawClient { return (this._transport.request('chat_get_media', [accountId, chatId, messageType, orMessageType2, orMessageType3] as RPC.Params)) as Promise<(T.U32)[]>; } + /** + * Search next/previous message based on a given message and a list of types. + * Typically used to implement the "next" and "previous" buttons + * in a gallery or in a media player. + * + * one combined call for getting chat::get_next_media for both directions + * the manual chat::get_next_media in only one direction is not exposed by the jsonrpc yet + */ + public chatGetNeighboringMedia(accountId: T.U32, msgId: T.U32, messageType: T.Viewtype, orMessageType2: (T.Viewtype|null), orMessageType3: (T.Viewtype|null)): Promise<[(T.U32|null),(T.U32|null)]> { + return (this._transport.request('chat_get_neighboring_media', [accountId, msgId, messageType, orMessageType2, orMessageType3] as RPC.Params)) as Promise<[(T.U32|null),(T.U32|null)]>; + } + /** * Indicate that the network likely has come back. * or just that the network conditions might have changed diff --git a/deltachat-jsonrpc/typescript/generated/types.ts b/deltachat-jsonrpc/typescript/generated/types.ts index a930ee5da..f24fc4117 100644 --- a/deltachat-jsonrpc/typescript/generated/types.ts +++ b/deltachat-jsonrpc/typescript/generated/types.ts @@ -137,7 +137,7 @@ export type WebxdcMessageInfo={ "internetAccess":boolean;}; export type DownloadState=("Done"|"Available"|"Failure"|"InProgress"); export type Message={"id":U32;"chatId":U32;"fromId":U32;"quote":(MessageQuote|null);"parentId":(U32|null);"text":(string|null);"hasLocation":boolean;"hasHtml":boolean;"viewType":Viewtype;"state":U32;"timestamp":I64;"sortTimestamp":I64;"receivedTimestamp":I64;"hasDeviatingTimestamp":boolean;"subject":string;"showPadlock":boolean;"isSetupmessage":boolean;"isInfo":boolean;"isForwarded":boolean;"duration":I32;"dimensionsHeight":I32;"dimensionsWidth":I32;"videochatType":(U32|null);"videochatUrl":(string|null);"overrideSenderName":(string|null);"sender":Contact;"setupCodeBegin":(string|null);"file":(string|null);"fileMime":(string|null);"fileBytes":U64;"fileName":(string|null);"webxdcInfo":(WebxdcMessageInfo|null);"downloadState":DownloadState;}; -export type MessageNotificationData={"id":U32;"chatId":U32;"accountId":U32;"image":(string|null);"imageMimeType":(string|null);"chatName":string;"chatProfileImage":(string|null); +export type MessageNotificationInfo={"id":U32;"chatId":U32;"accountId":U32;"image":(string|null);"imageMimeType":(string|null);"chatName":string;"chatProfileImage":(string|null); /** * also known as summary_text1 */ @@ -147,4 +147,4 @@ export type MessageNotificationData={"id":U32;"chatId":U32;"accountId":U32;"imag */ "summaryText":string;}; export type F64=number; -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,Qr,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,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,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,MessageNotificationData,U32,(U32)[],null,U32,U32,string,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,(U32|null),Viewtype,(Viewtype|null),(Viewtype|null),(U32)[],null,U32,U32,U32,string,U32,U32,string,string,null,U32,U32,U32,string,U32,U32,WebxdcMessageInfo,U32,(U32)[],U32,null,U32,U32,null,U32,U32,(Message|null),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,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,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,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,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,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,(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,string,string,null,U32,U32,U32,string,U32,U32,WebxdcMessageInfo,U32,(U32)[],U32,null,U32,U32,null,U32,U32,(Message|null),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];