From c5d18023463460316395fdb68a910cd5b31cc1d8 Mon Sep 17 00:00:00 2001 From: bjoern Date: Thu, 5 Jan 2023 10:31:47 +0100 Subject: [PATCH] "archive" consistency and improvements (#3918) * move 'archived link' betweeen pinned and normal cahts or above normal chats * add icon for 'archived chats' link * let get_fresh_msg_cnt() work for DC_CHAT_ID_ARCHIVED_LINK * move 'archived link' topmost * use less noticeable archived-icon * slightly smaller archived icon * update CHANGELOG --- CHANGELOG.md | 2 ++ assets/icon-archive.png | Bin 0 -> 1652 bytes assets/icon-archive.svg | 60 ++++++++++++++++++++++++++++++++++++++ deltachat-ffi/deltachat.h | 6 +++- src/chat.rs | 51 +++++++++++++++++++++++++++----- src/chatlist.rs | 20 +++++-------- 6 files changed, 118 insertions(+), 21 deletions(-) create mode 100644 assets/icon-archive.png create mode 100644 assets/icon-archive.svg diff --git a/CHANGELOG.md b/CHANGELOG.md index 323cfac6a..1ea187ef2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ - Add fuzzing tests #3853 - Add mappings for some file types to Viewtype / MIME type #3881 - Buffer IMAP client writes #3888 +- move `DC_CHAT_ID_ARCHIVED_LINK` to the top of chat lists + and make `dc_get_fresh_msg_cnt()` work for `DC_CHAT_ID_ARCHIVED_LINK` #3918 ### API-Changes - jsonrpc: add python API for webxdc updates #3872 diff --git a/assets/icon-archive.png b/assets/icon-archive.png new file mode 100644 index 0000000000000000000000000000000000000000..95d35e2a5107e14ee900d0b7947b2eb9a38e6a85 GIT binary patch literal 1652 zcmd^ATTI$_6#ikYc*lf9ywywG>Pu%?Y;CKExLGC(>n@h9#T$y^EKHo(YAY(MHFIez zOu~pNxLod^s zvwSgIq9bF_%>Jbz68a|by7K3QiqpfSq$_ueiSe`Fyc-t-pNl$ruwv#er;|rOAaAem zT9olDSg+*dm&UM?Ml`J>!(Te_s6#<1usqHV@2+5L%kxZf9$6+ug0VypMh5W$K)@n+ zG#{Y!1(ySWFBJYf+o5HpI@jjJA9zx2@y=hvX-M(h#wqFaWDo2R8c!X|>Lr0C;?-A3(cn9ul7IZ09IOhH6=T}%l zV!zfbI8w?V?v}wPx?r=}+-`6hrR#z~M1-chBe`Iw6i(=34doBdmlFp5)2ZAM9}?tt zZO7!A8iJ_IOdTtAoyvUMX2@hoTpZY8Bbi(+ngyBMu4c&Q^#-TXwuKoNe)OgZo<62611wKQ842J5wsXpzW($r{M;VFWLe<)XcDs1P zJM~Hqo2_j{z68?K>TR$J8m3T0{EQ%v^&&;T&=ZnwR%gY{lt{OWDX#4izTMEYNUgUB z;u?k^JYK4_E%Koa`5hrFUp^;sZF+E4lY{G4O@-hy9B!&9X*Nouk5zI93VZonMZax=i}#3_4}X#E|2Lf<^LgvH5~-kH)A*>qNdgHY zpY++OOtHb4XK^fbbI7fLtd6^6Vh1-&8=PW_)dKCzO^-8h0|0$5KeZCs|Wh z2;+}mO#oNkx-+&Dz3UMvE?WLt)p2lbnrGHWboC7)h?S2Zkx054 zP|AY9?|YdrYTnW9BMX@6SVV;3Q#uM;++!T|rPU3JH{80{$jHc|?7g?WCnmj)$i0asOjd;z5uQ8K@SaufNoUd8ti3fdUJcqYPtKO^YH3!Z;Q at}{@Dw+Qr~*o5AX0Z1oLW%s;ByZkq}L1Whd literal 0 HcmV?d00001 diff --git a/assets/icon-archive.svg b/assets/icon-archive.svg new file mode 100644 index 000000000..a8ba45d49 --- /dev/null +++ b/assets/icon-archive.svg @@ -0,0 +1,60 @@ + + + + + + + + + + diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index 4a03f1a8f..47452f6ac 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -1227,7 +1227,11 @@ int dc_get_msg_cnt (dc_context_t* context, uint32_t ch * Get the number of _fresh_ messages in a chat. * Typically used to implement a badge with a number in the chatlist. * - * If the specified chat is muted, + * As muted archived chats are not unarchived automatically, + * a similar information is needed for the @ref dc_get_chatlist() "archive link" as well: + * here, the number of archived chats containing fresh messages is returned. + * + * If the specified chat is muted or the @ref dc_get_chatlist() "archive link", * the UI should show the badge counter "less obtrusive", * e.g. using "gray" instead of "red" color. * diff --git a/src/chat.rs b/src/chat.rs index 8be73e1ef..4de92e070 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -782,17 +782,35 @@ impl ChatId { // the times are average, no matter if there are fresh messages or not - // and have to be multiplied by the number of items shown at once on the chatlist, // so savings up to 2 seconds are possible on older devices - newer ones will feel "snappier" :) - let count = context - .sql - .count( - "SELECT COUNT(*) + let count = if self.is_archived_link() { + context + .sql + .count( + "SELECT COUNT(DISTINCT(m.chat_id)) + FROM msgs m + LEFT JOIN chats c ON m.chat_id=c.id + WHERE m.state=10 + and m.hidden=0 + AND m.chat_id>9 + AND c.blocked=0 + AND c.archived=1 + ", + paramsv![], + ) + .await? + } else { + context + .sql + .count( + "SELECT COUNT(*) FROM msgs WHERE state=? AND hidden=0 AND chat_id=?;", - paramsv![MessageState::InFresh, self], - ) - .await?; + paramsv![MessageState::InFresh, self], + ) + .await? + }; Ok(count) } @@ -1216,6 +1234,10 @@ impl Chat { if !image_rel.is_empty() { return Ok(Some(get_abs_path(context, image_rel))); } + } else if self.id.is_archived_link() { + if let Ok(image_rel) = get_archive_icon(context).await { + return Ok(Some(get_abs_path(context, image_rel))); + } } else if self.typ == Chattype::Single { let contacts = get_chat_contacts(context, self.id).await?; if let Some(contact_id) = contacts.first() { @@ -1708,6 +1730,21 @@ pub(crate) async fn get_broadcast_icon(context: &Context) -> Result { Ok(icon) } +pub(crate) async fn get_archive_icon(context: &Context) -> Result { + if let Some(icon) = context.sql.get_raw_config("icon-archive").await? { + return Ok(icon); + } + + let icon = include_bytes!("../assets/icon-archive.png"); + let blob = BlobObject::create(context, "icon-archive.png", icon).await?; + let icon = blob.as_name().to_string(); + context + .sql + .set_raw_config("icon-archive", Some(&icon)) + .await?; + Ok(icon) +} + async fn update_special_chat_name( context: &Context, contact_id: ContactId, diff --git a/src/chatlist.rs b/src/chatlist.rs index da7d309a4..df80b15e2 100644 --- a/src/chatlist.rs +++ b/src/chatlist.rs @@ -92,8 +92,6 @@ impl Chatlist { let flag_no_specials = 0 != listflags & DC_GCL_NO_SPECIALS; let flag_add_alldone_hint = 0 != listflags & DC_GCL_ADD_ALLDONE_HINT; - let mut add_archived_link_item = false; - let process_row = |row: &rusqlite::Row| { let chat_id: ChatId = row.get(0)?; let msg_id: Option = row.get(1)?; @@ -123,7 +121,7 @@ impl Chatlist { // // The query shows messages from blocked contacts in // groups. Otherwise it would be hard to follow conversations. - let mut ids = if let Some(query_contact_id) = query_contact_id { + let ids = if let Some(query_contact_id) = query_contact_id { // show chats shared with a given contact context.sql.query_map( "SELECT c.id, m.id @@ -216,7 +214,7 @@ impl Chatlist { } else { ChatId::new(0) }; - let ids = context.sql.query_map( + let mut ids = context.sql.query_map( "SELECT c.id, m.id FROM chats c LEFT JOIN msgs m @@ -236,19 +234,15 @@ impl Chatlist { process_row, process_rows, ).await?; - if !flag_no_specials { - add_archived_link_item = true; + if !flag_no_specials && get_archived_cnt(context).await? > 0 { + if ids.is_empty() && flag_add_alldone_hint { + ids.push((DC_CHAT_ID_ALLDONE_HINT, None)); + } + ids.insert(0, (DC_CHAT_ID_ARCHIVED_LINK, None)); } ids }; - if add_archived_link_item && get_archived_cnt(context).await? > 0 { - if ids.is_empty() && flag_add_alldone_hint { - ids.push((DC_CHAT_ID_ALLDONE_HINT, None)); - } - ids.push((DC_CHAT_ID_ARCHIVED_LINK, None)); - } - Ok(Chatlist { ids }) }