set correct icon for DC_CONTACT_ID_DEVICE

This commit is contained in:
B. Petersen
2019-12-06 21:46:31 +01:00
committed by holger krekel
parent 36edf447e7
commit 021ad4f12c
2 changed files with 24 additions and 12 deletions

View File

@@ -593,12 +593,6 @@ pub fn set_blocking(context: &Context, chat_id: u32, new_blocking: Blocked) -> b
.is_ok() .is_ok()
} }
fn copy_device_icon_to_blobs(context: &Context) -> Result<String, Error> {
let icon = include_bytes!("../assets/icon-device.png");
let blob = BlobObject::create(context, "icon-device.png".to_string(), icon)?;
Ok(blob.as_name().to_string())
}
pub fn update_saved_messages_icon(context: &Context) -> Result<(), Error> { pub fn update_saved_messages_icon(context: &Context) -> Result<(), Error> {
// if there is no saved-messages chat, there is nothing to update. this is no error. // if there is no saved-messages chat, there is nothing to update. this is no error.
if let Ok((chat_id, _)) = lookup_by_contact_id(context, DC_CONTACT_ID_SELF) { if let Ok((chat_id, _)) = lookup_by_contact_id(context, DC_CONTACT_ID_SELF) {
@@ -613,6 +607,24 @@ pub fn update_saved_messages_icon(context: &Context) -> Result<(), Error> {
Ok(()) Ok(())
} }
pub fn update_device_icon(context: &Context) -> Result<(), Error> {
// if there is no device-chat, there is nothing to update. this is no error.
if let Ok((chat_id, _)) = lookup_by_contact_id(context, DC_CONTACT_ID_DEVICE) {
let icon = include_bytes!("../assets/icon-device.png");
let blob = BlobObject::create(context, "icon-device.png".to_string(), icon)?;
let icon = blob.as_name().to_string();
let mut chat = Chat::load_from_db(context, chat_id)?;
chat.param.set(Param::ProfileImage, &icon);
chat.update_param(context)?;
let mut contact = Contact::load_from_db(context, DC_CONTACT_ID_DEVICE)?;
contact.param.set(Param::ProfileImage, icon);
contact.update_param(context)?;
}
Ok(())
}
pub fn create_or_lookup_by_contact_id( pub fn create_or_lookup_by_contact_id(
context: &Context, context: &Context,
contact_id: u32, contact_id: u32,
@@ -638,10 +650,7 @@ pub fn create_or_lookup_by_contact_id(
chat_name, chat_name,
match contact_id { match contact_id {
DC_CONTACT_ID_SELF => "K=1".to_string(), // K = Param::Selftalk DC_CONTACT_ID_SELF => "K=1".to_string(), // K = Param::Selftalk
DC_CONTACT_ID_DEVICE => { DC_CONTACT_ID_DEVICE => "D=1".to_string(), // D = Param::Devicetalk
let icon = copy_device_icon_to_blobs(context)?;
format!("D=1\ni={}", icon) // D = Param::Devicetalk, i = Param::ProfileImage
},
_ => "".to_string() _ => "".to_string()
}, },
create_blocked as u8, create_blocked as u8,
@@ -665,6 +674,8 @@ pub fn create_or_lookup_by_contact_id(
if contact_id == DC_CONTACT_ID_SELF { if contact_id == DC_CONTACT_ID_SELF {
update_saved_messages_icon(context)?; update_saved_messages_icon(context)?;
} else if contact_id == DC_CONTACT_ID_DEVICE {
update_device_icon(context)?;
} }
Ok((chat_id, create_blocked)) Ok((chat_id, create_blocked))

View File

@@ -7,7 +7,7 @@ use std::time::Duration;
use rusqlite::{Connection, OpenFlags, Statement, NO_PARAMS}; use rusqlite::{Connection, OpenFlags, Statement, NO_PARAMS};
use thread_local_object::ThreadLocal; use thread_local_object::ThreadLocal;
use crate::chat::update_saved_messages_icon; use crate::chat::{update_device_icon, update_saved_messages_icon};
use crate::constants::ShowEmails; use crate::constants::ShowEmails;
use crate::context::Context; use crate::context::Context;
use crate::dc_tools::*; use crate::dc_tools::*;
@@ -848,7 +848,6 @@ fn open(
if exists_before_update && sql.get_raw_config_int(context, "bcc_self").is_none() { if exists_before_update && sql.get_raw_config_int(context, "bcc_self").is_none() {
sql.set_raw_config_int(context, "bcc_self", 1)?; sql.set_raw_config_int(context, "bcc_self", 1)?;
} }
update_icons = true;
sql.set_raw_config_int(context, "dbversion", 59)?; sql.set_raw_config_int(context, "dbversion", 59)?;
} }
if dbversion < 60 { if dbversion < 60 {
@@ -865,6 +864,7 @@ fn open(
"ALTER TABLE contacts ADD COLUMN selfavatar_sent INTEGER DEFAULT 0;", "ALTER TABLE contacts ADD COLUMN selfavatar_sent INTEGER DEFAULT 0;",
NO_PARAMS, NO_PARAMS,
)?; )?;
update_icons = true;
sql.set_raw_config_int(context, "dbversion", 61)?; sql.set_raw_config_int(context, "dbversion", 61)?;
} }
@@ -892,6 +892,7 @@ fn open(
} }
if update_icons { if update_icons {
update_saved_messages_icon(context)?; update_saved_messages_icon(context)?;
update_device_icon(context)?;
} }
} }