aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreta <hi@theta.eu.org>2019-10-18 13:02:29 +0100
committereta <hi@theta.eu.org>2019-10-18 13:02:29 +0100
commitb2aaec756c2015ef5dea553d52f0b9ac876b8ce4 (patch)
tree824e1447c700761e8c379e456ca3d74c00193696
parent6797a83d61beade63b65490af2b90c4023100fbc (diff)
downloadsms-irc-sqlite.tar.gz
sms-irc-sqlite.tar.bz2
sms-irc-sqlite.zip
Migrate from PostgreSQL to SQLitesqlite
- As part of the ongoing efforts to reduce the number of dependencies sms-irc requires, this commit completely removes PostgreSQL support, replacing it instead with SQLite through the `sequelight` crate (recently extracted from trainsplorer). - While we were at it, handling of PduAddresses and Jids was also improved; now, these types are represented as-is in models.rs, and are transparently serialized/deserialized when interacting with the database, removing the need for hacky code that does this all about the place. - No migration path is provided yet; the intent is to provide this in a separate crate.
-rw-r--r--.gitignore1
-rw-r--r--Cargo.lock421
-rw-r--r--Cargo.toml12
-rw-r--r--migrations/0_initial_up.sql48
-rw-r--r--src/contact.rs5
-rw-r--r--src/contact_common.rs8
-rw-r--r--src/contact_factory.rs7
-rw-r--r--src/insp_s2s.rs35
-rw-r--r--src/irc_s2c.rs15
-rw-r--r--src/main.rs3
-rw-r--r--src/models.rs251
-rw-r--r--src/sender_common.rs2
-rw-r--r--src/store.rs391
-rw-r--r--src/whatsapp.rs33
-rw-r--r--src/whatsapp_media.rs4
-rw-r--r--src/whatsapp_msg.rs6
16 files changed, 573 insertions, 669 deletions
diff --git a/.gitignore b/.gitignore
index 9442690..6e0cac4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
/target
+*.sqlite*
config.toml
**/*.rs.bk
diff --git a/Cargo.lock b/Cargo.lock
index 4bb432d..0f638f6 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -27,11 +27,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
-name = "arrayref"
-version = "0.3.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
-[[package]]
name = "arrayvec"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -66,15 +61,6 @@ dependencies = [
[[package]]
name = "base64"
-version = "0.6.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "base64"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
@@ -106,25 +92,11 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
-name = "block-buffer"
-version = "0.3.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
- "byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
name = "bufstream"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
-name = "byte-tools"
-version = "0.2.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
-[[package]]
name = "byteorder"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -189,11 +161,6 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
-name = "constant_time_eq"
-version = "0.1.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
-[[package]]
name = "cookie"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -290,15 +257,6 @@ dependencies = [
]
[[package]]
-name = "crypto-mac"
-version = "0.5.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
name = "deflate"
version = "0.7.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -318,46 +276,6 @@ dependencies = [
]
[[package]]
-name = "diesel"
-version = "1.4.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "chrono 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
- "diesel_derives 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "pq-sys 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "diesel_derives"
-version = "1.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
- "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
- "syn 0.15.42 (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"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
name = "dtoa"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -442,6 +360,19 @@ dependencies = [
]
[[package]]
+name = "err-derive"
+version = "0.1.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "proc-macro-error 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "synstructure 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "error-chain"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -471,13 +402,13 @@ dependencies = [
]
[[package]]
-name = "fake-simd"
-version = "0.1.2"
+name = "fallible-iterator"
+version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
-name = "fallible-iterator"
-version = "0.1.6"
+name = "fallible-streaming-iterator"
+version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@@ -547,14 +478,6 @@ version = "0.3.55"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
-name = "generic-array"
-version = "0.9.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
name = "getrandom"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -598,20 +521,6 @@ dependencies = [
]
[[package]]
-name = "hex"
-version = "0.2.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
-[[package]]
-name = "hmac"
-version = "0.5.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "crypto-mac 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
name = "http"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -841,6 +750,21 @@ version = "0.2.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
+name = "libsqlite3-sys"
+version = "0.16.0"
+source = "git+https://github.com/jgallagher/rusqlite#2d75411e4462ee8b3b69b8f6f504d65aed86c2a8"
+dependencies = [
+ "cc 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)",
+ "pkg-config 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
+ "vcpkg 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "linked-hash-map"
+version = "0.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
name = "lock_api"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -882,6 +806,14 @@ dependencies = [
]
[[package]]
+name = "lru-cache"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "lzw"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -892,11 +824,6 @@ version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
-name = "md5"
-version = "0.3.8"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
-[[package]]
name = "memchr"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -918,24 +845,6 @@ dependencies = [
]
[[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.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -953,7 +862,7 @@ dependencies = [
[[package]]
name = "mime_guess"
-version = "2.0.0"
+version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"mime 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1280,22 +1189,6 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
-name = "phf"
-version = "0.7.24"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "phf_shared 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "phf_shared"
-version = "0.7.24"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
name = "pkg-config"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1312,58 +1205,18 @@ dependencies = [
]
[[package]]
-name = "postgres"
-version = "0.15.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
- "fallible-iterator 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "postgres-protocol 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "postgres-shared 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "socket2 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "postgres-protocol"
-version = "0.3.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
- "fallible-iterator 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "hmac 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "md5 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)",
- "sha2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "stringprep 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "postgres-shared"
-version = "0.4.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "fallible-iterator 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "hex 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "phf 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)",
- "postgres-protocol 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
name = "ppv-lite86"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
-name = "pq-sys"
-version = "0.4.6"
+name = "proc-macro-error"
+version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "vcpkg 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -1383,6 +1236,14 @@ dependencies = [
]
[[package]]
+name = "proc-macro2"
+version = "1.0.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "protobuf"
version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1447,22 +1308,21 @@ dependencies = [
]
[[package]]
-name = "r2d2"
-version = "0.8.5"
+name = "quote"
+version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "scheduled-thread-pool 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
-name = "r2d2-diesel"
-version = "1.0.0"
+name = "r2d2"
+version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "r2d2 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "scheduled-thread-pool 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -1715,7 +1575,7 @@ dependencies = [
"hyper-tls 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"mime 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
- "mime_guess 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "mime_guess 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1745,6 +1605,22 @@ dependencies = [
]
[[package]]
+name = "rusqlite"
+version = "0.20.0"
+source = "git+https://github.com/jgallagher/rusqlite#2d75411e4462ee8b3b69b8f6f504d65aed86c2a8"
+dependencies = [
+ "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "chrono 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "fallible-iterator 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "fallible-streaming-iterator 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libsqlite3-sys 0.16.0 (git+https://github.com/jgallagher/rusqlite)",
+ "lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
+ "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "rust-crypto"
version = "0.2.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1781,11 +1657,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "safemem"
-version = "0.2.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
-[[package]]
-name = "safemem"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1859,6 +1730,18 @@ version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
+name = "sequelight"
+version = "0.1.0"
+source = "git+https://git.theta.eu.org/sequelight.git/#57c2ec5e017ed31418cba59cd3e1d091e0f14fce"
+dependencies = [
+ "chrono 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "err-derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "r2d2 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rusqlite 0.20.0 (git+https://github.com/jgallagher/rusqlite)",
+]
+
+[[package]]
name = "serde"
version = "1.0.98"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1903,17 +1786,6 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
-name = "sha2"
-version = "0.7.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "block-buffer 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
name = "signal-hook"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1932,11 +1804,6 @@ dependencies = [
]
[[package]]
-name = "siphasher"
-version = "0.2.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
-[[package]]
name = "slab"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1957,8 +1824,6 @@ version = "0.2.0"
dependencies = [
"base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.7 (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.28 (registry+https://github.com/rust-lang/crates.io-index)",
"huawei-modem 0.2.1 (git+https://git.theta.eu.org/huawei-modem.git/)",
@@ -1967,13 +1832,11 @@ dependencies = [
"irc 0.13.6 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "mime_guess 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "postgres 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "mime_guess 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"qrcode 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "r2d2 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)",
- "r2d2-diesel 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.9.19 (registry+https://github.com/rust-lang/crates.io-index)",
+ "sequelight 0.1.0 (git+https://git.theta.eu.org/sequelight.git/)",
"serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1989,17 +1852,6 @@ dependencies = [
]
[[package]]
-name = "socket2"
-version = "0.3.10"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)",
- "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)",
- "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
name = "spin"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2018,15 +1870,6 @@ dependencies = [
]
[[package]]
-name = "stringprep"
-version = "0.1.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
name = "syn"
version = "0.11.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2057,6 +1900,16 @@ dependencies = [
]
[[package]]
+name = "syn"
+version = "1.0.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "synom"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2076,6 +1929,17 @@ dependencies = [
]
[[package]]
+name = "synstructure"
+version = "0.12.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "tempfile"
version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2410,11 +2274,6 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
-name = "typenum"
-version = "1.10.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
-[[package]]
name = "ucd-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2467,6 +2326,11 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
+name = "unicode-xid"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
name = "unidecode"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2621,19 +2485,15 @@ dependencies = [
"checksum aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5"
"checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d"
"checksum arc-swap 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6e43c468bcaa343ddcad9e46806e066e39f62434898b20f5af21261da910d5c7"
-"checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee"
"checksum arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d73f9beda665eaa98ab9e4f7442bd4e7de6652587de55b2525e52e29c1b0ba"
"checksum autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "22130e92352b948e7e82a49cdb0aa94f2211761117f29e052dd397c1ac33542b"
"checksum backtrace 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)" = "b5164d292487f037ece34ec0de2fcede2faa162f085dd96d2385ab81b12765ba"
"checksum backtrace-sys 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "82a830b4ef2d1124a711c71d263c5abdc710ef8e907bd508c88be475cebc422b"
"checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e"
-"checksum base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96434f987501f0ed4eb336a411e0631ecd1afa11574fe148587adc4ff96143c9"
"checksum base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643"
"checksum bincode 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9f04a5e50dc80b3d5d35320889053637d15011aed5e66b66b37ae798c65da6f7"
"checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd"
-"checksum block-buffer 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a076c298b9ecdb530ed9d967e74a6027d6a7478924520acddcddc24c1c8ab3ab"
"checksum bufstream 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "40e38929add23cdf8a366df9b0e088953150724bcbe5fc330b0d8eb3b328eec8"
-"checksum byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "560c32574a12a89ecd91f5e742165893f86e3ab98d21f8ea548658eb9eef5f40"
"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5"
"checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c"
"checksum c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101"
@@ -2643,7 +2503,6 @@ dependencies = [
"checksum chrono 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "77d81f58b7301084de3b958691458a53c3f7e0b1d702f77e550b6a88e3a88abe"
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
"checksum color_quant 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0dbbb57365263e881e805dc77d94697c9118fd94d8da011240555aa7b23445bd"
-"checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e"
"checksum cookie 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "888604f00b3db336d2af898ec3c1d5d0ddf5e6d462220f2ededc33a87ac4bbd5"
"checksum cookie_store 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "46750b3f362965f197996c4448e4a0935e791bf7d6631bfce9ee0af3d24c919c"
"checksum core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "25b9e03f145fd4f2bf705e07b900cd41fc636598fe5dc452fd0db1441c3f496d"
@@ -2654,13 +2513,8 @@ dependencies = [
"checksum crossbeam-epoch 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fedcd6772e37f3da2a9af9bf12ebe046c0dfe657992377b4df982a2b54cd37a9"
"checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b"
"checksum crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6"
-"checksum crypto-mac 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0999b4ff4d3446d4ddb19a63e9e00c1876e75cd7000d20e57a693b4b3f08d958"
"checksum deflate 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)" = "707b6a7b384888a70c8d2e8650b3e60170dfc6a67bb4aa67b6dfca57af4bedb4"
"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 dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ea57b42383d091c85abcc2706240b94ab2a8fa1fc81c10ff23c4de06e2a90b5e"
"checksum either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5527cfe0d098f36e3f8839852688e63c8fff1c90b2b405aef730615f9a7bcf7b"
"checksum encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "6b0d943856b990d12d3b55b359144ff341533e516d94098b1d3fc1ac666d36ec"
@@ -2672,11 +2526,12 @@ dependencies = [
"checksum encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569"
"checksum encoding_rs 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)" = "4155785c79f2f6701f185eb2e6b4caf0555ec03477cb4c70db67b465311620ed"
"checksum env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3ddf21e73e016298f5cb37d6ef8e8da8e39f91f9ec8b0df44b7deb16a9f8cd5b"
+"checksum err-derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b41487fadaa500d02a819eefcde5f713599a01dd51626ef25d2d72d87115667b"
"checksum error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3ab49e9dcb602294bc42f9a7dfc9bc6e936fca4418ea300dbfb84fe16de0b7d9"
"checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2"
"checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1"
-"checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
-"checksum fallible-iterator 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "eb7217124812dc5672b7476d0c2d20cfe9f7c0f1ba0904b674a9762a0212f72e"
+"checksum fallible-iterator 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7"
+"checksum fallible-streaming-iterator 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a"
"checksum flate2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "550934ad4808d5d39365e5d61727309bf18b3b02c6c56b729cb92e7dd84bc3d8"
"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
"checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
@@ -2687,13 +2542,10 @@ dependencies = [
"checksum futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "45dc39533a6cae6da2b56da48edae506bb767ec07370f86f70fc062e9d435869"
"checksum futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4"
"checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2"
-"checksum generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d"
"checksum getrandom 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "cd8e190892c840661957ba9f32dacfb3eb405e657f9f9f60485605f0bb37d6f8"
"checksum gif 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "86c2f2b597d6e05c86ee5947b2223bda468fe8dad3e88e2a6520869322aaf568"
"checksum h2 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b34c246847f938a410a03c5458c7fee2274436675e76d8b903c08efc29c462"
"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
-"checksum hex 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d6a22814455d41612f41161581c2883c0c6a1c41852729b17d5ed88f01e153aa"
-"checksum hmac 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44f3bdb08579d99d7dc761c0e266f13b5f2ab8c8c703b9fc9ef333cd8f48f55e"
"checksum http 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "372bcb56f939e449117fb0869c2e8fd8753a8223d92a172c6e808cf123a5b6e4"
"checksum http-body 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6741c859c1b2463a423a1dbce98d418e6c3c3fc720fb0d45528657320920292d"
"checksum httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9"
@@ -2715,22 +2567,22 @@ dependencies = [
"checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a"
"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
"checksum libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)" = "d44e80633f007889c7eff624b709ab43c92d708caad982295768a7b13ca3b5eb"
+"checksum libsqlite3-sys 0.16.0 (git+https://github.com/jgallagher/rusqlite)" = "<none>"
+"checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83"
"checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c"
"checksum lock_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed946d4529956a20f2d63ebe1b69996d5a2137c91913fe3ebbeff957f5bca7ff"
"checksum lock_api 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f8912e782533a93a167888781b836336a6ca5da6175c05944c86cf28c31104dc"
"checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b"
"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
+"checksum lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c"
"checksum lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084"
"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
-"checksum md5 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "79c56d6a0b07f9e19282511c83fc5b086364cbae4ba8c7d5f190c3d9b0425a48"
"checksum memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "148fab2e51b4f1cfc66da2a7c32981d1d3c083a803978268bb11fe4b86925e7a"
"checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e"
"checksum memoffset 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ce6075db033bbbb7ee5a0bbd3a3186bbae616f57fb001c485c7ff77955f8177f"
-"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.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0"
"checksum mime 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "3e27ca21f40a310bd06d9031785f4801710d566c184a6e15bad4f1d9b65f9425"
-"checksum mime_guess 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d729cf45eaf996831fe7143af04190187ab3ee2a72ea96bd00958d1fae822a9d"
+"checksum mime_guess 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1a0ed03949aef72dbdf3116a383d7b38b4768e6f960528cd6a6044aa9ed68599"
"checksum miniz_oxide 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c061edee74a88eb35d876ce88b94d77a0448a201de111c244b70d047f5820516"
"checksum miniz_oxide_c_api 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6c675792957b0d19933816c4e1d56663c341dd9bfa31cb2140ff2267c1d8ecf4"
"checksum mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)" = "83f51996a3ed004ef184e16818edc51fadffe8e7ca68be67f9dee67d84d0ff23"
@@ -2762,17 +2614,13 @@ dependencies = [
"checksum parking_lot_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cb88cb1cb3790baa6776844f968fea3be44956cf184fa1be5a03341f5491278c"
"checksum parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b"
"checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831"
-"checksum phf 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "b3da44b85f8e8dfaec21adae67f95d93244b2ecf6ad2a692320598dcc8e6dd18"
-"checksum phf_shared 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "234f71a15de2288bcb7e3b6515828d22af7ec8598ee6d24c3b526fa0a80b67a0"
"checksum pkg-config 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c1d2cfa5a714db3b5f24f0915e74fcdf91d09d496ba61329705dda7774d2af"
"checksum png 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "63daf481fdd0defa2d1d2be15c674fbfa1b0fd71882c303a91f9a79b3252c359"
-"checksum postgres 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "115dde90ef51af573580c035857badbece2aa5cde3de1dfb3c932969ca92a6c5"
-"checksum postgres-protocol 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2487e66455bf88a1b247bf08a3ce7fe5197ac6d67228d920b0ee6a0e97fd7312"
-"checksum postgres-shared 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ffac35b3e0029b404c24a3b82149b4e904f293e8ca4a327eefa24d3ca50df36f"
"checksum ppv-lite86 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e3cbf9f658cdb5000fcf6f362b8ea2ba154b9f146a61c7a20d647034c6b6561b"
-"checksum pq-sys 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "6ac25eee5a0582f45a67e837e350d784e7003bd29a5f460796772061ca49ffda"
+"checksum proc-macro-error 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "aeccfe4d5d8ea175d5f0e4a2ad0637e0f4121d63bd99d356fb1f39ab2e7c6097"
"checksum proc-macro2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cd07deb3c6d1d9ff827999c7f9b04cdfd66b1b17ae508e14fe47b620f2282ae0"
"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
+"checksum proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "90cf5f418035b98e655e9cdb225047638296b862b42411c4e45bb88d700f7fc0"
"checksum protobuf 2.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8aefcec9f142b524d98fc81d07827743be89dd6586a1ba6ab21fa66a500b3fa5"
"checksum protobuf-codegen 2.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "31539be8028d6b9e8e1b3b7c74e2fa3555302e27b2cc20dbaee6ffba648f75e2"
"checksum protobuf-codegen-pure 2.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "00993dc5fbbfcf9d8a005f6b6c29fd29fd6d86deba3ae3f41fd20c624c414616"
@@ -2781,8 +2629,8 @@ dependencies = [
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
"checksum quote 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1eca14c727ad12702eb4b6bfb5a232287dcf8385cb8ca83a3eeaf6519c44c408"
"checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
+"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe"
"checksum r2d2 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)" = "bc42ce75d9f4447fb2a04bbe1ed5d18dd949104572850ec19b164e274919f81b"
-"checksum r2d2-diesel 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9c29bad92da76d02bc2c020452ebc3a3fe6fa74cfab91e711c43116e4fb1a3"
"checksum rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)" = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c"
"checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"
"checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca"
@@ -2810,12 +2658,12 @@ dependencies = [
"checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e"
"checksum reqwest 0.9.19 (registry+https://github.com/rust-lang/crates.io-index)" = "1d0777154c2c3eb54f5c480db01de845652d941e47191277cc673634c3853939"
"checksum ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)" = "426bc186e3e95cac1e4a4be125a4aca7e84c2d616ffc02244eef36e2a60a093c"
+"checksum rusqlite 0.20.0 (git+https://github.com/jgallagher/rusqlite)" = "<none>"
"checksum rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a"
"checksum rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f4dccf6f4891ebcc0c39f9b6eb1a83b9bf5d747cb439ec6fba4f3b977038af"
"checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
"checksum ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c92464b447c0ee8c4fb3824ecc8383b81717b9f1e74ba2e72540aef7b9f82997"
-"checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f"
"checksum safemem 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e133ccc4f4d1cd4f89cc8a7ff618287d56dc7f638b8e38fc32c5fdcadc339dd5"
"checksum schannel 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "f2f6abf258d99c3c1c5c2131d99d064e94b7b3dd5f416483057f308fea253339"
"checksum scheduled-thread-pool 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bd07742e081ff6c077f5f6b283f12f32b9e7cc765b316160d66289b74546fbb3"
@@ -2827,28 +2675,27 @@ dependencies = [
"checksum security-framework-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9636f8989cbf61385ae4824b98c1aaa54c994d7d8b41f11c601ed799f0549a56"
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
+"checksum sequelight 0.1.0 (git+https://git.theta.eu.org/sequelight.git/)" = "<none>"
"checksum serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)" = "7fe5626ac617da2f2d9c48af5515a21d5a480dbd151e01bb1c355e26a3e68113"
"checksum serde_derive 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)" = "01e69e1b8a631f245467ee275b8c757b818653c6d704cdbcaeb56b56767b529c"
"checksum serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)" = "051c49229f282f7c6f3813f8286cc1e3323e8051823fce42c7ea80fe13521704"
"checksum serde_urlencoded 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "642dd69105886af2efd227f75a520ec9b44a820d65bc133a9131f7d229fd165a"
"checksum sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d"
-"checksum sha2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9eb6be24e4c23a84d7184280d2722f7f2731fcdd4a9d886efbfe4413e4847ea0"
"checksum signal-hook 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4f61c4d59f3aaa9f61bba6450a9b80ba48362fd7d651689e7a10c453b1f6dc68"
"checksum signal-hook-registry 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1797d48f38f91643908bb14e35e79928f9f4b3cefb2420a564dde0991b4358dc"
-"checksum siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac"
"checksum slab 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17b4fcaed89ab08ef143da37bc52adbcc04d4a69014f4c1208d6b51f0c47bc23"
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
"checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7"
-"checksum socket2 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)" = "df028e0e632c2a1823d920ad74895e7f9128e6438cbc4bc6fd1f180e644767b9"
"checksum spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44363f6f51401c34e7be73db0db371c04705d35efbe9f7d6082e03a921a32c55"
"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
"checksum string 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d24114bfcceb867ca7f71a0d3fe45d45619ec47a6fbfa98cb14e14250bfa5d6d"
-"checksum stringprep 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8ee348cb74b87454fff4b551cbf727025810a004f88aeacae7f85b87f4e9a1c1"
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
"checksum syn 0.12.15 (registry+https://github.com/rust-lang/crates.io-index)" = "c97c05b8ebc34ddd6b967994d5c6e9852fa92f8b82b3858c39451f97346dcce5"
"checksum syn 0.15.42 (registry+https://github.com/rust-lang/crates.io-index)" = "eadc09306ca51a40555dd6fc2b415538e9e18bc9f870e47b1a524a79fe2dcf5e"
+"checksum syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf"
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
"checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f"
+"checksum synstructure 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3f085a5855930c0441ca1288cf044ea4aecf4f43a91668abdb870b4ba546a203"
"checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9"
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
"checksum tiff 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1e4834f28a0330cb9f3f2c87d2649dca723cb33802e2bdcf18da32759fbec7ce"
@@ -2879,7 +2726,6 @@ dependencies = [
"checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382"
"checksum try_from 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "283d3b89e1368717881a9d51dad843cc435380d8109c9e47d38780a324698d8b"
"checksum typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887"
-"checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169"
"checksum ucd-util 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa9b3b49edd3468c0e6565d85783f51af95212b6fa3986a5500954f00b460874"
"checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33"
"checksum unicase 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a84e5511b2a947f3ae965dcb29b13b7b1691b6e7332cf5dbc1744138d5acb7f6"
@@ -2888,6 +2734,7 @@ dependencies = [
"checksum unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1967f4cdfc355b37fd76d2a954fb2ed3871034eb4f26d60537d88795cfc332a9"
"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
+"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
"checksum unidecode 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "402bb19d8e03f1d1a7450e2bd613980869438e0666331be3e073089124aa1adc"
"checksum untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "55cd1f4b4e96b46aeb8d4855db4a7a9bd96eeeb5c6a1ab54593328761642ce2f"
"checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a"
diff --git a/Cargo.toml b/Cargo.toml
index 2c02842..ee76991 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,7 +8,6 @@ license = "AGPL-3.0"
[dependencies]
base64 = "0.10"
-diesel_migrations = "1.4"
failure = "0.1"
futures = "0.1"
humansize = "1.0"
@@ -16,11 +15,8 @@ image = "0.21"
irc = "0.13"
lazy_static = "1.2.0"
log = "0.4"
-mime_guess = "2.0.0-alpha.6"
-postgres = "0.15.2"
+mime_guess = "2.0.1"
qrcode = "0.10"
-r2d2 = "0.8"
-r2d2-diesel = "1.0"
regex = "1.1.0"
reqwest = "0.9"
serde = "1.0"
@@ -38,9 +34,9 @@ unidecode = "0.3"
features = ["serde"]
version = "0.4"
-[dependencies.diesel]
-features = ["postgres", "serde_json", "chrono"]
-version = "1.0"
+[dependencies.sequelight]
+git = "https://git.theta.eu.org/sequelight.git/"
+features = ["bundled", "serde_json"]
[dependencies.huawei-modem]
git = "https://git.theta.eu.org/huawei-modem.git/"
diff --git a/migrations/0_initial_up.sql b/migrations/0_initial_up.sql
new file mode 100644
index 0000000..1b4a86c
--- /dev/null
+++ b/migrations/0_initial_up.sql
@@ -0,0 +1,48 @@
+CREATE TABLE recipients (
+ id INTEGER PRIMARY KEY,
+ phone_number TEXT NOT NULL,
+ nick TEXT NOT NULL,
+ whatsapp BOOL NOT NULL,
+ avatar_url TEXT,
+ notify TEXT,
+ nicksrc INT NOT NULL
+);
+CREATE INDEX recipients_phone_number ON recipients (phone_number);
+CREATE INDEX recipients_nick ON recipients (nick);
+
+CREATE TABLE groups (
+ id INTEGER PRIMARY KEY,
+ jid TEXT UNIQUE NOT NULL,
+ channel TEXT UNIQUE NOT NULL,
+ topic TEXT NOT NULL
+);
+
+CREATE TABLE messages (
+ id INTEGER PRIMARY KEY,
+ phone_number TEXT NOT NULL,
+ pdu BLOB,
+ csms_data INT,
+ group_target INT REFERENCES groups,
+ text TEXT,
+ source INT NOT NULL,
+ ts TEXT NOT NULL
+);
+CREATE INDEX messages_phone_number ON messages (phone_number);
+CREATE INDEX messages_csms_data ON messages (csms_data);
+CREATE INDEX messages_group_target ON messages (group_target);
+
+CREATE TABLE group_memberships (
+ group_id INT NOT NULL REFERENCES groups,
+ user_id INT NOT NULL REFERENCES recipients,
+ is_admin BOOL NOT NULL,
+ UNIQUE(group_id, user_id)
+);
+
+CREATE TABLE wa_persistence (
+ rev INT UNIQUE NOT NULL,
+ data TEXT NOT NULL
+);
+
+CREATE TABLE wa_msgid (
+ mid TEXT UNIQUE NOT NULL
+);
diff --git a/src/contact.rs b/src/contact.rs
index 2fc34a7..749fae7 100644
--- a/src/contact.rs
+++ b/src/contact.rs
@@ -271,10 +271,7 @@ impl ContactManager {
pub fn new(recip: Recipient, p: InitParameters<IrcClientConfig>) -> impl Future<Item = Self, Error = Error> {
let store = p.store;
let wa_mode = recip.whatsapp;
- let addr = match recip.get_addr() {
- Ok(r) => r,
- Err(e) => return Either::B(futures::future::err(e.into()))
- };
+ let addr = recip.phone_number;
let (tx, rx) = mpsc::unbounded();
let modem_tx = p.cm.modem_tx.clone();
let wa_tx = p.cm.wa_tx.clone();
diff --git a/src/contact_common.rs b/src/contact_common.rs
index e7e1c8b..0588483 100644
--- a/src/contact_common.rs
+++ b/src/contact_common.rs
@@ -12,20 +12,20 @@ pub trait ContactManagerManager {
fn wa_tx(&mut self) -> &mut UnboundedSender<WhatsappCommand>;
fn m_tx(&mut self) -> &mut UnboundedSender<ModemCommand>;
fn cb_tx(&mut self) -> &mut UnboundedSender<ControlBotCommand>;
- fn setup_contact_for(&mut self, _: Recipient, _: PduAddress) -> Result<()>;
+ fn setup_contact_for(&mut self, _: Recipient) -> Result<()>;
fn remove_contact_for(&mut self, _: &PduAddress) -> Result<()>;
fn has_contact(&mut self, _: &PduAddress) -> bool;
fn store(&mut self) -> &mut Store;
fn forward_cmd(&mut self, _: &PduAddress, _: ContactManagerCommand) -> Result<()>;
fn resolve_nick(&self, _: &str) -> Option<PduAddress>;
fn setup_recipient(&mut self, recip: Recipient) -> Result<()> {
- let addr = recip.get_addr()?;
+ let addr = &recip.phone_number;
debug!("Setting up recipient for {} (nick {})", addr, recip.nick);
- if self.has_contact(&addr) {
+ if self.has_contact(addr) {
debug!("Not doing anything; contact already exists");
return Ok(());
}
- self.setup_contact_for(recip, addr)?;
+ self.setup_contact_for(recip)?;
Ok(())
}
fn query_contact(&mut self, a: PduAddress, src: i32) -> Result<()> {
diff --git a/src/contact_factory.rs b/src/contact_factory.rs
index cfbbd56..b8d77be 100644
--- a/src/contact_factory.rs
+++ b/src/contact_factory.rs
@@ -26,7 +26,7 @@ pub struct ContactFactory {
contacts_presence: HashMap<PduAddress, Option<String>>,
failed_contacts: HashSet<PduAddress>,
failure_int: Interval,
- messages_processed: HashSet<i32>,
+ messages_processed: HashSet<i64>,
cfg: Config,
store: Store,
cm: ChannelMaker,
@@ -103,7 +103,8 @@ impl ContactManagerManager for ContactFactory {
fn wa_tx(&mut self) -> &mut UnboundedSender<WhatsappCommand> { &mut self.wa_tx }
fn cb_tx(&mut self) -> &mut UnboundedSender<ControlBotCommand> { &mut self.cb_tx }
fn m_tx(&mut self) -> &mut UnboundedSender<ModemCommand> { &mut self.m_tx }
- fn setup_contact_for(&mut self, recip: Recipient, addr: PduAddress) -> Result<()> {
+ fn setup_contact_for(&mut self, recip: Recipient) -> Result<()> {
+ let addr = recip.phone_number.clone();
let cfut = {
let ip = self.get_init_parameters();
ContactManager::new(recip, ip)
@@ -201,7 +202,7 @@ impl ContactFactory {
fn process_messages(&mut self) -> Result<()> {
for msg in self.store.get_all_messages()? {
if self.messages_processed.insert(msg.id) {
- let addr = msg.get_addr()?;
+ let addr = msg.phone_number;
if self.contacts_starting.get(&addr).is_some() {
continue;
}
diff --git a/src/insp_s2s.rs b/src/insp_s2s.rs
index 04b9506..f9bd1d0 100644
--- a/src/insp_s2s.rs
+++ b/src/insp_s2s.rs
@@ -94,7 +94,8 @@ impl ContactManagerManager for InspLink {
fn wa_tx(&mut self) -> &mut UnboundedSender<WhatsappCommand> { &mut self.wa_tx }
fn m_tx(&mut self) -> &mut UnboundedSender<ModemCommand> { &mut self.m_tx }
fn cb_tx(&mut self) -> &mut UnboundedSender<ControlBotCommand> { &mut self.cb_tx }
- fn setup_contact_for(&mut self, recip: Recipient, addr: PduAddress) -> Result<()> {
+ fn setup_contact_for(&mut self, recip: Recipient) -> Result<()> {
+ let addr = recip.phone_number;
trace!("setting up contact for recip #{}: {}", recip.id, addr);
let host = self.host_for_wa(recip.whatsapp);
let nick = match self.check_nick_for_collisions(&recip.nick) {
@@ -609,18 +610,18 @@ impl InspLink {
self.process_groups_for_recipient(&addr)?;
}
for grp in self.store.get_all_groups()? {
- for part in grp.participants {
- if let Some(recip) = self.store.get_recipient_by_id_opt(part)? {
- let num = recip.get_addr()?;
- if let Some(ct) = self.contacts.get(&num) {
- let mode = if grp.admins.contains(&part) {
- "+o"
- }
- else {
- "-o"
- };
- self.outbox.push(Message::new(Some(&self.cfg.sid), "MODE", vec![&grp.channel, mode, &ct.uuid], None)?);
+ let participants = self.store.get_group_members(grp.id)?;
+ // FIXME ugly (see elsewhere)
+ let admins = self.store.get_group_members(grp.id)?;
+ for part in participants {
+ if let Some(ct) = self.contacts.get(&part.phone_number) {
+ let mode = if admins.contains(&part) {
+ "+o"
}
+ else {
+ "-o"
+ };
+ self.outbox.push(Message::new(Some(&self.cfg.sid), "MODE", vec![&grp.channel, mode, &ct.uuid], None)?);
}
}
if self.cfg.set_topics {
@@ -741,27 +742,27 @@ impl InspLink {
};
for msg in self.store.get_all_messages()? {
debug!("Processing message #{}", msg.id);
- let addr = msg.get_addr()?;
- if !self.has_contact(&addr) {
+ let addr = &msg.phone_number;
+ if !self.has_contact(addr) {
if !self.request_contact(addr.clone(), msg.source)? {
continue;
}
}
let (uuid, is_wa) = {
- let ct = self.contacts.get(&addr).unwrap();
+ let ct = self.contacts.get(addr).unwrap();
(ct.uuid.clone(), ct.wa_mode)
};
if msg.pdu.is_some() {
let pdu = DeliverPdu::try_from(msg.pdu.as_ref().unwrap() as &[u8])?;
if is_wa {
- self.set_wa_state(&addr, false)?;
+ self.set_wa_state(addr, false)?;
self.contact_message(&uuid, "NOTICE", &auid, "Notice: SMS mode automatically enabled.")?;
}
self.process_msg_pdu(&uuid, msg, pdu)?;
}
else {
if !is_wa {
- self.set_wa_state(&addr, true)?;
+ self.set_wa_state(addr, true)?;
self.contact_message(&uuid, "NOTICE", &auid, "Notice: WhatsApp mode automatically enabled.")?;
}
self.process_msg_plain(&uuid, msg)?;
diff --git a/src/irc_s2c.rs b/src/irc_s2c.rs
index 92bad19..543b9cc 100644
--- a/src/irc_s2c.rs
+++ b/src/irc_s2c.rs
@@ -250,8 +250,7 @@ impl IrcConnection {
for msg in self.store.get_all_messages()? {
debug!("Processing message #{}", msg.id);
- let addr = msg.get_addr()?;
- let recip = match self.store.get_recipient_by_addr_opt(&addr)? {
+ let recip = match self.store.get_recipient_by_addr_opt(&msg.phone_number)? {
Some(r) => r,
None => {
warn!("stub impl doesn't make new recipients yet");
@@ -272,16 +271,14 @@ impl IrcConnection {
self.reply_from_user("JOIN", vec![&grp.channel], None)?;
self.reply_s2c("332", vec![&grp.channel], Some(&grp.topic as &str))?;
self.reply_s2c("353", vec!["=", &grp.channel], Some(&format!("&{}", self.reginfo.nick) as &str))?;
- let mut recips = Vec::with_capacity(grp.participants.len());
- for id in grp.participants.iter() {
- recips.push(self.store.get_recipient_by_id_opt(*id)?
- .ok_or(format_err!("recipient group wat"))?);
- }
+ let recips = self.store.get_group_members(grp.id)?;
+ // FIXME ugly - should ideally get admin status in some form of JOIN
+ let admins = self.store.get_group_admins(grp.id)?;
for recips in recips.chunks(5) {
let nicks = recips
.iter()
.map(|x| {
- let op = if grp.admins.contains(&x.id) {
+ let op = if admins.contains(&x) {
"@"
}
else {
@@ -356,7 +353,7 @@ impl IrcConnection {
}
else {
if let Some(recip) = self.store.get_recipient_by_nick_opt(&target)? {
- let addr = recip.get_addr()?;
+ let addr = recip.phone_number;
if recip.whatsapp {
self.wa_outbox.push_back(WhatsappCommand::SendDirectMessage(addr, msg));
}
diff --git a/src/main.rs b/src/main.rs
index 8826b3d..90daee0 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,11 +1,9 @@
#![allow(proc_macro_derive_resolution_fallback)]
-#[macro_use] extern crate diesel;
#[macro_use] extern crate serde_derive;
#[macro_use] extern crate failure;
#[macro_use] extern crate log;
#[macro_use] extern crate lazy_static;
-#[macro_use] extern crate diesel_migrations;
extern crate whatsappweb_eta as whatsappweb;
mod config;
@@ -15,7 +13,6 @@ mod modem;
mod comm;
#[macro_use]
mod util;
-mod schema;
mod models;
mod contact;
mod contact_factory;
diff --git a/src/models.rs b/src/models.rs
index 569d7d9..bff70d1 100644
--- a/src/models.rs
+++ b/src/models.rs
@@ -1,19 +1,60 @@
-use crate::schema::{recipients, messages, groups, wa_persistence, wa_msgids};
use serde_json::Value;
use chrono::NaiveDateTime;
use huawei_modem::pdu::PduAddress;
-use crate::util::{self, Result};
+use crate::util;
+use sequelight::traits::*;
+use sequelight::migrations::Migration;
+use sequelight::migration;
+use sequelight::rusqlite;
+use whatsappweb::Jid;
-#[derive(Queryable)]
+pub static MIGRATIONS: [Migration; 1] = [
+ migration!(0, "initial")
+];
+
+#[derive(Debug, PartialEq)]
pub struct Recipient {
- pub id: i32,
- pub phone_number: String,
+ pub id: i64,
+ pub phone_number: PduAddress,
pub nick: String,
pub whatsapp: bool,
pub avatar_url: Option<String>,
pub notify: Option<String>,
pub nicksrc: i32,
}
+impl DbType for Recipient {
+ fn table_name() -> &'static str {
+ "recipients"
+ }
+ fn from_row(row: &Row, s: usize) -> RowResult<Self> {
+ let addr: String = row.get(s + 1)?;
+ // FIXME: a bit hacky, but this is a sequelight limitation really
+ let phone_number = util::un_normalize_address(&addr)
+ .ok_or(rusqlite::Error::InvalidParameterName("invalid pdua in db".into()))?;
+ Ok(Self {
+ id: row.get(s + 0)?,
+ phone_number,
+ nick: row.get(s + 2)?,
+ whatsapp: row.get(s + 3)?,
+ avatar_url: row.get(s + 4)?,
+ notify: row.get(s + 5)?,
+ nicksrc: row.get(s + 6)?,
+ })
+ }
+}
+impl InsertableDbType for Recipient {
+ type Id = i64;
+ fn insert_self(&self, conn: &Connection) -> RowResult<i64> {
+ let mut stmt = conn.prepare("INSERT INTO recipients
+ (phone_number, nick, whatsapp, avatar_url,
+ notify, nicksrc)
+ VALUES (?, ?, ?, ?, ?, ?)")?;
+ let phone_number = util::normalize_address(&self.phone_number);
+ let rid = stmt.insert(params![phone_number, self.nick, self.whatsapp,
+ self.avatar_url, self.notify, self.nicksrc])?;
+ Ok(rid)
+ }
+}
impl Recipient {
/// Nick source: migrated from previous sms-irc install
pub const NICKSRC_MIGRATED: i32 = -1;
@@ -27,86 +68,168 @@ impl Recipient {
pub const NICKSRC_WA_NOTIFY: i32 = 3;
/// Nick source: from a nick collision
pub const NICKSRC_COLLISION: i32 = 4;
- pub fn get_addr(&self) -> Result<PduAddress> {
- let addr = util::un_normalize_address(&self.phone_number)
- .ok_or(format_err!("invalid address {} in db", self.phone_number))?;
- Ok(addr)
- }
}
-#[derive(Insertable)]
-#[table_name="recipients"]
-pub struct NewRecipient<'a> {
- pub phone_number: &'a str,
- pub nick: &'a str,
- pub whatsapp: bool,
- pub avatar_url: Option<&'a str>,
- pub notify: Option<&'a str>,
- pub nicksrc: i32
-}
-#[derive(Queryable, Debug)]
+#[derive(Debug)]
pub struct Message {
- pub id: i32,
- pub phone_number: String,
+ pub id: i64,
+ pub phone_number: PduAddress,
pub pdu: Option<Vec<u8>>,
pub csms_data: Option<i32>,
- pub group_target: Option<i32>,
+ pub group_target: Option<i64>,
pub text: Option<String>,
pub source: i32,
pub ts: NaiveDateTime
}
+impl DbType for Message {
+ fn table_name() -> &'static str {
+ "messages"
+ }
+ fn from_row(row: &Row, s: usize) -> RowResult<Self> {
+ let addr: String = row.get(s + 1)?;
+ // FIXME: a bit hacky, but this is a sequelight limitation really
+ let phone_number = util::un_normalize_address(&addr)
+ .ok_or(rusqlite::Error::InvalidParameterName("invalid pdua in db".into()))?;
+ Ok(Self {
+ id: row.get(s + 0)?,
+ phone_number,
+ pdu: row.get(s + 2)?,
+ csms_data: row.get(s + 3)?,
+ group_target: row.get(s + 4)?,
+ text: row.get(s + 5)?,
+ source: row.get(s + 6)?,
+ ts: row.get(s + 7)?,
+ })
+ }
+}
+impl InsertableDbType for Message {
+ type Id = i64;
+ fn insert_self(&self, conn: &Connection) -> RowResult<i64> {
+ let mut stmt = conn.prepare("INSERT INTO messages
+ (phone_number, pdu, csms_data, group_target,
+ text, source, ts)
+ VALUES (?, ?, ?, ?, ?, ?, ?)")?;
+ let phone_number = util::normalize_address(&self.phone_number);
+ let rid = stmt.insert(params![phone_number, self.pdu, self.csms_data,
+ self.group_target, self.text, self.source, self.ts])?;
+ Ok(rid)
+ }
+}
impl Message {
pub const SOURCE_SMS: i32 = 0;
pub const SOURCE_WA: i32 = 1;
-
- pub fn get_addr(&self) -> Result<PduAddress> {
- let addr = util::un_normalize_address(&self.phone_number)
- .ok_or(format_err!("invalid address {} in db", self.phone_number))?;
- Ok(addr)
- }
}
-#[derive(Queryable, Debug)]
+#[derive(Debug)]
pub struct Group {
- pub id: i32,
- pub jid: String,
+ pub id: i64,
+ pub jid: Jid,
pub channel: String,
- pub participants: Vec<i32>,
- pub admins: Vec<i32>,
pub topic: String
}
-#[derive(Insertable, Queryable, Debug)]
-#[table_name="wa_persistence"]
+impl DbType for Group {
+ fn table_name() -> &'static str {
+ "groups"
+ }
+ fn from_row(row: &Row, s: usize) -> RowResult<Self> {
+ use std::str::FromStr;
+
+ let jid: String = row.get(s + 1)?;
+ let jid = Jid::from_str(&jid)
+ .map_err(|e| rusqlite::Error::InvalidParameterName(e.to_string()))?;
+ Ok(Self {
+ id: row.get(s + 0)?,
+ jid,
+ channel: row.get(s + 2)?,
+ topic: row.get(s + 3)?,
+ })
+ }
+}
+impl InsertableDbType for Group {
+ type Id = i64;
+ fn insert_self(&self, conn: &Connection) -> RowResult<i64> {
+ let mut stmt = conn.prepare("INSERT INTO groups
+ (jid, channel, topic)
+ VALUES (?, ?, ?)")?;
+ let jid = self.jid.to_string();
+ let rid = stmt.insert(params![jid, self.channel, self.topic])?;
+ Ok(rid)
+ }
+}
+#[derive(Debug)]
+pub struct GroupMembership {
+ pub group_id: i64,
+ pub user_id: i64,
+ pub is_admin: bool
+}
+impl DbType for GroupMembership {
+ fn table_name() -> &'static str {
+ "group_memberships"
+ }
+ fn from_row(row: &Row, s: usize) -> RowResult<Self> {
+ Ok(Self {
+ group_id: row.get(s + 0)?,
+ user_id: row.get(s + 1)?,
+ is_admin: row.get(s + 2)?,
+ })
+ }
+}
+impl InsertableDbType for GroupMembership {
+ type Id = i64;
+ fn insert_self(&self, conn: &Connection) -> RowResult<i64> {
+ let mut stmt = conn.prepare("INSERT INTO group_memberships
+ (group_id, user_id, is_admin)
+ VALUES (?, ?, ?)")?;
+ let rid = stmt.insert(params![self.group_id, self.user_id, self.is_admin])?;
+ Ok(rid)
+ }
+}
+#[derive(Debug)]
pub struct PersistenceData {
- pub rev: i32,
+ pub rev: i64,
pub data: Value
}
-#[derive(Insertable, Queryable, Debug)]
-#[table_name="wa_msgids"]
+impl DbType for PersistenceData {
+ fn table_name() -> &'static str {
+ "wa_persistence"
+ }
+ fn from_row(row: &Row, s: usize) -> RowResult<Self> {
+ Ok(Self {
+ rev: row.get(s + 0)?,
+ data: row.get(s + 1)?,
+ })
+ }
+}
+impl InsertableDbType for PersistenceData {
+ type Id = i64;
+ fn insert_self(&self, conn: &Connection) -> RowResult<i64> {
+ let mut stmt = conn.prepare("INSERT INTO wa_persistence
+ (rev, data)
+ VALUES (?, ?)
+ ON CONFLICT (rev) DO UPDATE SET data = excluded.data")?;
+ let rid = stmt.insert(params![self.rev, self.data])?;
+ Ok(rid)
+ }
+}
+#[derive(Debug)]
pub struct WaMessageId {
pub mid: String
}
-#[derive(Insertable)]
-#[table_name="groups"]
-pub struct NewGroup<'a> {
- pub jid: &'a str,
- pub channel: &'a str,
- pub participants: Vec<i32>,
- pub admins: Vec<i32>,
- pub topic: &'a str
-}
-#[derive(Insertable)]
-#[table_name="messages"]
-pub struct NewMessage<'a> {
- pub phone_number: &'a str,
- pub pdu: &'a [u8],
- pub csms_data: Option<i32>,
- pub source: i32,
+impl DbType for WaMessageId {
+ fn table_name() -> &'static str {
+ "wa_msgid"
+ }
+ fn from_row(row: &Row, s: usize) -> RowResult<Self> {
+ Ok(Self {
+ mid: row.get(s + 0)?,
+ })
+ }
}
-#[derive(Insertable)]
-#[table_name="messages"]
-pub struct NewPlainMessage<'a> {
- pub phone_number: &'a str,
- pub group_target: Option<i32>,
- pub text: &'a str,
- pub source: i32,
- pub ts: NaiveDateTime
+impl InsertableDbType for WaMessageId {
+ type Id = i64;
+ fn insert_self(&self, conn: &Connection) -> RowResult<i64> {
+ let mut stmt = conn.prepare("INSERT INTO wa_msgid
+ (mid)
+ VALUES (?)")?;
+ let rid = stmt.insert(params![self.mid])?;
+ Ok(rid)
+ }
}
diff --git a/src/sender_common.rs b/src/sender_common.rs
index 242bd41..c9c3a11 100644
--- a/src/sender_common.rs
+++ b/src/sender_common.rs
@@ -22,7 +22,7 @@ pub trait Sender {
fn ensure_joined(&mut self, _ch: &str) -> Result<()> {
Ok(())
}
- fn send_raw_message(&mut self, from_nick: &str, msg: &str, group_target: Option<i32>) -> Result<()> {
+ fn send_raw_message(&mut self, from_nick: &str, msg: &str, group_target: Option<i64>) -> Result<()> {
let dest = if let Some(g) = group_target {
let grp = self.store().get_group_by_id(g)?;
self.ensure_joined(&grp.channel)?;
diff --git a/src/store.rs b/src/store.rs
index b8693af..94c1876 100644
--- a/src/store.rs
+++ b/src/store.rs
@@ -1,143 +1,118 @@
//! Handles database stuff.
-use diesel::PgConnection;
-use r2d2_diesel::ConnectionManager;
-use r2d2::Pool;
use crate::config::Config;
-use std::sync::Arc;
use huawei_modem::pdu::PduAddress;
-use diesel::prelude::*;
use serde_json;
use whatsappweb::session::PersistentSession;
use whatsappweb::Jid;
use crate::util::{self, Result};
-use chrono::NaiveDateTime;
-use regex::Regex;
+use chrono::{NaiveDateTime, Utc};
use crate::models::*;
-
-embed_migrations!();
+use sequelight::traits::*;
+use sequelight::{LightPool, LightConnectionManager};
+use sequelight::r2d2::Pool;
+use std::sync::Arc;
#[derive(Clone)]
pub struct Store {
- inner: Arc<Pool<ConnectionManager<PgConnection>>>
+ inner: Arc<LightPool>,
}
impl Store {
pub fn new(cfg: &Config) -> Result<Self> {
- let manager = ConnectionManager::new(cfg.database_url.clone());
+ let manager = LightConnectionManager::initialize(cfg.database_url.clone(), &MIGRATIONS)?;
let pool = Pool::builder()
.build(manager)?;
- embedded_migrations::run(&*pool.get()?)?;
- let mut ret = Self {
+ Ok(Self {
inner: Arc::new(pool)
- };
- let sourceless = ret.get_recipients_with_nicksrc(Recipient::NICKSRC_MIGRATED)?;
- if sourceless.len() > 0 {
- warn!("Adding nickname sources for migrated recipients");
- // Use heuristics to match nicknames which look like they've been
- // automatically generated
- lazy_static! {
- static ref DEFAULT_RE: Regex = Regex::new(r#"I\d+"#).unwrap();
- }
- for r in sourceless {
- let addr = r.get_addr()?;
- let newsrc = if DEFAULT_RE.is_match(&r.nick) {
- Recipient::NICKSRC_AUTO
- }
- else {
- // We can't assume much, so set to NICKSRC_USER so
- // nothing overwrites it
- Recipient::NICKSRC_USER
- };
- ret.update_recipient_nick(&addr, &r.nick, newsrc)?;
- }
- }
- Ok(ret)
+ })
}
+ // FIXME pass by-value here instead of cloning (well, everywhere really)
pub fn store_sms_message(&mut self, addr: &PduAddress, pdu: &[u8], csms_data: Option<i32>) -> Result<Message> {
- use crate::schema::messages;
-
- let num = util::normalize_address(addr);
- let nm = NewMessage {
- phone_number: &num,
- pdu,
+ let db = self.inner.get()?;
+ let mut msg = Message {
+ id: -1,
+ phone_number: addr.clone(),
+ pdu: Some(pdu.to_owned()),
csms_data,
- source: Message::SOURCE_SMS
+ group_target: None,
+ text: None,
+ source: Message::SOURCE_SMS,
+ ts: Utc::now().naive_utc()
};
- let conn = self.inner.get()?;
-
- let res = ::diesel::insert_into(messages::table)
- .values(&nm)
- .get_result(&*conn)?;
- Ok(res)
+ msg.id = msg.insert_self(&db)?;
+ Ok(msg)
}
- pub fn store_wa_message(&mut self, addr: &PduAddress, text: &str, group_target: Option<i32>, ts: NaiveDateTime) -> Result<Message> {
- use crate::schema::messages;
-
- let num = util::normalize_address(addr);
- let nm = NewPlainMessage {
- phone_number: &num,
- text,
+ pub fn store_wa_message(&mut self, addr: &PduAddress, text: &str, group_target: Option<i64>, ts: NaiveDateTime) -> Result<Message> {
+ let db = self.inner.get()?;
+ let mut msg = Message {
+ id: -1,
+ phone_number: addr.clone(),
+ pdu: None,
+ csms_data: None,
group_target,
+ text: Some(text.to_owned()),
source: Message::SOURCE_WA,
ts
};
- let conn = self.inner.get()?;
-
- let res = ::diesel::insert_into(messages::table)
- .values(&nm)
- .get_result(&*conn)?;
- Ok(res)
+ msg.id = msg.insert_self(&db)?;
+ Ok(msg)
}
pub fn store_wa_persistence(&mut self, p: PersistentSession) -> Result<()> {
- use crate::schema::wa_persistence;
- use crate::schema::wa_persistence::dsl::*;
-
+ let db = self.inner.get()?;
let pdata = serde_json::to_value(&p)?;
let pdata = PersistenceData {
rev: 0,
data: pdata
};
- let conn = self.inner.get()?;
-
- ::diesel::insert_into(wa_persistence::table)
- .values(&pdata)
- .on_conflict(rev)
- .do_update()
- .set(data.eq(::diesel::pg::upsert::excluded(data)))
- .execute(&*conn)?;
+ pdata.insert_self(&db)?;
Ok(())
}
- pub fn store_group(&mut self, jid: &Jid, channel: &str, participants: Vec<i32>, admins: Vec<i32>, topic: &str) -> Result<Group> {
- use crate::schema::groups;
- let jid = jid.to_string();
- let newgrp = NewGroup {
- jid: &jid,
- channel, participants, admins, topic
+ pub fn store_group(&mut self, jid: &Jid, channel: &str, topic: &str) -> Result<Group> {
+ let db = self.inner.get()?;
+ let mut grp = Group {
+ id: -1,
+ jid: jid.clone(),
+ channel: channel.to_owned(),
+ topic: topic.to_owned()
};
- let conn = self.inner.get()?;
-
- let res = ::diesel::insert_into(groups::table)
- .values(&newgrp)
- .get_result(&*conn)?;
+ grp.id = grp.insert_self(&db)?;
+ Ok(grp)
+ }
+ pub fn update_group_members(&mut self, id: i64, members: Vec<i64>, admins: Vec<i64>) -> Result<()> {
+ let mut db = self.inner.get()?;
+ let trans = db.transaction()?;
+ trans.execute("DELETE FROM group_memberships WHERE group_id = ?", params![id])?;
+ for memb in members {
+ GroupMembership {
+ group_id: id,
+ user_id: memb,
+ is_admin: admins.contains(&memb)
+ }.insert_self(&trans)?;
+ }
+ trans.commit()?;
+ Ok(())
+ }
+ pub fn get_group_members(&mut self, id: i64) -> Result<Vec<Recipient>> {
+ let db = self.inner.get()?;
+ let res = Recipient::from_select(&db, "INNER JOIN group_memberships AS gm ON gm.user_id = recipients.id WHERE gm.group_id = ? AND gm.is_admin = false", params![id])?;
Ok(res)
}
- pub fn update_group(&mut self, j: &Jid, parts: Vec<i32>, adms: Vec<i32>, tpc: &str) -> Result<Group> {
- use crate::schema::groups::dsl::*;
- let j = j.to_string();
- let conn = self.inner.get()?;
-
- let res = ::diesel::update(groups.filter(jid.eq(&j)))
- .set((participants.eq(parts), admins.eq(adms), topic.eq(tpc)))
- .get_result(&*conn)?;
+ pub fn get_group_admins(&mut self, id: i64) -> Result<Vec<Recipient>> {
+ let db = self.inner.get()?;
+ let res = Recipient::from_select(&db, "INNER JOIN group_memberships AS gm ON gm.user_id = recipients.id WHERE gm.group_id = ? AND gm.is_admin = true", params![id])?;
Ok(res)
}
+ pub fn update_group_topic(&mut self, id: i64, tpc: &str) -> Result<()> {
+ let db = self.inner.get()?;
+ db.execute("UPDATE groups SET topic = ? WHERE id = ?", params![id, tpc])?;
+ Ok(())
+ }
pub fn get_wa_persistence_opt(&mut self) -> Result<Option<PersistentSession>> {
- use crate::schema::wa_persistence::dsl::*;
- let conn = self.inner.get()?;
- let res: Option<PersistenceData> = wa_persistence.filter(rev.eq(0))
- .first(&*conn)
- .optional()?;
- let res = match res {
+ let db = self.inner.get()?;
+ let pd = PersistenceData::from_select(&db, "WHERE rev = 0", NO_PARAMS)?
+ .into_iter()
+ .nth(0);
+ let res = match pd {
Some(res) => {
let res: PersistentSession = serde_json::from_value(res.data)?;
Some(res)
@@ -147,244 +122,160 @@ impl Store {
Ok(res)
}
pub fn is_wa_msgid_stored(&mut self, id: &str) -> Result<bool> {
- use crate::schema::wa_msgids::dsl::*;
- let conn = self.inner.get()?;
- let res: Option<WaMessageId> = wa_msgids.filter(mid.eq(id))
- .first(&*conn)
- .optional()?;
- Ok(res.is_some())
+ let db = self.inner.get()?;
+ let msgids = WaMessageId::from_select(&db, "WHERE mid = ?", params![id])?;
+ Ok(msgids.len() > 0)
}
pub fn store_wa_msgid(&mut self, id: String) -> Result<()> {
- use crate::schema::wa_msgids;
-
+ let db = self.inner.get()?;
let new = WaMessageId { mid: id };
- let conn = self.inner.get()?;
-
- ::diesel::insert_into(wa_msgids::table)
- .values(&new)
- .on_conflict(wa_msgids::dsl::mid)
- .do_nothing()
- .execute(&*conn)?;
+ new.insert_self(&db)?;
Ok(())
}
pub fn store_recipient(&mut self, addr: &PduAddress, nick: &str) -> Result<Recipient> {
- use crate::schema::recipients;
-
- let num = util::normalize_address(addr);
- let nr = NewRecipient {
- phone_number: &num,
- nick,
+ let db = self.inner.get()?;
+ let mut recip = Recipient {
+ id: -1,
+ phone_number: addr.clone(),
+ nick: nick.to_owned(),
whatsapp: false,
avatar_url: None,
notify: None,
nicksrc: Recipient::NICKSRC_AUTO
};
- let conn = self.inner.get()?;
-
- let res = ::diesel::insert_into(recipients::table)
- .values(&nr)
- .get_result(&*conn)?;
- Ok(res)
+ recip.id = recip.insert_self(&db)?;
+ Ok(recip)
}
pub fn store_wa_recipient(&mut self, addr: &PduAddress, nick: &str, notify: Option<&str>, nicksrc: i32) -> Result<Recipient> {
- use crate::schema::recipients;
-
- let num = util::normalize_address(addr);
- let nr = NewRecipient {
- phone_number: &num,
- nick,
+ let db = self.inner.get()?;
+ let mut recip = Recipient {
+ id: -1,
+ phone_number: addr.clone(),
+ nick: nick.to_owned(),
whatsapp: true,
avatar_url: None,
- notify: notify,
+ notify: notify.map(|x| x.to_owned()),
nicksrc
};
- let conn = self.inner.get()?;
-
- let res = ::diesel::insert_into(recipients::table)
- .values(&nr)
- .get_result(&*conn)?;
- Ok(res)
+ recip.id = recip.insert_self(&db)?;
+ Ok(recip)
}
pub fn update_recipient_notify(&mut self, addr: &PduAddress, n: Option<&str>) -> Result<()> {
- use crate::schema::recipients::dsl::*;
- let conn = self.inner.get()?;
- let num = util::normalize_address(addr);
-
- ::diesel::update(recipients)
- .filter(phone_number.eq(num))
- .set(notify.eq(n))
- .execute(&*conn)?;
+ let db = self.inner.get()?;
+ let addr = util::normalize_address(addr);
+ db.execute("UPDATE recipients SET notify = ? WHERE phone_number = ?", params![n, addr])?;
Ok(())
}
pub fn update_recipient_nick(&mut self, addr: &PduAddress, n: &str, src: i32) -> Result<()> {
- use crate::schema::recipients::dsl::*;
- let conn = self.inner.get()?;
- let num = util::normalize_address(addr);
-
- ::diesel::update(recipients)
- .filter(phone_number.eq(num))
- .set((nick.eq(n), nicksrc.eq(src)))
- .execute(&*conn)?;
+ let db = self.inner.get()?;
+ let addr = util::normalize_address(addr);
+ db.execute("UPDATE recipients SET nick = ?, nicksrc = ? WHERE phone_number = ?", params![n, src, addr])?;
Ok(())
}
pub fn update_recipient_wa(&mut self, addr: &PduAddress, wa: bool) -> Result<()> {
- use crate::schema::recipients::dsl::*;
- let conn = self.inner.get()?;
- let num = util::normalize_address(addr);
-
- ::diesel::update(recipients)
- .filter(phone_number.eq(num))
- .set(whatsapp.eq(wa))
- .execute(&*conn)?;
+ let db = self.inner.get()?;
+ let addr = util::normalize_address(addr);
+ db.execute("UPDATE recipients SET whatsapp = ? WHERE phone_number = ?", params![wa, addr])?;
Ok(())
}
- pub fn get_recipient_by_id_opt(&mut self, i: i32) -> Result<Option<Recipient>> {
- use crate::schema::recipients::dsl::*;
- let conn = self.inner.get()?;
-
- let res = recipients.filter(id.eq(i))
- .first(&*conn)
- .optional()?;
- Ok(res)
- }
pub fn get_recipient_by_nick_opt(&mut self, n: &str) -> Result<Option<Recipient>> {
- use crate::schema::recipients::dsl::*;
- let conn = self.inner.get()?;
-
- let res = recipients.filter(nick.eq(n))
- .first(&*conn)
- .optional()?;
+ let db = self.inner.get()?;
+ let res = Recipient::from_select(&db, "WHERE nick = ?", params![n])?
+ .into_iter()
+ .nth(0);
Ok(res)
}
pub fn get_recipient_by_addr_opt(&mut self, addr: &PduAddress) -> Result<Option<Recipient>> {
- use crate::schema::recipients::dsl::*;
- let conn = self.inner.get()?;
-
+ let db = self.inner.get()?;
let num = util::normalize_address(addr);
- let res = recipients.filter(phone_number.eq(num))
- .first(&*conn)
- .optional()?;
+ let res = Recipient::from_select(&db, "WHERE phone_number = ?", params![num])?
+ .into_iter()
+ .nth(0);
Ok(res)
}
pub fn get_all_recipients(&mut self) -> Result<Vec<Recipient>> {
- use crate::schema::recipients::dsl::*;
- let conn = self.inner.get()?;
-
- let res = recipients
- .load(&*conn)?;
- Ok(res)
- }
- pub fn get_recipients_with_nicksrc(&mut self, ns: i32) -> Result<Vec<Recipient>> {
- use crate::schema::recipients::dsl::*;
- let conn = self.inner.get()?;
+ let db = self.inner.get()?;
- let res = recipients
- .filter(nicksrc.eq(ns))
- .load(&*conn)?;
+ let res = Recipient::from_select(&db, "", NO_PARAMS)?;
Ok(res)
}
pub fn get_all_messages(&mut self) -> Result<Vec<Message>> {
- use crate::schema::messages::dsl::*;
- let conn = self.inner.get()?;
+ let db = self.inner.get()?;
- let res = messages
- .order((ts.asc(), id.asc()))
- .load(&*conn)?;
+ let res = Message::from_select(&db, "ORDER BY ts, id ASC", NO_PARAMS)?;
Ok(res)
}
- pub fn get_group_by_id(&mut self, gid: i32) -> Result<Group> {
- use crate::schema::groups::dsl::*;
- let conn = self.inner.get()?;
+ pub fn get_group_by_id(&mut self, gid: i64) -> Result<Group> {
+ let db = self.inner.get()?;
- let res = groups.filter(id.eq(gid))
- .first(&*conn)?;
+ let res = Group::from_select(&db, "WHERE id = ?", params![gid])?
+ .into_iter().nth(0)
+ .ok_or(format_err!("group not found"))?;
Ok(res)
}
pub fn get_all_groups(&mut self) -> Result<Vec<Group>> {
- use crate::schema::groups::dsl::*;
let conn = self.inner.get()?;
- let res = groups
- .load(&*conn)?;
+ let res = Group::from_select(&conn, "", NO_PARAMS)?;
Ok(res)
}
pub fn get_group_by_jid_opt(&mut self, j: &Jid) -> Result<Option<Group>> {
- use crate::schema::groups::dsl::*;
+ let db = self.inner.get()?;
let j = j.to_string();
- let conn = self.inner.get()?;
-
- let res = groups.filter(jid.eq(j))
- .first(&*conn)
- .optional()?;
+ let res = Group::from_select(&db, "WHERE jid = ?", params![j])?
+ .into_iter().nth(0);
Ok(res)
}
pub fn get_group_by_chan_opt(&mut self, c: &str) -> Result<Option<Group>> {
- use crate::schema::groups::dsl::*;
- let conn = self.inner.get()?;
-
- let res = groups.filter(channel.eq(c))
- .first(&*conn)
- .optional()?;
+ let db = self.inner.get()?;
+ let res = Group::from_select(&db, "WHERE channel = ?", params![c])?
+ .into_iter().nth(0);
Ok(res)
}
pub fn get_groups_for_recipient(&mut self, addr: &PduAddress) -> Result<Vec<Group>> {
- use crate::schema::groups::dsl::*;
- let r = self.get_recipient_by_addr_opt(addr)?
- .ok_or(format_err!("get_groups_for_recipient couldn't find recipient"))?;
- let conn = self.inner.get()?;
-
- let res = groups.filter(participants.contains(vec![r.id]))
- .load(&*conn)?;
+ let db = self.inner.get()?;
+ let num = util::normalize_address(addr);
+ let res = Group::from_select(&db, "INNER JOIN group_memberships AS gm ON gm.group_id = groups.id INNER JOIN recipients AS r ON gm.user_id = r.id WHERE r.phone_number = ?",
+ params![num])?;
Ok(res)
}
pub fn get_messages_for_recipient(&mut self, addr: &PduAddress) -> Result<Vec<Message>> {
- use crate::schema::messages::dsl::*;
- let conn = self.inner.get()?;
+ let db = self.inner.get()?;
let num = util::normalize_address(addr);
- let res = messages.filter(phone_number.eq(num))
- .order((ts.asc(), id.asc()))
- .load(&*conn)?;
+ let res = Message::from_select(&db, "WHERE phone_number = ? ORDER BY ts, id ASC", params![num])?;
Ok(res)
}
- pub fn get_all_concatenated(&mut self, num: &str, rf: i32) -> Result<Vec<Message>> {
- use crate::schema::messages::dsl::*;
- let conn = self.inner.get()?;
+ pub fn get_all_concatenated(&mut self, addr: &PduAddress, rf: i32) -> Result<Vec<Message>> {
+ let db = self.inner.get()?;
+ let num = util::normalize_address(addr);
- let res = messages.filter(csms_data.eq(rf)
- .and(phone_number.eq(num)))
- .load(&*conn)?;
+ let res = Message::from_select(&db, "WHERE csms_data = ? AND phone_number = ?", params![rf, num])?;
Ok(res)
}
- pub fn delete_group_with_id(&mut self, i: i32) -> Result<()> {
- use crate::schema::groups::dsl::*;
+ pub fn delete_group_with_id(&mut self, i: i64) -> Result<()> {
let conn = self.inner.get()?;
- let rows_affected = ::diesel::delete(groups.filter(id.eq(i)))
- .execute(&*conn)?;
+ let rows_affected = conn.execute("DELETE FROM groups WHERE id = ?", params![i])?;
if rows_affected == 0 {
return Err(format_err!("no rows affected deleting gid {}", i));
}
Ok(())
}
pub fn delete_recipient_with_addr(&mut self, addr: &PduAddress) -> Result<()> {
- use crate::schema::recipients::dsl::*;
let conn = self.inner.get()?;
let num = util::normalize_address(addr);
- let rows_affected = ::diesel::delete(recipients.filter(phone_number.eq(num)))
- .execute(&*conn)?;
+ let rows_affected = conn.execute("DELETE FROM recipients WHERE phone_number = ?", params![num])?;
if rows_affected == 0 {
return Err(format_err!("no rows affected deleting recip {}", addr));
}
Ok(())
}
- pub fn delete_message(&mut self, mid: i32) -> Result<()> {
- use crate::schema::messages::dsl::*;
+ pub fn delete_message(&mut self, mid: i64) -> Result<()> {
let conn = self.inner.get()?;
- let rows_affected = ::diesel::delete(messages.filter(id.eq(mid)))
- .execute(&*conn)?;
+ let rows_affected = conn.execute("DELETE FROM messages WHERE id = ?", params![mid])?;
if rows_affected == 0 {
return Err(format_err!("no rows affected deleting mid #{}", mid));
}
diff --git a/src/whatsapp.rs b/src/whatsapp.rs
index 3f2da80..e7bbda7 100644
--- a/src/whatsapp.rs
+++ b/src/whatsapp.rs
@@ -309,7 +309,7 @@ impl WhatsappManager {
debug!("Sending message to group with chan {}...", chan);
trace!("Message contents: {}", content);
if let Some(grp) = self.store.get_group_by_chan_opt(&chan)? {
- let jid = grp.jid.parse().expect("bad jid in DB");
+ let jid = grp.jid;
let content = ChatMessageContent::Text(content);
if !self.connected || !self.conn.is_connected() {
self.queue_message(content, jid);
@@ -422,7 +422,7 @@ impl WhatsappManager {
}
Ok(())
}
- fn store_message(&mut self, from: &Jid, text: &str, group: Option<i32>, ts: NaiveDateTime) -> Result<()> {
+ fn store_message(&mut self, from: &Jid, text: &str, group: Option<i64>, ts: NaiveDateTime) -> Result<()> {
if let Some(addr) = util::jid_to_address(from) {
let _ = self.get_wa_recipient(from)?;
self.store.store_wa_message(&addr, &text, group, ts)?;
@@ -501,25 +501,31 @@ impl WhatsappManager {
}
}
fn on_got_group_metadata(&mut self, grp: GroupMetadata) -> Result<()> {
- match self.store.get_group_by_jid_opt(&grp.id)? {
+ let id = match self.store.get_group_by_jid_opt(&grp.id)? {
Some(g) => {
- info!("Got metadata for group '{}' (jid {}, id {})", grp.subject, grp.id, g.id);
+ debug!("Got metadata for group '{}' (jid {}, id {})", grp.subject, grp.id, g.id);
+ g.id
},
None => {
- warn!("Got metadata for unbridged group '{}' (jid {})", grp.subject, grp.id);
if self.autocreate.is_some() {
match self.group_autocreate(grp.clone()) {
Ok((id, chan)) => {
self.cb_respond(format!("Automatically bridged new group '{}' to channel {} (id {})", grp.subject, chan, id));
+ id
},
Err(e) => {
warn!("Autocreation failed for group {}: {}", grp.id, e);
self.cb_respond(format!("Failed to autocreate new group {} - check logs for details.", grp.id));
+ return Ok(());
}
}
}
+ else {
+ warn!("Got metadata for unbridged group '{}' (jid {})", grp.subject, grp.id);
+ return Ok(());
+ }
}
- }
+ };
let mut participants = vec![];
let mut admins = vec![];
for &(ref jid, admin) in grp.participants.iter() {
@@ -529,16 +535,15 @@ impl WhatsappManager {
admins.push(recip.id);
}
}
- self.store.update_group(&grp.id, participants, admins, &grp.subject)?;
+ self.store.update_group_topic(id, &grp.subject)?;
+ self.store.update_group_members(id, participants, admins)?;
self.on_groups_changed();
Ok(())
}
fn group_update_all(&mut self) -> Result<()> {
info!("Updating metadata for ALL groups");
for grp in self.store.get_all_groups()? {
- if let Ok(j) = grp.jid.parse() {
- self.request_update_group(j)?;
- }
+ self.request_update_group(grp.jid)?;
}
Ok(())
}
@@ -569,7 +574,7 @@ impl WhatsappManager {
///
/// Here, we have to hope that we've got data in our initial chat list for this group;
/// otherwise, we can't know the subject of the group in order to autocreate it.
- fn group_autocreate_from_unbridged(&mut self, jid: Jid) -> Result<i32> {
+ fn group_autocreate_from_unbridged(&mut self, jid: Jid) -> Result<i64> {
let chat = match self.chats.get(&jid) {
Some(c) => c.clone(),
None => bail!("chat not in chat list")
@@ -583,14 +588,14 @@ impl WhatsappManager {
let id = self.group_associate(jid, chan.clone(), true)?;
Ok(id)
}
- fn group_autocreate(&mut self, meta: GroupMetadata) -> Result<(i32, String)> {
+ fn group_autocreate(&mut self, meta: GroupMetadata) -> Result<(i64, String)> {
let irc_subject = util::string_to_irc_chan(&meta.subject);
let chan = format!("{}-{}", self.autocreate.as_ref().unwrap(), irc_subject);
let id = self.group_associate(meta.id.clone(), chan.clone(), false)?;
self.on_got_group_metadata(meta)?;
Ok((id, chan))
}
- fn group_associate(&mut self, jid: Jid, chan: String, request_update: bool) -> Result<i32> {
+ fn group_associate(&mut self, jid: Jid, chan: String, request_update: bool) -> Result<i64> {
if let Some(grp) = self.store.get_group_by_jid_opt(&jid)? {
bail!("that group already exists (channel {})!", grp.channel);
}
@@ -604,7 +609,7 @@ impl WhatsappManager {
bail!("that jid isn't a group!");
}
info!("Bridging WA group {} to channel {}", jid, chan);
- let grp = self.store.store_group(&jid, &chan, vec![], vec![], "*** Group setup in progress, please wait... ***")?;
+ let grp = self.store.store_group(&jid, &chan, "*** Group setup in progress, please wait... ***")?;
if request_update {
self.request_update_group(jid)?;
}
diff --git a/src/whatsapp_media.rs b/src/whatsapp_media.rs
index c2fa707..809ef1d 100644
--- a/src/whatsapp_media.rs
+++ b/src/whatsapp_media.rs
@@ -33,7 +33,7 @@ pub struct MediaInfo {
pub mi: MessageId,
pub peer: Option<Peer>,
pub from: Jid,
- pub group: Option<i32>,
+ pub group: Option<i64>,
pub path: String,
pub dl_path: String,
pub tx: Arc<UnboundedSender<WhatsappCommand>>,
@@ -42,7 +42,7 @@ pub struct MediaInfo {
}
pub struct MediaResult {
pub from: Jid,
- pub group: Option<i32>,
+ pub group: Option<i64>,
pub mi: MessageId,
pub peer: Option<Peer>,
pub ts: NaiveDateTime,
diff --git a/src/whatsapp_msg.rs b/src/whatsapp_msg.rs
index de5aded..98d9599 100644
--- a/src/whatsapp_msg.rs
+++ b/src/whatsapp_msg.rs
@@ -18,7 +18,7 @@ pub struct IncomingMessage {
pub id: MessageId,
pub peer: Option<Peer>,
pub from: Jid,
- pub group: Option<i32>,
+ pub group: Option<i64>,
pub content: ChatMessageContent,
pub quoted: Option<QuotedChatMessage>,
pub ts: NaiveDateTime
@@ -26,7 +26,7 @@ pub struct IncomingMessage {
pub struct ProcessedIncomingMessage {
pub from: Jid,
pub text: String,
- pub group: Option<i32>,
+ pub group: Option<i64>,
pub ts: NaiveDateTime
}
pub struct WaMessageProcessor {
@@ -37,7 +37,7 @@ pub struct WaMessageProcessor {
}
impl WaMessageProcessor {
- fn process_incoming_media(&mut self, id: MessageId, peer: Option<Peer>, from: Jid, group: Option<i32>, ct: ChatMessageContent, ts: NaiveDateTime) -> Result<()> {
+ fn process_incoming_media(&mut self, id: MessageId, peer: Option<Peer>, from: Jid, group: Option<i64>, ct: ChatMessageContent, ts: NaiveDateTime) -> Result<()> {
let (ty, fi, name) = match ct {
ChatMessageContent::Image { info, .. } => (MediaType::Image, info, None),