Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion deltachat-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1532,6 +1532,7 @@ pub unsafe extern "C" fn dc_get_chat_media(
msg_type: libc::c_int,
or_msg_type2: libc::c_int,
or_msg_type3: libc::c_int,
// limit: u32,
) -> *mut dc_array::dc_array_t {
if context.is_null() {
eprintln!("ignoring careless call to dc_get_chat_media()");
Expand All @@ -1551,7 +1552,7 @@ pub unsafe extern "C" fn dc_get_chat_media(

block_on(async move {
Box::into_raw(Box::new(
chat::get_chat_media(ctx, chat_id, msg_type, or_msg_type2, or_msg_type3)
chat::get_chat_media(ctx, chat_id, msg_type, or_msg_type2, or_msg_type3, None)
.await
.unwrap_or_log_default(ctx, "Failed get_chat_media")
.into(),
Expand Down
4 changes: 3 additions & 1 deletion deltachat-jsonrpc/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,7 @@ impl CommandApi {
message_type: MessageViewtype,
or_message_type2: Option<MessageViewtype>,
or_message_type3: Option<MessageViewtype>,
limit: Option<u32>,
) -> Result<Vec<u32>> {
let ctx = self.get_context(account_id).await?;

Expand All @@ -1745,7 +1746,8 @@ impl CommandApi {
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, 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, limit).await?;
Ok(media.iter().map(|msg_id| msg_id.to_u32()).collect())
}

Expand Down
1 change: 1 addition & 0 deletions deltachat-repl/src/cmdline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
Viewtype::Image,
Viewtype::Gif,
Viewtype::Video,
None,
)
.await?;
println!("{} images or videos: ", images.len());
Expand Down
9 changes: 7 additions & 2 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3292,6 +3292,7 @@ pub async fn get_chat_media(
msg_type: Viewtype,
msg_type2: Viewtype,
msg_type3: Viewtype,
limit: Option<u32>,
) -> Result<Vec<MsgId>> {
let list = if msg_type == Viewtype::Webxdc
&& msg_type2 == Viewtype::Unknown
Expand All @@ -3306,12 +3307,14 @@ pub async fn get_chat_media(
AND chat_id != ?
AND type = ?
AND hidden=0
ORDER BY max(timestamp, timestamp_rcvd), id;",
ORDER BY max(timestamp, timestamp_rcvd), id
LIMIT ?;",
(
chat_id.is_none(),
chat_id.unwrap_or_else(|| ChatId::new(0)),
DC_CHAT_ID_TRASH,
Viewtype::Webxdc,
limit.map(|l| l.to_string()).unwrap_or("ALL".to_string()),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SQLite doesn't support ALL. Looks like we need to omit the parameter somehow. Maybe using format!

),
|row| row.get::<_, MsgId>(0),
|ids| Ok(ids.flatten().collect()),
Expand All @@ -3327,7 +3330,8 @@ pub async fn get_chat_media(
AND chat_id != ?
AND type IN (?, ?, ?)
AND hidden=0
ORDER BY timestamp, id;",
ORDER BY timestamp, id
LIMIT ?;",
(
chat_id.is_none(),
chat_id.unwrap_or_else(|| ChatId::new(0)),
Expand All @@ -3343,6 +3347,7 @@ pub async fn get_chat_media(
} else {
msg_type
},
limit.map(|l| l.to_string()).unwrap_or("ALL".to_string()),
),
|row| row.get::<_, MsgId>(0),
|ids| Ok(ids.flatten().collect()),
Expand Down
52 changes: 51 additions & 1 deletion src/chat/chat_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3189,7 +3189,8 @@ async fn test_get_chat_media() -> Result<()> {
Some(chat_id1),
Viewtype::Image,
Viewtype::Sticker,
Viewtype::Unknown
Viewtype::Unknown,
None,
)
.await?
.len(),
Expand Down Expand Up @@ -3250,6 +3251,7 @@ async fn test_get_chat_media() -> Result<()> {
Viewtype::Image,
Viewtype::Unknown,
Viewtype::Unknown,
None,
)
.await?
.len(),
Expand All @@ -3262,6 +3264,7 @@ async fn test_get_chat_media() -> Result<()> {
Viewtype::Sticker,
Viewtype::Unknown,
Viewtype::Unknown,
None,
)
.await?
.len(),
Expand All @@ -3274,18 +3277,33 @@ async fn test_get_chat_media() -> Result<()> {
Viewtype::Sticker,
Viewtype::Image,
Viewtype::Unknown,
None,
)
.await?
.len(),
2
);
assert_eq!(
get_chat_media(
&t,
Some(chat_id1),
Viewtype::Sticker,
Viewtype::Image,
Viewtype::Unknown,
Some(1),
)
.await?
.len(),
1
);
assert_eq!(
get_chat_media(
&t,
Some(chat_id2),
Viewtype::Webxdc,
Viewtype::Unknown,
Viewtype::Unknown,
None,
)
.await?
.len(),
Expand All @@ -3298,6 +3316,7 @@ async fn test_get_chat_media() -> Result<()> {
Viewtype::Image,
Viewtype::Unknown,
Viewtype::Unknown,
None,
)
.await?
.len(),
Expand All @@ -3310,6 +3329,33 @@ async fn test_get_chat_media() -> Result<()> {
Viewtype::Image,
Viewtype::Sticker,
Viewtype::Unknown,
None,
)
.await?
.len(),
3
);
assert_eq!(
get_chat_media(
&t,
None,
Viewtype::Image,
Viewtype::Sticker,
Viewtype::Webxdc,
None,
)
.await?
.len(),
4
);
assert_eq!(
get_chat_media(
&t,
None,
Viewtype::Image,
Viewtype::Sticker,
Viewtype::Webxdc,
Some(3),
)
.await?
.len(),
Expand All @@ -3322,6 +3368,7 @@ async fn test_get_chat_media() -> Result<()> {
Viewtype::Image,
Viewtype::Sticker,
Viewtype::Webxdc,
Some(99),
)
.await?
.len(),
Expand All @@ -3337,6 +3384,7 @@ async fn test_get_chat_media() -> Result<()> {
Viewtype::Image,
Viewtype::Sticker,
Viewtype::Webxdc,
None,
)
.await?
.len(),
Expand Down Expand Up @@ -3378,6 +3426,7 @@ async fn test_get_chat_media_webxdc_order() -> Result<()> {
Viewtype::Webxdc,
Viewtype::Unknown,
Viewtype::Unknown,
None,
)
.await?;
assert_eq!(media.first().unwrap(), &instance1_id);
Expand All @@ -3393,6 +3442,7 @@ async fn test_get_chat_media_webxdc_order() -> Result<()> {
Viewtype::Webxdc,
Viewtype::Unknown,
Viewtype::Unknown,
None,
)
.await?;
assert_eq!(media.first().unwrap(), &instance2_id);
Expand Down
Loading