diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index f81eabdee..969e31700 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -861,6 +861,7 @@ void dc_maybe_network (dc_context_t* context); #define DC_GCL_ARCHIVED_ONLY 0x01 #define DC_GCL_NO_SPECIALS 0x02 #define DC_GCL_ADD_ALLDONE_HINT 0x04 +#define DC_GCL_ADD_DRAFTS 0x08 /** @@ -904,6 +905,12 @@ void dc_maybe_network (dc_context_t* context); * not needed when DC_GCL_ARCHIVED_ONLY is already set) * - if the flag DC_GCL_ADD_ALLDONE_HINT is set, DC_CHAT_ID_ALLDONE_HINT * is added as needed. + * - if the flag DC_GCL_ADD_DRAFTS is set + * and a chat has a recent draft, + * the draft is returned by dc_chatlist_get_msg_id(). + * if the chatlist is shown permanently eg. on desktop, + * you may not want to add this flags + * as the resorting on dc_set_draft() is easily confusing. * @param query_str An optional query for filtering the list. Only chats matching this query * are returned. Give NULL for no filtering. * @param query_id An optional contact ID for filtering the list. Only chats including this contact ID diff --git a/python/src/deltachat/const.py b/python/src/deltachat/const.py index f7d9d0b69..d06a0a283 100644 --- a/python/src/deltachat/const.py +++ b/python/src/deltachat/const.py @@ -11,6 +11,7 @@ from os.path import join as joinpath DC_GCL_ARCHIVED_ONLY = 0x01 DC_GCL_NO_SPECIALS = 0x02 DC_GCL_ADD_ALLDONE_HINT = 0x04 +DC_GCL_ADD_DRAFTS = 0x08 DC_GCL_VERIFIED_ONLY = 0x01 DC_GCL_ADD_SELF = 0x02 DC_QR_ASK_VERIFYCONTACT = 200 diff --git a/src/chatlist.rs b/src/chatlist.rs index 6af38353c..fc8e208b1 100644 --- a/src/chatlist.rs +++ b/src/chatlist.rs @@ -88,6 +88,16 @@ impl Chatlist { ) -> Result { let mut add_archived_link_item = false; + // drafts are hidden in the database. + // if add_drafts is set, this will be expanded to `hidden=1 AND state=DC_STATE_OUT_DRAFT`. + // otherwise, this results in `hidden=0 AND state=DC_STATE_OUT_DRAFT` in the sql statement + // and no additional messages will be regarded + let add_drafts = if 0 != listflags & DC_GCL_ADD_DRAFTS { + 1 + } else { + 0 + }; + // select with left join and minimum: // - the inner select must use `hidden` and _not_ `m.hidden` // which would refer the outer select and take a lot of time @@ -125,10 +135,10 @@ impl Chatlist { ON c.id=m.chat_id \ AND m.timestamp=( SELECT MAX(timestamp) \ FROM msgs WHERE chat_id=c.id \ - AND (hidden=0 OR (hidden=1 AND state=19))) WHERE c.id>9 \ + AND (hidden=0 OR (hidden=? AND state=19))) WHERE c.id>9 \ AND c.blocked=0 AND c.id IN(SELECT chat_id FROM chats_contacts WHERE contact_id=?) \ GROUP BY c.id ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;", - params![query_contact_id as i32], + params![add_drafts, query_contact_id as i32], process_row, process_rows, )? @@ -139,10 +149,10 @@ impl Chatlist { ON c.id=m.chat_id \ AND m.timestamp=( SELECT MAX(timestamp) \ FROM msgs WHERE chat_id=c.id \ - AND (hidden=0 OR (hidden=1 AND state=19))) WHERE c.id>9 \ + AND (hidden=0 OR (hidden=? AND state=19))) WHERE c.id>9 \ AND c.blocked=0 AND c.archived=1 GROUP BY c.id \ ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;", - params![], + params![add_drafts], process_row, process_rows, )? @@ -156,10 +166,10 @@ impl Chatlist { ON c.id=m.chat_id \ AND m.timestamp=( SELECT MAX(timestamp) \ FROM msgs WHERE chat_id=c.id \ - AND (hidden=0 OR (hidden=1 AND state=19))) WHERE c.id>9 \ + AND (hidden=0 OR (hidden=? AND state=19))) WHERE c.id>9 \ AND c.blocked=0 AND c.name LIKE ? \ GROUP BY c.id ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;", - params![str_like_cmd], + params![add_drafts, str_like_cmd], process_row, process_rows, )? @@ -171,11 +181,11 @@ impl Chatlist { ON c.id=m.chat_id \ AND m.timestamp=( SELECT MAX(timestamp) \ FROM msgs WHERE chat_id=c.id \ - AND (hidden=0 OR (hidden=1 AND state=19))) WHERE c.id>9 \ + AND (hidden=0 OR (hidden=? AND state=19))) WHERE c.id>9 \ AND c.blocked=0 AND c.archived=0 \ GROUP BY c.id \ ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;", - params![], + params![add_drafts], process_row, process_rows, )?; diff --git a/src/constants.rs b/src/constants.rs index fb1c486d7..79a546280 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -53,6 +53,7 @@ pub const DC_HANDSHAKE_ADD_DELETE_JOB: i32 = 0x04; pub const DC_GCL_ARCHIVED_ONLY: usize = 0x01; pub const DC_GCL_NO_SPECIALS: usize = 0x02; pub const DC_GCL_ADD_ALLDONE_HINT: usize = 0x04; +pub const DC_GCL_ADD_DRAFTS: usize = 0x08; const DC_GCM_ADDDAYMARKER: usize = 0x01; diff --git a/src/dc_tools.rs b/src/dc_tools.rs index 6cf4c11de..2d072d31b 100644 --- a/src/dc_tools.rs +++ b/src/dc_tools.rs @@ -1378,5 +1378,9 @@ mod tests { assert!(listflags_has(listflags, DC_GCL_ADD_SELF) == true); let listflags: u32 = DC_GCL_VERIFIED_ONLY.try_into().unwrap(); assert!(listflags_has(listflags, DC_GCL_ADD_SELF) == false); + + let listflags: u32 = DC_GCL_ADD_DRAFTS.try_into().unwrap(); + assert!(listflags_has(listflags, DC_GCL_ADD_ALLDONE_HINT) == false); + assert!(listflags_has(listflags, 0x8) == true); } }