Compare commits

...

2 Commits

Author SHA1 Message Date
B. Petersen
6c7962690f drafts are added to chatlist only on explicit request 2019-10-20 23:38:22 +02:00
B. Petersen
5fd691e01b use boolean for add_archived_link_item 2019-10-20 18:03:19 +02:00
5 changed files with 34 additions and 11 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -86,7 +86,17 @@ impl Chatlist {
query: Option<&str>,
query_contact_id: Option<u32>,
) -> Result<Self> {
let mut add_archived_link_item = 0;
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`
@@ -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,
)?;
@@ -184,12 +194,12 @@ impl Chatlist {
if last_deaddrop_fresh_msg_id > 0 {
ids.insert(0, (DC_CHAT_ID_DEADDROP, last_deaddrop_fresh_msg_id));
}
add_archived_link_item = 1;
add_archived_link_item = true;
}
ids
};
if 0 != add_archived_link_item && dc_get_archived_cnt(context) > 0 {
if add_archived_link_item && dc_get_archived_cnt(context) > 0 {
if ids.is_empty() && 0 != listflags & DC_GCL_ADD_ALLDONE_HINT {
ids.push((DC_CHAT_ID_ALLDONE_HINT, 0));
}

View File

@@ -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;

View File

@@ -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);
}
}