Skip to content

Commit a24e6d4

Browse files
authored
feat: sort apps by recently-updated (#6875)
closes #6873 , see there for reasoning. tested that on iOS already, works like a charm - and was much easier than expected as @iequidoo already updated `timestamp_rcvd` on status updates in #5388 ~~a test is missing, ordering is not tested at all, will check if that is doable reasonably easy~~ EDIT: added a test
1 parent 776b224 commit a24e6d4

File tree

2 files changed

+106
-26
lines changed

2 files changed

+106
-26
lines changed

src/chat.rs

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3534,37 +3534,62 @@ pub async fn get_chat_media(
35343534
msg_type2: Viewtype,
35353535
msg_type3: Viewtype,
35363536
) -> Result<Vec<MsgId>> {
3537-
// TODO This query could/should be converted to `AND type IN (?, ?, ?)`.
3538-
let list = context
3539-
.sql
3540-
.query_map(
3541-
"SELECT id
3537+
let list = if msg_type == Viewtype::Webxdc
3538+
&& msg_type2 == Viewtype::Unknown
3539+
&& msg_type3 == Viewtype::Unknown
3540+
{
3541+
context
3542+
.sql
3543+
.query_map(
3544+
"SELECT id
3545+
FROM msgs
3546+
WHERE (1=? OR chat_id=?)
3547+
AND chat_id != ?
3548+
AND type = ?
3549+
AND hidden=0
3550+
ORDER BY max(timestamp, timestamp_rcvd), id;",
3551+
(
3552+
chat_id.is_none(),
3553+
chat_id.unwrap_or_else(|| ChatId::new(0)),
3554+
DC_CHAT_ID_TRASH,
3555+
Viewtype::Webxdc,
3556+
),
3557+
|row| row.get::<_, MsgId>(0),
3558+
|ids| Ok(ids.flatten().collect()),
3559+
)
3560+
.await?
3561+
} else {
3562+
context
3563+
.sql
3564+
.query_map(
3565+
"SELECT id
35423566
FROM msgs
35433567
WHERE (1=? OR chat_id=?)
35443568
AND chat_id != ?
3545-
AND (type=? OR type=? OR type=?)
3569+
AND type IN (?, ?, ?)
35463570
AND hidden=0
35473571
ORDER BY timestamp, id;",
3548-
(
3549-
chat_id.is_none(),
3550-
chat_id.unwrap_or_else(|| ChatId::new(0)),
3551-
DC_CHAT_ID_TRASH,
3552-
msg_type,
3553-
if msg_type2 != Viewtype::Unknown {
3554-
msg_type2
3555-
} else {
3556-
msg_type
3557-
},
3558-
if msg_type3 != Viewtype::Unknown {
3559-
msg_type3
3560-
} else {
3561-
msg_type
3562-
},
3563-
),
3564-
|row| row.get::<_, MsgId>(0),
3565-
|ids| Ok(ids.flatten().collect()),
3566-
)
3567-
.await?;
3572+
(
3573+
chat_id.is_none(),
3574+
chat_id.unwrap_or_else(|| ChatId::new(0)),
3575+
DC_CHAT_ID_TRASH,
3576+
msg_type,
3577+
if msg_type2 != Viewtype::Unknown {
3578+
msg_type2
3579+
} else {
3580+
msg_type
3581+
},
3582+
if msg_type3 != Viewtype::Unknown {
3583+
msg_type3
3584+
} else {
3585+
msg_type
3586+
},
3587+
),
3588+
|row| row.get::<_, MsgId>(0),
3589+
|ids| Ok(ids.flatten().collect()),
3590+
)
3591+
.await?
3592+
};
35683593
Ok(list)
35693594
}
35703595

src/chat/chat_tests.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,6 +2924,61 @@ async fn test_get_chat_media() -> Result<()> {
29242924
Ok(())
29252925
}
29262926

2927+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
2928+
async fn test_get_chat_media_webxdc_order() -> Result<()> {
2929+
let mut tcm = TestContextManager::new();
2930+
let alice = tcm.alice().await;
2931+
let bob = tcm.bob().await;
2932+
let chat = alice.create_chat(&bob).await;
2933+
2934+
let mut instance1 = Message::new(Viewtype::Webxdc);
2935+
instance1.set_file_from_bytes(
2936+
&alice,
2937+
"test1.xdc",
2938+
include_bytes!("../../test-data/webxdc/minimal.xdc"),
2939+
None,
2940+
)?;
2941+
let instance1_id = send_msg(&alice, chat.id, &mut instance1).await?;
2942+
2943+
let mut instance2 = Message::new(Viewtype::Webxdc);
2944+
instance2.set_file_from_bytes(
2945+
&alice,
2946+
"test2.xdc",
2947+
include_bytes!("../../test-data/webxdc/minimal.xdc"),
2948+
None,
2949+
)?;
2950+
let instance2_id = send_msg(&alice, chat.id, &mut instance2).await?;
2951+
2952+
// list is ordered oldest to newest, check that
2953+
let media = get_chat_media(
2954+
&alice,
2955+
Some(chat.id),
2956+
Viewtype::Webxdc,
2957+
Viewtype::Unknown,
2958+
Viewtype::Unknown,
2959+
)
2960+
.await?;
2961+
assert_eq!(media.first().unwrap(), &instance1_id);
2962+
assert_eq!(media.get(1).unwrap(), &instance2_id);
2963+
2964+
// add a status update for the oder instance; that resorts the list
2965+
alice
2966+
.send_webxdc_status_update(instance1_id, r#"{"payload": {"foo": "bar"}}"#)
2967+
.await?;
2968+
let media = get_chat_media(
2969+
&alice,
2970+
Some(chat.id),
2971+
Viewtype::Webxdc,
2972+
Viewtype::Unknown,
2973+
Viewtype::Unknown,
2974+
)
2975+
.await?;
2976+
assert_eq!(media.first().unwrap(), &instance2_id);
2977+
assert_eq!(media.get(1).unwrap(), &instance1_id);
2978+
2979+
Ok(())
2980+
}
2981+
29272982
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
29282983
async fn test_blob_renaming() -> Result<()> {
29292984
let alice = TestContext::new_alice().await;

0 commit comments

Comments
 (0)