From 0dc82ac353c9f77150a1ec472e4da6e5a3cb9eb5 Mon Sep 17 00:00:00 2001 From: link2xt Date: Wed, 2 Oct 2024 23:23:56 +0000 Subject: [PATCH] api!: remove deprecated get_next_media() APIs --- deltachat-ffi/deltachat.h | 24 --------------- deltachat-ffi/src/lib.rs | 42 ------------------------- deltachat-jsonrpc/src/api.rs | 49 ------------------------------ node/lib/context.ts | 41 ------------------------- node/src/module.c | 22 -------------- src/chat.rs | 59 ------------------------------------ 6 files changed, 237 deletions(-) diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index f5450dddd5..11951c8c04 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -1547,30 +1547,6 @@ void dc_marknoticed_chat (dc_context_t* context, uint32_t ch dc_array_t* dc_get_chat_media (dc_context_t* context, uint32_t chat_id, int msg_type, int msg_type2, int msg_type3); -/** - * 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. - * - * @deprecated Deprecated 2023-10-03, use dc_get_chat_media() and navigate the returned array instead. - * @memberof dc_context_t - * @param context The context object as returned from dc_context_new(). - * @param msg_id The ID of the current message from which the next or previous message should be searched. - * @param dir 1=get the next message, -1=get the previous one. - * @param msg_type The message type to search for. - * If 0, the message type from curr_msg_id is used. - * @param msg_type2 Alternative message type to search for. 0 to skip. - * @param msg_type3 Alternative message type to search for. 0 to skip. - * @return Returns the message ID that should be played next. - * The returned message is in the same chat as the given one - * and has one of the given types. - * Typically, this result is passed again to dc_get_next_media() - * later on the next swipe. - * If there is not next/previous message, the function returns 0. - */ -uint32_t dc_get_next_media (dc_context_t* context, uint32_t msg_id, int dir, int msg_type, int msg_type2, int msg_type3); - - /** * Set chat visibility to pinned, archived or normal. * diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 601718c072..2b3dab6374 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -1443,48 +1443,6 @@ pub unsafe extern "C" fn dc_get_chat_media( }) } -#[no_mangle] -#[allow(deprecated)] -pub unsafe extern "C" fn dc_get_next_media( - context: *mut dc_context_t, - msg_id: u32, - dir: libc::c_int, - msg_type: libc::c_int, - or_msg_type2: libc::c_int, - or_msg_type3: libc::c_int, -) -> u32 { - if context.is_null() { - eprintln!("ignoring careless call to dc_get_next_media()"); - return 0; - } - let direction = if dir < 0 { - chat::Direction::Backward - } else { - chat::Direction::Forward - }; - - let ctx = &*context; - let msg_type = from_prim(msg_type).expect(&format!("invalid msg_type = {msg_type}")); - let or_msg_type2 = - from_prim(or_msg_type2).expect(&format!("incorrect or_msg_type2 = {or_msg_type2}")); - let or_msg_type3 = - from_prim(or_msg_type3).expect(&format!("incorrect or_msg_type3 = {or_msg_type3}")); - - block_on(async move { - chat::get_next_media( - ctx, - MsgId::new(msg_id), - direction, - msg_type, - or_msg_type2, - or_msg_type3, - ) - .await - .map(|msg_id| msg_id.map(|id| id.to_u32()).unwrap_or_default()) - .unwrap_or(0) - }) -} - #[no_mangle] pub unsafe extern "C" fn dc_set_chat_visibility( context: *mut dc_context_t, diff --git a/deltachat-jsonrpc/src/api.rs b/deltachat-jsonrpc/src/api.rs index 6ce7e9da79..091689d153 100644 --- a/deltachat-jsonrpc/src/api.rs +++ b/deltachat-jsonrpc/src/api.rs @@ -1552,55 +1552,6 @@ 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 - /// - /// Deprecated 2023-10-03, use `get_chat_media` method - /// and navigate the returned array instead. - #[allow(deprecated)] - async fn get_neighboring_chat_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)) - } - // --------------------------------------------- // backup // --------------------------------------------- diff --git a/node/lib/context.ts b/node/lib/context.ts index b292e9e358..67055d8e5a 100644 --- a/node/lib/context.ts +++ b/node/lib/context.ts @@ -475,47 +475,6 @@ export class Context extends EventEmitter { return binding.dcn_get_msg_html(this.dcn_context, Number(messageId)) } - getNextMediaMessage( - messageId: number, - msgType1: number, - msgType2: number, - msgType3: number - ) { - debug( - `getNextMediaMessage ${messageId} ${msgType1} ${msgType2} ${msgType3}` - ) - return this._getNextMedia(messageId, 1, msgType1, msgType2, msgType3) - } - - getPreviousMediaMessage( - messageId: number, - msgType1: number, - msgType2: number, - msgType3: number - ) { - debug( - `getPreviousMediaMessage ${messageId} ${msgType1} ${msgType2} ${msgType3}` - ) - return this._getNextMedia(messageId, -1, msgType1, msgType2, msgType3) - } - - _getNextMedia( - messageId: number, - dir: number, - msgType1: number, - msgType2: number, - msgType3: number - ): number { - return binding.dcn_get_next_media( - this.dcn_context, - Number(messageId), - dir, - msgType1 || 0, - msgType2 || 0, - msgType3 || 0 - ) - } - getSecurejoinQrCode(chatId: number): string { debug(`getSecurejoinQrCode ${chatId}`) return binding.dcn_get_securejoin_qr(this.dcn_context, Number(chatId)) diff --git a/node/src/module.c b/node/src/module.c index 13e9feff91..33492aeecb 100644 --- a/node/src/module.c +++ b/node/src/module.c @@ -1053,27 +1053,6 @@ NAPI_METHOD(dcn_get_msg_html) { NAPI_RETURN_AND_UNREF_STRING(msg_html); } -NAPI_METHOD(dcn_get_next_media) { - NAPI_ARGV(6); - NAPI_DCN_CONTEXT(); - NAPI_ARGV_UINT32(msg_id, 1); - NAPI_ARGV_INT32(dir, 2); - NAPI_ARGV_INT32(msg_type1, 3); - NAPI_ARGV_INT32(msg_type2, 4); - NAPI_ARGV_INT32(msg_type3, 5); - - //TRACE("calling.."); - uint32_t next_id = dc_get_next_media(dcn_context->dc_context, - msg_id, - dir, - msg_type1, - msg_type2, - msg_type3); - //TRACE("result %d", next_id); - - NAPI_RETURN_UINT32(next_id); -} - NAPI_METHOD(dcn_set_chat_visibility) { NAPI_ARGV(3); NAPI_DCN_CONTEXT(); @@ -3443,7 +3422,6 @@ NAPI_INIT() { NAPI_EXPORT_FUNCTION(dcn_get_msg_cnt); NAPI_EXPORT_FUNCTION(dcn_get_msg_info); NAPI_EXPORT_FUNCTION(dcn_get_msg_html); - NAPI_EXPORT_FUNCTION(dcn_get_next_media); NAPI_EXPORT_FUNCTION(dcn_set_chat_visibility); NAPI_EXPORT_FUNCTION(dcn_get_securejoin_qr); NAPI_EXPORT_FUNCTION(dcn_get_securejoin_qr_svg); diff --git a/src/chat.rs b/src/chat.rs index a557df6e5b..01f4d2a135 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -3416,65 +3416,6 @@ pub async fn get_chat_media( Ok(list) } -/// Indicates the direction over which to iterate. -#[derive(Debug, Clone, PartialEq, Eq)] -#[repr(i32)] -pub enum Direction { - /// Search forward. - Forward = 1, - - /// Search backward. - Backward = -1, -} - -/// Searches next/previous message based on the given message and list of types. -/// -/// Deprecated since 2023-10-03. -#[deprecated(note = "use `get_chat_media` instead")] -pub async fn get_next_media( - context: &Context, - curr_msg_id: MsgId, - direction: Direction, - msg_type: Viewtype, - msg_type2: Viewtype, - msg_type3: Viewtype, -) -> Result> { - let mut ret: Option = None; - - if let Ok(msg) = Message::load_from_db(context, curr_msg_id).await { - let list: Vec = get_chat_media( - context, - Some(msg.chat_id), - if msg_type != Viewtype::Unknown { - msg_type - } else { - msg.viewtype - }, - msg_type2, - msg_type3, - ) - .await?; - for (i, msg_id) in list.iter().enumerate() { - if curr_msg_id == *msg_id { - match direction { - Direction::Forward => { - if i + 1 < list.len() { - ret = list.get(i + 1).copied(); - } - } - Direction::Backward => { - if i >= 1 { - ret = list.get(i - 1).copied(); - } - } - } - break; - } - } - } - Ok(ret) -} - /// Returns a vector of contact IDs for given chat ID. pub async fn get_chat_contacts(context: &Context, chat_id: ChatId) -> Result> { // Normal chats do not include SELF. Group chats do (as it may happen that one is deleted from a