mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
add hide_pre_message_metadata_text config option to hide the additional text that would get added to pre-messages
This commit is contained in:
@@ -495,6 +495,8 @@ char* dc_get_blobdir (const dc_context_t* context);
|
|||||||
* Post-Messages are automatically downloaded if they are smaller than the download_limit.
|
* Post-Messages are automatically downloaded if they are smaller than the download_limit.
|
||||||
* 0=no limit (default).
|
* 0=no limit (default).
|
||||||
* Changes affect future messages only.
|
* Changes affect future messages only.
|
||||||
|
* - `hide_pre_message_metadata_text` = Pre-Messages get information added to their text field.
|
||||||
|
* UI can set this to true when it already displays this information in a prettier manner.
|
||||||
* - `protect_autocrypt` = Enable Header Protection for Autocrypt header.
|
* - `protect_autocrypt` = Enable Header Protection for Autocrypt header.
|
||||||
* This is an experimental option not compatible to other MUAs
|
* This is an experimental option not compatible to other MUAs
|
||||||
* and older Delta Chat versions.
|
* and older Delta Chat versions.
|
||||||
|
|||||||
@@ -446,6 +446,12 @@ pub enum Config {
|
|||||||
|
|
||||||
/// Return an error from `receive_imf_inner()`. For tests.
|
/// Return an error from `receive_imf_inner()`. For tests.
|
||||||
SimulateReceiveImfError,
|
SimulateReceiveImfError,
|
||||||
|
|
||||||
|
/// Disable the addition of the metadata to the text field of Pre-Messages.
|
||||||
|
///
|
||||||
|
/// This is used by tests and can be used in the UI,
|
||||||
|
/// when the UI wants to displays that information in a prettier manner.
|
||||||
|
HidePreMessageMetadataText,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
|
|||||||
@@ -1093,6 +1093,13 @@ impl Context {
|
|||||||
.await?
|
.await?
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
);
|
);
|
||||||
|
res.insert(
|
||||||
|
"hide_pre_message_metadata_text",
|
||||||
|
self.sql
|
||||||
|
.get_raw_config("hide_pre_message_metadata_text")
|
||||||
|
.await?
|
||||||
|
.unwrap_or_default(),
|
||||||
|
);
|
||||||
|
|
||||||
let elapsed = time_elapsed(&self.creation_time);
|
let elapsed = time_elapsed(&self.creation_time);
|
||||||
res.insert("uptime", duration_to_str(elapsed));
|
res.insert("uptime", duration_to_str(elapsed));
|
||||||
|
|||||||
@@ -783,6 +783,13 @@ async fn export_database(
|
|||||||
let res = conn
|
let res = conn
|
||||||
.query_row("SELECT sqlcipher_export('backup')", [], |_row| Ok(()))
|
.query_row("SELECT sqlcipher_export('backup')", [], |_row| Ok(()))
|
||||||
.context("failed to export to attached backup database");
|
.context("failed to export to attached backup database");
|
||||||
|
// This option is device/client specific, so we reset it on backup.
|
||||||
|
// The test for this is tests::pre_messages::additional_text::test_disable_option_is_exluded_from_backup
|
||||||
|
conn.execute(
|
||||||
|
"UPDATE backup.config SET value='0' WHERE keyname=?;",
|
||||||
|
[Config::HidePreMessageMetadataText.to_string()],
|
||||||
|
)
|
||||||
|
.ok();
|
||||||
conn.execute(
|
conn.execute(
|
||||||
"UPDATE backup.config SET value='0' WHERE keyname='verified_one_on_one_chats';",
|
"UPDATE backup.config SET value='0' WHERE keyname='verified_one_on_one_chats';",
|
||||||
[],
|
[],
|
||||||
|
|||||||
@@ -604,6 +604,10 @@ impl Message {
|
|||||||
param: &Params,
|
param: &Params,
|
||||||
) -> Result<String> {
|
) -> Result<String> {
|
||||||
if download_state != DownloadState::Done {
|
if download_state != DownloadState::Done {
|
||||||
|
let hide_pre_message_metadata = context
|
||||||
|
.get_config_bool(Config::HidePreMessageMetadataText)
|
||||||
|
.await?;
|
||||||
|
if !hide_pre_message_metadata {
|
||||||
let file_size = param
|
let file_size = param
|
||||||
.get(Param::PostMessageFileBytes)
|
.get(Param::PostMessageFileBytes)
|
||||||
.and_then(|s| s.parse().ok())
|
.and_then(|s| s.parse().ok())
|
||||||
@@ -626,6 +630,7 @@ impl Message {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Ok(String::new())
|
Ok(String::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
use crate::message::Viewtype;
|
use crate::EventType;
|
||||||
|
use crate::config::Config;
|
||||||
|
use crate::imex::{ImexMode, has_backup, imex};
|
||||||
|
use crate::message::{Message, Viewtype};
|
||||||
use crate::test_utils::TestContextManager;
|
use crate::test_utils::TestContextManager;
|
||||||
use crate::tests::pre_messages::util::{
|
use crate::tests::pre_messages::util::{
|
||||||
send_large_file_message, send_large_image_message, send_large_webxdc_message,
|
send_large_file_message, send_large_image_message, send_large_webxdc_message,
|
||||||
@@ -38,3 +41,75 @@ async fn test_additional_text_on_different_viewtypes() -> Result<()> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Test that disabling the addition of the download info works
|
||||||
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
|
async fn test_disable_additional_text() -> Result<()> {
|
||||||
|
let mut tcm = TestContextManager::new();
|
||||||
|
let alice = &tcm.alice().await;
|
||||||
|
let bob = &tcm.bob().await;
|
||||||
|
let alice_group_id = alice.create_group_with_members("test group", &[bob]).await;
|
||||||
|
|
||||||
|
let (pre_message, _post_message, _alice_msg_id) =
|
||||||
|
send_large_file_message(alice, alice_group_id, Viewtype::File, &vec![0u8; 1_000_000])
|
||||||
|
.await?;
|
||||||
|
let msg = bob.recv_msg(&pre_message).await;
|
||||||
|
assert_eq!(msg.get_text(), "test [test.bin - 976.56 KiB]".to_owned());
|
||||||
|
|
||||||
|
bob.set_config_bool(Config::HidePreMessageMetadataText, true)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let msg = Message::load_from_db(bob, msg.id).await?;
|
||||||
|
assert_eq!(msg.get_text(), "test".to_owned());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Test that disabling the addition of the download info works
|
||||||
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
|
async fn test_disable_option_is_exluded_from_backup() -> Result<()> {
|
||||||
|
let backup_dir = tempfile::tempdir()?;
|
||||||
|
let mut tcm = TestContextManager::new();
|
||||||
|
let alice = &tcm.alice().await;
|
||||||
|
|
||||||
|
tcm.section("set config option");
|
||||||
|
alice
|
||||||
|
.set_config_bool(Config::HidePreMessageMetadataText, true)
|
||||||
|
.await?;
|
||||||
|
assert_eq!(
|
||||||
|
alice
|
||||||
|
.get_config_bool(Config::HidePreMessageMetadataText)
|
||||||
|
.await?,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
tcm.section("export backup");
|
||||||
|
imex(alice, ImexMode::ExportBackup, backup_dir.path(), None).await?;
|
||||||
|
let _event = alice
|
||||||
|
.evtracker
|
||||||
|
.get_matching(|evt| matches!(evt, EventType::ImexProgress(1000)))
|
||||||
|
.await;
|
||||||
|
|
||||||
|
tcm.section("import backup");
|
||||||
|
let alice2 = &tcm.unconfigured().await;
|
||||||
|
let backup = has_backup(alice2, backup_dir.path()).await?;
|
||||||
|
imex(alice2, ImexMode::ImportBackup, backup.as_ref(), None).await?;
|
||||||
|
let _event = alice2
|
||||||
|
.evtracker
|
||||||
|
.get_matching(|evt| matches!(evt, EventType::ImexProgress(1000)))
|
||||||
|
.await;
|
||||||
|
assert_eq!(
|
||||||
|
alice.get_primary_self_addr().await?,
|
||||||
|
alice2.get_primary_self_addr().await?,
|
||||||
|
"address should be the same"
|
||||||
|
);
|
||||||
|
|
||||||
|
tcm.section("test if config is reset as expected");
|
||||||
|
assert_eq!(
|
||||||
|
alice2
|
||||||
|
.get_config_bool(Config::HidePreMessageMetadataText)
|
||||||
|
.await?,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user