Merge pull request #911 from deltachat/draft-sorting

sort newly created chats atop of chatlist
This commit is contained in:
björn petersen
2019-11-29 15:11:06 +01:00
committed by GitHub
4 changed files with 71 additions and 68 deletions

View File

@@ -637,7 +637,7 @@ pub fn create_or_lookup_by_contact_id(
context, context,
&context.sql, &context.sql,
format!( format!(
"INSERT INTO chats (type, name, param, blocked, grpid) VALUES({}, '{}', '{}', {}, '{}')", "INSERT INTO chats (type, name, param, blocked, grpid, created_timestamp) VALUES({}, '{}', '{}', {}, '{}', {})",
100, 100,
chat_name, chat_name,
match contact_id { match contact_id {
@@ -650,6 +650,7 @@ pub fn create_or_lookup_by_contact_id(
}, },
create_blocked as u8, create_blocked as u8,
contact.get_addr(), contact.get_addr(),
time(),
), ),
params![], params![],
)?; )?;
@@ -1388,7 +1389,7 @@ pub fn create_group_chat(
sql::execute( sql::execute(
context, context,
&context.sql, &context.sql,
"INSERT INTO chats (type, name, grpid, param) VALUES(?, ?, ?, \'U=1\');", "INSERT INTO chats (type, name, grpid, param, created_timestamp) VALUES(?, ?, ?, \'U=1\', ?);",
params![ params![
if verified != VerifiedStatus::Unverified { if verified != VerifiedStatus::Unverified {
Chattype::VerifiedGroup Chattype::VerifiedGroup
@@ -1396,7 +1397,8 @@ pub fn create_group_chat(
Chattype::Group Chattype::Group
}, },
chat_name.as_ref(), chat_name.as_ref(),
grpid grpid,
time(),
], ],
)?; )?;

View File

@@ -119,22 +119,20 @@ impl Chatlist {
let mut ids = if let Some(query_contact_id) = query_contact_id { let mut ids = if let Some(query_contact_id) = query_contact_id {
// show chats shared with a given contact // show chats shared with a given contact
context.sql.query_map( context.sql.query_map(
concat!( "SELECT c.id, m.id
"SELECT c.id, m.id", FROM chats c
" FROM chats c", LEFT JOIN msgs m
" LEFT JOIN msgs m", ON c.id=m.chat_id
" ON c.id=m.chat_id", AND m.timestamp=(
" AND m.timestamp=(", SELECT MAX(timestamp)
" SELECT MAX(timestamp)", FROM msgs
" FROM msgs", WHERE chat_id=c.id
" WHERE chat_id=c.id", AND hidden=0)
" AND hidden=0)", WHERE c.id>9
" WHERE c.id>9", AND c.blocked=0
" AND c.blocked=0", AND c.id IN(SELECT chat_id FROM chats_contacts WHERE contact_id=?)
" AND c.id IN(SELECT chat_id FROM chats_contacts WHERE contact_id=?)", GROUP BY c.id
" GROUP BY c.id", ORDER BY IFNULL(m.timestamp,c.created_timestamp) DESC, m.id DESC;",
" ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;"
),
params![query_contact_id as i32], params![query_contact_id as i32],
process_row, process_row,
process_rows, process_rows,
@@ -142,22 +140,20 @@ impl Chatlist {
} else if 0 != listflags & DC_GCL_ARCHIVED_ONLY { } else if 0 != listflags & DC_GCL_ARCHIVED_ONLY {
// show archived chats // show archived chats
context.sql.query_map( context.sql.query_map(
concat!( "SELECT c.id, m.id
"SELECT c.id, m.id", FROM chats c
" FROM chats c", LEFT JOIN msgs m
" LEFT JOIN msgs m", ON c.id=m.chat_id
" ON c.id=m.chat_id", AND m.timestamp=(
" AND m.timestamp=(", SELECT MAX(timestamp)
" SELECT MAX(timestamp)", FROM msgs
" FROM msgs", WHERE chat_id=c.id
" WHERE chat_id=c.id", AND hidden=0)
" AND hidden=0)", WHERE c.id>9
" WHERE c.id>9", AND c.blocked=0
" AND c.blocked=0", AND c.archived=1
" AND c.archived=1", GROUP BY c.id
" GROUP BY c.id", ORDER BY IFNULL(m.timestamp,c.created_timestamp) DESC, m.id DESC;",
" ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;"
),
params![], params![],
process_row, process_row,
process_rows, process_rows,
@@ -168,22 +164,20 @@ impl Chatlist {
let str_like_cmd = format!("%{}%", query); let str_like_cmd = format!("%{}%", query);
context.sql.query_map( context.sql.query_map(
concat!( "SELECT c.id, m.id
"SELECT c.id, m.id", FROM chats c
" FROM chats c", LEFT JOIN msgs m
" LEFT JOIN msgs m", ON c.id=m.chat_id
" ON c.id=m.chat_id", AND m.timestamp=(
" AND m.timestamp=(", SELECT MAX(timestamp)
" SELECT MAX(timestamp)", FROM msgs
" FROM msgs", WHERE chat_id=c.id
" WHERE chat_id=c.id", AND hidden=0)
" AND hidden=0)", WHERE c.id>9
" WHERE c.id>9", AND c.blocked=0
" AND c.blocked=0", AND c.name LIKE ?
" AND c.name LIKE ?", GROUP BY c.id
" GROUP BY c.id", ORDER BY IFNULL(m.timestamp,c.created_timestamp) DESC, m.id DESC;",
" ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;"
),
params![str_like_cmd], params![str_like_cmd],
process_row, process_row,
process_rows, process_rows,
@@ -191,22 +185,20 @@ impl Chatlist {
} else { } else {
// show normal chatlist // show normal chatlist
let mut ids = context.sql.query_map( let mut ids = context.sql.query_map(
concat!( "SELECT c.id, m.id
"SELECT c.id, m.id", FROM chats c
" FROM chats c", LEFT JOIN msgs m
" LEFT JOIN msgs m", ON c.id=m.chat_id
" ON c.id=m.chat_id", AND m.timestamp=(
" AND m.timestamp=(", SELECT MAX(timestamp)
" SELECT MAX(timestamp)", FROM msgs
" FROM msgs", WHERE chat_id=c.id
" WHERE chat_id=c.id", AND hidden=0)
" AND hidden=0)", WHERE c.id>9
" WHERE c.id>9", AND c.blocked=0
" AND c.blocked=0", AND c.archived=0
" AND c.archived=0", GROUP BY c.id
" GROUP BY c.id", ORDER BY IFNULL(m.timestamp,c.created_timestamp) DESC, m.id DESC;",
" ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;"
),
params![], params![],
process_row, process_row,
process_rows, process_rows,

View File

@@ -1439,7 +1439,7 @@ fn create_group_record(
if sql::execute( if sql::execute(
context, context,
&context.sql, &context.sql,
"INSERT INTO chats (type, name, grpid, blocked) VALUES(?, ?, ?, ?);", "INSERT INTO chats (type, name, grpid, blocked, created_timestamp) VALUES(?, ?, ?, ?, ?);",
params![ params![
if VerifiedStatus::Unverified != create_verified { if VerifiedStatus::Unverified != create_verified {
Chattype::VerifiedGroup Chattype::VerifiedGroup
@@ -1449,6 +1449,7 @@ fn create_group_record(
grpname.as_ref(), grpname.as_ref(),
grpid.as_ref(), grpid.as_ref(),
create_blocked, create_blocked,
time(),
], ],
) )
.is_err() .is_err()

View File

@@ -829,6 +829,14 @@ fn open(
update_icons = true; update_icons = true;
sql.set_raw_config_int(context, "dbversion", 59)?; sql.set_raw_config_int(context, "dbversion", 59)?;
} }
if dbversion < 60 {
info!(context, "[migration] v60");
sql.execute(
"ALTER TABLE chats ADD COLUMN created_timestamp INTEGER DEFAULT 0;",
NO_PARAMS,
)?;
sql.set_raw_config_int(context, "dbversion", 60)?;
}
// (2) updates that require high-level objects // (2) updates that require high-level objects
// (the structure is complete now and all objects are usable) // (the structure is complete now and all objects are usable)