Browse Source

embed migrations, fix contact downloading, suppress dead code warnings

master
eta 3 years ago
parent
commit
98b53e2c45
  1. 31
      Cargo.lock
  2. 1
      Cargo.toml
  3. 3
      src/comm.rs
  4. 1
      src/main.rs
  5. 3
      src/store.rs
  6. 6
      src/whatsapp.rs
  7. 4
      src/whatsapp_media.rs

31
Cargo.lock generated

@ -438,6 +438,15 @@ dependencies = [ @@ -438,6 +438,15 @@ dependencies = [
"syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "diesel_migrations"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"migrations_internals 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"migrations_macros 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "digest"
version = "0.7.6"
@ -981,6 +990,24 @@ name = "memoffset" @@ -981,6 +990,24 @@ name = "memoffset"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "migrations_internals"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "migrations_macros"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"migrations_internals 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "mime"
version = "0.3.13"
@ -1934,6 +1961,7 @@ dependencies = [ @@ -1934,6 +1961,7 @@ dependencies = [
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"derive_builder 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"diesel_migrations 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
"huawei-modem 0.2.1 (git+https://git.theta.eu.org/huawei-modem.git/)",
@ -2618,6 +2646,7 @@ dependencies = [ @@ -2618,6 +2646,7 @@ dependencies = [
"checksum derive_is_enum_variant 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d0ac8859845146979953797f03cc5b282fb4396891807cdb3d04929a88418197"
"checksum diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8d24935ba50c4a8dc375a0fd1f8a2ba6bdbdc4125713126a74b965d6a01a06d7"
"checksum diesel_derives 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "62a27666098617d52c487a41f70de23d44a1dc1f3aa5877ceba2790fb1f1cab4"
"checksum diesel_migrations 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3cde8413353dc7f5d72fa8ce0b99a560a359d2c5ef1e5817ca731cd9008f4c"
"checksum digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "03b072242a8cbaf9c145665af9d250c59af3b958f83ed6824e13533cf76d5b90"
"checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c"
"checksum dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ea57b42383d091c85abcc2706240b94ab2a8fa1fc81c10ff23c4de06e2a90b5e"
@ -2683,6 +2712,8 @@ dependencies = [ @@ -2683,6 +2712,8 @@ dependencies = [
"checksum memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "148fab2e51b4f1cfc66da2a7c32981d1d3c083a803978268bb11fe4b86925e7a"
"checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39"
"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
"checksum migrations_internals 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8089920229070f914b9ce9b07ef60e175b2b9bc2d35c3edd8bf4433604e863b9"
"checksum migrations_macros 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1664412abf7db2b8a6d58be42a38b099780cc542b5b350383b805d88932833fe"
"checksum mime 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "3e27ca21f40a310bd06d9031785f4801710d566c184a6e15bad4f1d9b65f9425"
"checksum mime_guess 2.0.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "30de2e4613efcba1ec63d8133f344076952090c122992a903359be5a4f99c3ed"
"checksum miniz_oxide 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c468f2369f07d651a5d0bb2c9079f8488a66d5466efe42d0c5c6466edcb7f71e"

1
Cargo.toml

@ -7,6 +7,7 @@ version = "0.1.0" @@ -7,6 +7,7 @@ version = "0.1.0"
[dependencies]
chrono = "0.4"
derive_builder = "0.7"
diesel_migrations = "1.4"
failure = "0.1"
futures = "0.1"
humansize = "1.0"

3
src/comm.rs

@ -27,6 +27,8 @@ pub enum ModemCommand { @@ -27,6 +27,8 @@ pub enum ModemCommand {
UpdatePath(Option<String>),
CommandTimeout
}
// FIXME: clean up dead code wrt avatars
#[allow(dead_code)]
pub enum WhatsappCommand {
StartRegistration,
LogonIfSaved,
@ -49,6 +51,7 @@ pub enum WhatsappCommand { @@ -49,6 +51,7 @@ pub enum WhatsappCommand {
AvatarShow(String),
AvatarUpdateAll
}
#[allow(dead_code)]
pub enum ContactFactoryCommand {
ProcessMessages,
ProcessGroups,

1
src/main.rs

@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
#[macro_use] extern crate failure;
#[macro_use] extern crate log;
#[macro_use] extern crate lazy_static;
#[macro_use] extern crate diesel_migrations;
mod config;
mod logging;

3
src/store.rs

@ -13,6 +13,8 @@ use whatsappweb::Jid; @@ -13,6 +13,8 @@ use whatsappweb::Jid;
use crate::util::{self, Result};
use crate::models::*;
embed_migrations!();
#[derive(Clone)]
pub struct Store {
inner: Arc<Pool<ConnectionManager<PgConnection>>>
@ -22,6 +24,7 @@ impl Store { @@ -22,6 +24,7 @@ impl Store {
let manager = ConnectionManager::new(cfg.database_url.clone());
let pool = Pool::builder()
.build(manager)?;
embedded_migrations::run(&*pool.get()?)?;
Ok(Self {
inner: Arc::new(pool)
})

6
src/whatsapp.rs

@ -342,7 +342,7 @@ impl WhatsappManager { @@ -342,7 +342,7 @@ impl WhatsappManager {
Ok(None)
}
fn on_message(&mut self, msg: Box<WaMessage>) -> Result<()> {
use whatsappweb::message::{Direction, Peer};
use whatsappweb::message::{Direction};
trace!("processing WA message: {:?}", msg);
let msg = *msg; // otherwise stupid borrowck gets angry, because Box
@ -433,11 +433,11 @@ impl WhatsappManager { @@ -433,11 +433,11 @@ impl WhatsappManager {
ChatMessageContent::Contact { display_name, vcard } => {
match crate::whatsapp_media::store_contact(&self.media_path, &self.dl_path, vcard) {
Ok(link) => {
format!("\x01ACTION uploaded a contact for '{}' - {}", display_name, link)
format!("\x01ACTION uploaded a contact for '{}' - {}\x01", display_name, link)
},
Err(e) => {
warn!("Failed to save contact card: {}", e);
format!("\x01ACTION uploaded a contact for '{}' (couldn't download)", display_name)
format!("\x01ACTION uploaded a contact for '{}' (couldn't download)\x01", display_name)
}
}
},

4
src/whatsapp_media.rs

@ -20,11 +20,11 @@ use mime_guess::get_mime_extensions_str; @@ -20,11 +20,11 @@ use mime_guess::get_mime_extensions_str;
pub fn store_contact(path: &str, dl_path: &str, vcard: String) -> Result<String> {
let uu = Uuid::new_v4().to_simple().to_string();
let path = format!("{}/{}.vcf", path, uu);
let dl_path = format!("{}/{}.vcf", path, uu);
let dl_path = format!("{}/{}.vcf", dl_path, uu);
debug!("Creating file {}", path);
let mut file = File::create(&path)?;
file.write_all(&vcard.as_bytes())?;
Ok(path)
Ok(dl_path)
}
pub struct MediaInfo {

Loading…
Cancel
Save