mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 13:36:30 +03:00
refactor: remove update_icons and disable_server_delete migrations
This commit is contained in:
@@ -7215,11 +7215,6 @@ void dc_event_unref(dc_event_t* event);
|
||||
/// Used as device message text.
|
||||
#define DC_STR_SELF_DELETED_MSG_BODY 91
|
||||
|
||||
/// "'Delete messages from server' turned off as now all folders are affected."
|
||||
///
|
||||
/// Used as device message text.
|
||||
#define DC_STR_SERVER_TURNED_OFF 92
|
||||
|
||||
/// "Message deletion timer is set to %1$s minutes."
|
||||
///
|
||||
/// Used in status messages.
|
||||
|
||||
19
src/sql.rs
19
src/sql.rs
@@ -9,7 +9,6 @@ use rusqlite::{Connection, OpenFlags, Row, config::DbConfig, types::ValueRef};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use crate::blob::BlobObject;
|
||||
use crate::chat::add_device_msg;
|
||||
use crate::config::Config;
|
||||
use crate::constants::DC_CHAT_ID_TRASH;
|
||||
use crate::context::Context;
|
||||
@@ -18,12 +17,11 @@ use crate::ephemeral::start_ephemeral_timers;
|
||||
use crate::imex::BLOBS_BACKUP_NAME;
|
||||
use crate::location::delete_orphaned_poi_locations;
|
||||
use crate::log::{LogExt, warn};
|
||||
use crate::message::{Message, MsgId};
|
||||
use crate::message::MsgId;
|
||||
use crate::net::dns::prune_dns_cache;
|
||||
use crate::net::http::http_cache_cleanup;
|
||||
use crate::net::prune_connection_history;
|
||||
use crate::param::{Param, Params};
|
||||
use crate::stock_str;
|
||||
use crate::tools::{SystemTime, Time, delete_file, time, time_elapsed};
|
||||
|
||||
/// Extension to [`rusqlite::ToSql`] trait
|
||||
@@ -216,26 +214,13 @@ impl Sql {
|
||||
// this should be done before updates that use high-level objects that
|
||||
// rely themselves on the low-level structure.
|
||||
|
||||
// `update_icons` is not used anymore, since it's not necessary anymore to "update" icons:
|
||||
let (_update_icons, disable_server_delete, recode_avatar) = migrations::run(context, self)
|
||||
let recode_avatar = migrations::run(context, self)
|
||||
.await
|
||||
.context("failed to run migrations")?;
|
||||
|
||||
// (2) updates that require high-level objects
|
||||
// the structure is complete now and all objects are usable
|
||||
|
||||
if disable_server_delete {
|
||||
// We now always watch all folders and delete messages there if delete_server is enabled.
|
||||
// So, for people who have delete_server enabled, disable it and add a hint to the devicechat:
|
||||
if context.get_config_delete_server_after().await?.is_some() {
|
||||
let mut msg = Message::new_text(stock_str::delete_server_turned_off(context).await);
|
||||
add_device_msg(context, None, Some(&mut msg)).await?;
|
||||
context
|
||||
.set_config_internal(Config::DeleteServerAfter, Some("0"))
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
if recode_avatar && let Some(avatar) = context.get_config(Config::Selfavatar).await? {
|
||||
let mut blob = BlobObject::from_path(context, Path::new(&avatar))?;
|
||||
match blob.recode_to_avatar_size(context).await {
|
||||
|
||||
@@ -31,7 +31,7 @@ tokio::task_local! {
|
||||
static STOP_MIGRATIONS_AT: i32;
|
||||
}
|
||||
|
||||
pub async fn run(context: &Context, sql: &Sql) -> Result<(bool, bool, bool)> {
|
||||
pub async fn run(context: &Context, sql: &Sql) -> Result<bool> {
|
||||
let mut exists_before_update = false;
|
||||
let mut dbversion_before_update = DBVERSION;
|
||||
|
||||
@@ -68,8 +68,6 @@ pub async fn run(context: &Context, sql: &Sql) -> Result<(bool, bool, bool)> {
|
||||
}
|
||||
|
||||
let dbversion = dbversion_before_update;
|
||||
let mut update_icons = !exists_before_update;
|
||||
let mut disable_server_delete = false;
|
||||
let mut recode_avatar = false;
|
||||
|
||||
if dbversion < 1 {
|
||||
@@ -299,7 +297,6 @@ CREATE INDEX devmsglabels_index1 ON devmsglabels (label);"#, 59)
|
||||
61,
|
||||
)
|
||||
.await?;
|
||||
update_icons = true;
|
||||
}
|
||||
if dbversion < 62 {
|
||||
sql.execute_migration(
|
||||
@@ -327,7 +324,6 @@ ALTER TABLE msgs ADD COLUMN ephemeral_timestamp INTEGER DEFAULT 0;"#,
|
||||
.await?;
|
||||
}
|
||||
if dbversion < 66 {
|
||||
update_icons = true;
|
||||
sql.set_db_version(66).await?;
|
||||
}
|
||||
if dbversion < 67 {
|
||||
@@ -445,17 +441,6 @@ CREATE TABLE imap_sync (folder TEXT PRIMARY KEY, uidvalidity INTEGER DEFAULT 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
if exists_before_update {
|
||||
disable_server_delete = true;
|
||||
|
||||
// Don't disable server delete if it was on by default (Nauta):
|
||||
if let Some(provider) = context.get_configured_provider().await?
|
||||
&& let Some(defaults) = &provider.config_defaults
|
||||
&& defaults.iter().any(|d| d.key == Config::DeleteServerAfter)
|
||||
{
|
||||
disable_server_delete = false;
|
||||
}
|
||||
}
|
||||
sql.set_db_version(73).await?;
|
||||
}
|
||||
if dbversion < 74 {
|
||||
@@ -1468,7 +1453,7 @@ CREATE INDEX imap_sync_index ON imap_sync(transport_id, folder);
|
||||
}
|
||||
info!(context, "Database version: v{new_version}.");
|
||||
|
||||
Ok((update_icons, disable_server_delete, recode_avatar))
|
||||
Ok(recode_avatar)
|
||||
}
|
||||
|
||||
fn migrate_key_contacts(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use super::*;
|
||||
use crate::message::Message;
|
||||
use crate::{EventType, test_utils::TestContext};
|
||||
|
||||
#[test]
|
||||
@@ -179,9 +180,7 @@ async fn test_migration_flags() -> Result<()> {
|
||||
// as migrations::run() was already executed on context creation,
|
||||
// another call should not result in any action needed.
|
||||
// this test catches some bugs where dbversion was forgotten to be persisted.
|
||||
let (update_icons, disable_server_delete, recode_avatar) = migrations::run(&t, &t.sql).await?;
|
||||
assert!(!update_icons);
|
||||
assert!(!disable_server_delete);
|
||||
let recode_avatar = migrations::run(&t, &t.sql).await?;
|
||||
assert!(!recode_avatar);
|
||||
|
||||
info!(&t, "test_migration_flags: XXX END MARKER");
|
||||
|
||||
@@ -155,13 +155,6 @@ pub enum StockMessage {
|
||||
To use the \"Saved messages\" feature again, create a new chat with yourself."))]
|
||||
SelfDeletedMsgBody = 91,
|
||||
|
||||
#[strum(props(
|
||||
fallback = "⚠️ The \"Delete messages from server\" feature now also deletes messages in folders other than Inbox, DeltaChat and Sent.\n\n\
|
||||
ℹ️ To avoid accidentally deleting messages, we turned it off for you. Please turn it on again at \
|
||||
Settings → \"Chats and Media\" → \"Delete messages from server\" to continue using it."
|
||||
))]
|
||||
DeleteServerTurnedOff = 92,
|
||||
|
||||
#[strum(props(fallback = "Forwarded"))]
|
||||
Forwarded = 97,
|
||||
|
||||
@@ -1041,11 +1034,6 @@ pub(crate) async fn self_deleted_msg_body(context: &Context) -> String {
|
||||
translated(context, StockMessage::SelfDeletedMsgBody).await
|
||||
}
|
||||
|
||||
/// Stock string: `⚠️ The "Delete messages from server" feature now also...`.
|
||||
pub(crate) async fn delete_server_turned_off(context: &Context) -> String {
|
||||
translated(context, StockMessage::DeleteServerTurnedOff).await
|
||||
}
|
||||
|
||||
/// Stock string: `Message deletion timer is set to %1$s minutes.`.
|
||||
pub(crate) async fn msg_ephemeral_timer_minutes(
|
||||
context: &Context,
|
||||
|
||||
Reference in New Issue
Block a user