globally search for media (#3528)

* get_chat_media() from any chat similar to search_msgs()

* do not return hidden media

this fixes the issue that drafts
and other hidden messages pop up in the gallery.

* add a test for get_chat_media()

* use None instead of ChatId::new(0)

* clarify scope of 'any' in get_chat_media()

* adapt json rpc to changed get_chat_media()

* jsonrpc: chat_get_media turn chat_id into option
and also still allow `0` for dev convenience
(though I'm not totally sure if thats the right decision)

* cargo fmt

Co-authored-by: Simon Laux <mobile.info@simonlaux.de>
This commit is contained in:
bjoern
2022-08-18 10:27:36 +02:00
committed by GitHub
parent d297aa70bf
commit fdf91b772e
8 changed files with 188 additions and 31 deletions

View File

@@ -577,28 +577,28 @@ impl CommandApi {
/// The list is already sorted and starts with the oldest message.
/// Clients should not try to re-sort the list as this would be an expensive action
/// and would result in inconsistencies between clients.
///
/// Setting `chat_id` to `None` (`null` in typescript) means get messages with media
/// from any chat of the currently used account.
async fn chat_get_media(
&self,
account_id: u32,
chat_id: u32,
chat_id: Option<u32>,
message_type: MessageViewtype,
or_message_type2: Option<MessageViewtype>,
or_message_type3: Option<MessageViewtype>,
) -> Result<Vec<u32>> {
let ctx = self.get_context(account_id).await?;
let chat_id = match chat_id {
None | Some(0) => None,
Some(id) => Some(ChatId::new(id)),
};
let msg_type = message_type.into();
let or_msg_type2 = or_message_type2.map_or(Viewtype::Unknown, |v| v.into());
let or_msg_type3 = or_message_type3.map_or(Viewtype::Unknown, |v| v.into());
let media = get_chat_media(
&ctx,
ChatId::new(chat_id),
msg_type,
or_msg_type2,
or_msg_type3,
)
.await?;
let media = get_chat_media(&ctx, chat_id, msg_type, or_msg_type2, or_msg_type3).await?;
Ok(media.iter().map(|msg_id| msg_id.to_u32()).collect())
}