Skip to content

Commit 63ac982

Browse files
authored
feat!: remove json storage and deprecated data_path config (#446)
Migration from JSON storage to SQLite storage is also removed.
1 parent 6fdc0db commit 63ac982

File tree

11 files changed

+11
-866
lines changed

11 files changed

+11
-866
lines changed

Cargo.lock

Lines changed: 2 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "gurk"
33
description = "Signal messenger client for terminal"
4-
version = "0.7.2"
4+
version = "0.8.0-dev"
55
authors = ["boxdot <[email protected]>"]
66
edition = "2024"
77
keywords = ["signal", "tui"]
@@ -26,7 +26,7 @@ lto = "thin"
2626
debug = true
2727

2828
[features]
29-
dev = ["prost", "base64"]
29+
dev = ["prost", "base64", "serde_json"]
3030

3131
[dependencies]
3232
presage = { git = "https://github.com/whisperfish/presage", rev = "ed011688fc8d9c0ee07c3d44743c138c1fa4dfda" }
@@ -64,7 +64,7 @@ ratatui = "0.29.0"
6464
regex = "1.11.1"
6565
scopeguard = "1.2.0"
6666
serde = { version = "1.0.216", features = ["derive"] }
67-
serde_json = "1.0.134"
67+
serde_json = { version = "1.0.134", optional = true }
6868
sqlx = { version = "0.8.2", features = [
6969
"sqlite",
7070
"runtime-tokio-rustls",
@@ -108,7 +108,6 @@ ignored = ["libsqlite3-sys"]
108108
[dev-dependencies]
109109
criterion = { version = "0.7", features = ["async_tokio", "html_reports"] }
110110
hex-literal = "1.0.0"
111-
insta = { version = "1.41.1", features = ["json"] }
112111
quickcheck = "1.0.3"
113112
quickcheck_macros = "1.0.0"
114113

src/config.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ pub struct Config {
1919
skip_serializing_if = "is_default_data_dir"
2020
)]
2121
pub data_dir: PathBuf,
22-
/// Path to the JSON file (incl. filename) storing channels and messages.
23-
#[serde(
24-
default = "default_data_json_path",
25-
rename = "data_path",
26-
skip_serializing
27-
)]
28-
pub deprecated_data_path: PathBuf,
2922
/// Path to the Signal database containing the linked device data.
3023
#[serde(
3124
rename = "signal_db_path",
@@ -123,7 +116,6 @@ impl Config {
123116
Config {
124117
user,
125118
data_dir: default_data_dir(),
126-
deprecated_data_path: default_data_json_path(),
127119
deprecated_signal_db_path: default_signal_db_path(),
128120
first_name_only: false,
129121
show_receipts: true,
@@ -202,12 +194,6 @@ impl Config {
202194
message: "sqlite is now enabled by default",
203195
});
204196
}
205-
if config_value.get("data_path").is_some() {
206-
keys.push(DeprecatedConfigKey {
207-
key: "data_path",
208-
message: "is not used anymore, and is migrated to sqlite.url",
209-
});
210-
}
211197
if config_value.get("signal_db_path").is_some() {
212198
keys.push(DeprecatedConfigKey {
213199
key: "signal_db_path",
@@ -327,10 +313,6 @@ fn is_default_data_dir(path: &Path) -> bool {
327313
path == default_data_dir()
328314
}
329315

330-
fn default_data_json_path() -> PathBuf {
331-
default_data_dir().join("gurk.data.json")
332-
}
333-
334316
fn default_true() -> bool {
335317
true
336318
}

src/data.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,6 @@ impl Message {
325325
})
326326
}
327327

328-
/// Returns whether this message is an edit of an another message
329-
pub(crate) fn is_edit(&self) -> bool {
330-
self.edit.is_some()
331-
}
332-
333328
pub fn is_empty(&self) -> bool {
334329
self.message.is_none()
335330
&& self.attachments.is_empty()

src/main.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ use crossterm::{
1717
};
1818
use gurk::{app::App, config::Config};
1919
use gurk::{backoff::Backoff, passphrase::Passphrase};
20-
use gurk::{config, signal, ui};
2120
use gurk::{
2221
onboarding,
23-
storage::{JsonStorage, MemCache, SqliteStorage, Storage, sync_from_signal},
22+
storage::{MemCache, SqliteStorage, Storage, sync_from_signal},
2423
};
24+
use gurk::{signal, ui};
2525
use presage::libsignal_service::content::Content;
2626
use ratatui::{Terminal, backend::CrosstermBackend};
2727
use tokio::{runtime, select};
@@ -135,23 +135,9 @@ async fn run(config: Config, passphrase: Passphrase, relink: bool) -> anyhow::Re
135135
};
136136

137137
debug!(%url, "opening sqlite data storage");
138-
let mut sqlite_storage = SqliteStorage::maybe_encrypt_and_open(&url, &passphrase, false)
138+
let sqlite_storage = SqliteStorage::maybe_encrypt_and_open(&url, &passphrase, false)
139139
.await
140140
.with_context(|| format!("failed to open sqlite data storage at: {url}"))?;
141-
if sqlite_storage.is_empty() || !(sqlite_storage.metadata().fully_migrated.unwrap_or(false))
142-
{
143-
if let Ok(json_storage) = JsonStorage::new(
144-
&config.deprecated_data_path,
145-
config::fallback_data_path().as_deref(),
146-
) {
147-
println!("converting JSON storage to SQLite storage at {url}");
148-
let stats = sqlite_storage.copy_from(&json_storage).await?;
149-
let mut metadata = sqlite_storage.metadata().into_owned();
150-
metadata.fully_migrated = Some(true);
151-
sqlite_storage.store_metadata(metadata);
152-
info!(?stats, "converted");
153-
}
154-
}
155141
Box::new(MemCache::new(sqlite_storage))
156142
};
157143

src/receipt.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,4 @@ mod tests {
180180
assert!(Receipt::Sent < Receipt::Delivered);
181181
assert!(Receipt::Delivered < Receipt::Read);
182182
}
183-
184-
#[test]
185-
fn test_receipt_serde() -> anyhow::Result<()> {
186-
assert_eq!(serde_json::to_string(&Receipt::Nothing)?, "\"Nothing\"");
187-
assert_eq!(serde_json::to_string(&Receipt::Sent)?, "\"Sent\"");
188-
assert_eq!(serde_json::to_string(&Receipt::Delivered)?, "\"Delivered\"");
189-
assert_eq!(serde_json::to_string(&Receipt::Read)?, "\"Read\"");
190-
191-
let receipt: Receipt = serde_json::from_str("\"Unknown\"")?;
192-
assert_eq!(receipt, Receipt::Nothing);
193-
194-
Ok(())
195-
}
196183
}

src/storage/copy.rs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,6 @@ use crate::signal::SignalManager;
66

77
use super::Storage;
88

9-
#[derive(Debug, Default)]
10-
pub struct Stats {
11-
pub channels: usize,
12-
pub messages: usize,
13-
pub names: usize,
14-
}
15-
16-
pub fn copy(from: &dyn Storage, to: &mut dyn Storage) -> Stats {
17-
let mut stats = Stats::default();
18-
19-
to.store_metadata(from.metadata().into_owned());
20-
21-
for channel in from.channels() {
22-
let channel_id = channel.id;
23-
to.store_channel(channel.into_owned());
24-
stats.channels += 1;
25-
for message in from.messages(channel_id) {
26-
to.store_message(channel_id, message.into_owned());
27-
stats.messages += 1;
28-
}
29-
}
30-
31-
for (id, name) in from.names() {
32-
to.store_name(id, name.into_owned());
33-
stats.names += 1;
34-
}
35-
36-
stats
37-
}
38-
399
/// Copies contacts and groups from the signal manager into the storages
4010
///
4111
/// If contact/group is not in the storage, a new one is created. Group channels are updated,

0 commit comments

Comments
 (0)