From cb2a1147f016df6188cd301a95f9d11859e7376c Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 26 Dec 2019 11:55:37 +0100 Subject: [PATCH] fix searching for localized device chats --- src/chat.rs | 22 ++++++++++++++++++++++ src/chatlist.rs | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/src/chat.rs b/src/chat.rs index 6ce2da0fc..73b0a7a56 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -720,6 +720,28 @@ pub fn update_device_icon(context: &Context) -> Result<(), Error> { Ok(()) } +fn update_special_chat_name( + context: &Context, + contact_id: u32, + stock_id: StockMessage, +) -> Result<(), Error> { + if let Ok((chat_id, _)) = lookup_by_contact_id(context, contact_id) { + let name: String = context.stock_str(stock_id).into(); + // the `!= name` condition avoids unneeded writes + context.sql.execute( + "UPDATE chats SET name=? WHERE id=? AND name!=?;", + params![name, chat_id, name], + )?; + } + Ok(()) +} + +pub fn update_special_chat_names(context: &Context) -> Result<(), Error> { + update_special_chat_name(context, DC_CONTACT_ID_DEVICE, StockMessage::DeviceMessages)?; + update_special_chat_name(context, DC_CONTACT_ID_SELF, StockMessage::SavedMessages)?; + Ok(()) +} + pub fn create_or_lookup_by_contact_id( context: &Context, contact_id: u32, diff --git a/src/chatlist.rs b/src/chatlist.rs index 28789b931..3efadd888 100644 --- a/src/chatlist.rs +++ b/src/chatlist.rs @@ -162,6 +162,10 @@ impl Chatlist { let query = query.trim().to_string(); ensure!(!query.is_empty(), "missing query"); + // allow searching over special names that may change at any time + // when the ui calls set_stock_translation() + update_special_chat_names(context)?; + let str_like_cmd = format!("%{}%", query); context.sql.query_map( "SELECT c.id, m.id