Browse Source

add avatar support, linking in to a Quassel database (beta)

master
eeeeeta 3 years ago
parent
commit
616b03a84e
  1. 192
      Cargo.lock
  2. 1
      Cargo.toml
  3. 1
      migrations/20190217093945_avatars/down.sql
  4. 1
      migrations/20190217093945_avatars/up.sql
  5. 6
      src/comm.rs
  6. 4
      src/config.rs
  7. 5
      src/contact_factory.rs
  8. 45
      src/insp_s2s.rs
  9. 14
      src/main.rs
  10. 6
      src/models.rs
  11. 1
      src/schema.rs
  12. 23
      src/store.rs
  13. 51
      src/whatsapp.rs

192
Cargo.lock generated

@ -21,6 +21,11 @@ name = "arc-swap" @@ -21,6 +21,11 @@ name = "arc-swap"
version = "0.3.7"
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.7"
@ -50,6 +55,15 @@ dependencies = [ @@ -50,6 +55,15 @@ dependencies = [
"libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "base64"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.2.6 (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"
@ -73,6 +87,15 @@ name = "bitflags" @@ -73,6 +87,15 @@ name = "bitflags"
version = "1.0.4"
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"
@ -83,6 +106,11 @@ name = "build_const" @@ -83,6 +106,11 @@ name = "build_const"
version = "0.2.1"
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.2.6"
@ -135,6 +163,11 @@ name = "color_quant" @@ -135,6 +163,11 @@ name = "color_quant"
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 = "core-foundation"
version = "0.5.1"
@ -223,6 +256,15 @@ name = "crossbeam-utils" @@ -223,6 +256,15 @@ name = "crossbeam-utils"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[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.19"
@ -283,6 +325,14 @@ dependencies = [ @@ -283,6 +325,14 @@ dependencies = [
"syn 0.13.11 (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.3"
@ -395,6 +445,16 @@ dependencies = [ @@ -395,6 +445,16 @@ dependencies = [
"synstructure 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "fake-simd"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "fallible-iterator"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "flate2"
version = "1.0.3"
@ -455,6 +515,14 @@ name = "gcc" @@ -455,6 +515,14 @@ name = "gcc"
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 = "gif"
version = "0.10.1"
@ -489,6 +557,20 @@ dependencies = [ @@ -489,6 +557,20 @@ dependencies = [
"unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[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.13"
@ -771,6 +853,11 @@ name = "matches" @@ -771,6 +853,11 @@ name = "matches"
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"
@ -1137,6 +1224,48 @@ dependencies = [ @@ -1137,6 +1224,48 @@ dependencies = [
"num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "postgres"
version = "0.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bytes 0.4.10 (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.5 (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.8 (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.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.10 (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.22 (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.23 (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 = "pq-sys"
version = "0.4.6"
@ -1446,6 +1575,11 @@ name = "ryu" @@ -1446,6 +1575,11 @@ name = "ryu"
version = "0.2.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.0"
@ -1577,6 +1711,17 @@ name = "sha1" @@ -1577,6 +1711,17 @@ name = "sha1"
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.7"
@ -1635,6 +1780,7 @@ dependencies = [ @@ -1635,6 +1780,7 @@ dependencies = [
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"log4rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"mime_guess 2.0.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)",
"postgres 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)",
"qrcode 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"r2d2 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"r2d2-diesel 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1652,6 +1798,17 @@ dependencies = [ @@ -1652,6 +1798,17 @@ dependencies = [
"whatsappweb 0.0.2 (git+https://github.com/eeeeeta/whatsappweb-rs)",
]
[[package]]
name = "socket2"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "spin"
version = "0.5.0"
@ -1667,6 +1824,15 @@ name = "string" @@ -1667,6 +1824,15 @@ name = "string"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[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.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "syn"
version = "0.11.11"
@ -2020,6 +2186,11 @@ dependencies = [ @@ -2020,6 +2186,11 @@ dependencies = [
"unsafe-any 0.4.2 (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.1"
@ -2242,14 +2413,18 @@ dependencies = [ @@ -2242,14 +2413,18 @@ dependencies = [
"checksum aho-corasick 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "68f56c7353e5a9547cbd76ed90f7bb5ffc3ba09d4ea9bd1d8c06c8b1142eeb5a"
"checksum antidote 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "34fde25430d87a9388dadbe6e34d7f72a462c8b43ac8d309b42b0a8505d7e2a5"
"checksum arc-swap 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1025aeae2b664ca0ea726a89d574fe8f4e77dd712d443236ad1de00379450cf6"
"checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee"
"checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef"
"checksum backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "89a47830402e9981c5c41223151efcced65a0510c13097c769cede7efb34782a"
"checksum backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)" = "c66d56ac8dabd07f6aacdaf633f4b8262f5b3601a810a0dcddffd5c22c69daa0"
"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.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9f2fb9e29e72fd6bc12071533d5dc7664cb01480c59406f656d7ac25c7bd8ff7"
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
"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 build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39"
"checksum byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "560c32574a12a89ecd91f5e742165893f86e3ab98d21f8ea548658eb9eef5f40"
"checksum byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "90492c5858dd7d2e78691cfb89f90d273a2800fc11d98f60786e5d87e2f83781"
"checksum bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0ce55bd354b095246fc34caf4e9e242f5297a7fd938b090cadfea6eee614aa62"
"checksum cc 1.0.29 (registry+https://github.com/rust-lang/crates.io-index)" = "4390a3b5f4f6bce9c1d0c00128379df433e53777fdd30e92f16a529332baec4e"
@ -2258,6 +2433,7 @@ dependencies = [ @@ -2258,6 +2433,7 @@ dependencies = [
"checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878"
"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 core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "286e0b41c3a20da26536c6000a280585d519fd07b3956b43aed8a79e9edce980"
"checksum core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "716c271e8613ace48344f723b60b900a93150271e5be206212d052bbc0883efa"
"checksum crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb"
@ -2268,12 +2444,14 @@ dependencies = [ @@ -2268,12 +2444,14 @@ dependencies = [
"checksum crossbeam-epoch 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30fecfcac6abfef8771151f8be4abc9e4edc112c2bcb233314cafde2680536e9"
"checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9"
"checksum crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "677d453a17e8bd2b913fa38e8b9cf04bcdbb5be790aa294f2389661d72036015"
"checksum crypto-mac 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0999b4ff4d3446d4ddb19a63e9e00c1876e75cd7000d20e57a693b4b3f08d958"
"checksum deflate 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)" = "8a6abb26e16e8d419b5c78662aa9f82857c2386a073da266840e474d5055ec86"
"checksum derive_builder 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c998e6ab02a828dd9735c18f154e14100e674ed08cb4e1938f0e4177543f439"
"checksum derive_builder_core 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "735e24ee9e5fa8e16b86da5007856e97d592e11867e45d76e0c0d0a164a0b757"
"checksum derive_is_enum_variant 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d0ac8859845146979953797f03cc5b282fb4396891807cdb3d04929a88418197"
"checksum diesel 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "164080ac16a4d1d80a50f0a623e4ddef41cb2779eee85bcc76907d340dfc98cc"
"checksum diesel_derives 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "03bcaf77491f53e400d5ee3bdd57142ea4e1c47fe9217b3361ff9a76ca0e3d37"
"checksum digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "03b072242a8cbaf9c145665af9d250c59af3b958f83ed6824e13533cf76d5b90"
"checksum dtoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6d301140eb411af13d3115f9a562c85cc6b541ade9dfa314132244aaee7489dd"
"checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0"
"checksum encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "6b0d943856b990d12d3b55b359144ff341533e516d94098b1d3fc1ac666d36ec"
@ -2288,6 +2466,8 @@ dependencies = [ @@ -2288,6 +2466,8 @@ dependencies = [
"checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02"
"checksum failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7efb22686e4a466b1ec1a15c2898f91fa9cb340452496dca654032de20ff95b9"
"checksum failure_derive 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "946d0e98a50d9831f5d589038d2ca7f8f455b1c21028c0db0e84116a12696426"
"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 flate2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4af030962d89d62aa52cd9492083b1cd9b2d1a77764878102a6c0f86b4d5444d"
"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"
@ -2297,9 +2477,12 @@ dependencies = [ @@ -2297,9 +2477,12 @@ dependencies = [
"checksum futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "49e7653e374fe0d0c12de4250f0bdb60680b8c80eed558c5c7538eec9c89e21b"
"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 gif 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4bca55ac1f213920ce3527ccd62386f1f15fa3f1714aeee1cf93f2c416903f"
"checksum h2 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "a27e7ed946e8335bdf9a191bc1b9b14a03ba822d013d2f58437f4fabcbd7fc2c"
"checksum heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea04fa3ead4e05e51a7c806fc07271fdbde4e246a6c6d1efd52e72230b771b82"
"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.13 (registry+https://github.com/rust-lang/crates.io-index)" = "24f58e8c2d8e886055c3ead7b28793e1455270b5fb39650984c224bc538ba581"
"checksum httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e8734b0cfd3bc3e101ec59100e101c2eecd19282202e87808b3037b442777a83"
"checksum huawei-modem 0.1.0 (git+https://github.com/eeeeeta/huawei-modem)" = "<none>"
@ -2329,6 +2512,7 @@ dependencies = [ @@ -2329,6 +2512,7 @@ dependencies = [
"checksum log4rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a1f16090a553200fba94e104310b3e53e71f500fd9db7dc2143055aa3cc7ae63"
"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.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4b3629fe9fdbff6daa6c33b90f7c08355c1aca05a3d01fa8063b822fcf185f3b"
"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
@ -2368,6 +2552,9 @@ dependencies = [ @@ -2368,6 +2552,9 @@ dependencies = [
"checksum phf_shared 0.7.23 (registry+https://github.com/rust-lang/crates.io-index)" = "b539898d22d4273ded07f64a05737649dc69095d92cb87c7097ec68e3f150b93"
"checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c"
"checksum png 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f54b9600d584d3b8a739e1662a595fab051329eff43f20e7d8cc22872962145b"
"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 pq-sys 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "6ac25eee5a0582f45a67e837e350d784e7003bd29a5f460796772061ca49ffda"
"checksum proc-macro2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cd07deb3c6d1d9ff827999c7f9b04cdfd66b1b17ae508e14fe47b620f2282ae0"
"checksum proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1b06e2f335f48d24442b35a19df506a835fb3547bc3c06ef27340da9acf5cae7"
@ -2403,6 +2590,7 @@ dependencies = [ @@ -2403,6 +2590,7 @@ dependencies = [
"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 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7153dd96dade874ab973e098cb62fcdbb89a03682e46b144fd09550998d4a4a7"
"checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f"
"checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9"
"checksum schannel 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "0e1a231dc10abf6749cfa5d7767f25888d484201accbd919b66ab5413c502d56"
"checksum scheduled-thread-pool 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a2ff3fc5223829be817806c6441279c676e454cc7da608faf03b0ccc09d3889"
@ -2420,15 +2608,18 @@ dependencies = [ @@ -2420,15 +2608,18 @@ dependencies = [
"checksum serde_urlencoded 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "aaed41d9fb1e2f587201b863356590c90c1157495d811430a0c0325fe8169650"
"checksum serde_yaml 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ef8099d3df28273c99a1728190c7a9f19d444c941044f64adf986bee7ec53051"
"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.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1f272d1b7586bec132ed427f532dd418d8beca1ca7f2caf7df35569b1415a4b4"
"checksum simple_logger 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2c0619150c42143a91bd79aa00b5f01f9b0a3ec38b1a59bc0b2f5aa24fc4c9bd"
"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.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5f9776d6b986f77b35c6cf846c11ad986ff128fe0b2b63a3628e3755e8d3102d"
"checksum smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "153ffa32fd170e9944f7e0838edf824a754ec4c1fc64746fcc9fe1f8fa602e5d"
"checksum socket2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "c4d11a52082057d87cb5caa31ad812f4504b97ab44732cd8359df2e9ff9f48e7"
"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.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00caf261d6f90f588f8450b8e1230fa0d5be49ee6140fdfbcb55335aff350970"
"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.13.11 (registry+https://github.com/rust-lang/crates.io-index)" = "14f9bf6292f3a61d2c716723fdb789a41bbe104168e6f496dc6497e531ea1b9b"
@ -2461,6 +2652,7 @@ dependencies = [ @@ -2461,6 +2652,7 @@ dependencies = [
"checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079"
"checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382"
"checksum typemap 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "653be63c80a3296da5551e1bfd2cca35227e13cdd08c6668903ae2f4f77aa1f6"
"checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169"
"checksum ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd2be2d6639d0f8fe6cdda291ad456e23629558d466e2789d2c3e9892bda285d"
"checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33"
"checksum unicase 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9d3218ea14b4edcaccfa0df0a64a3792a2c32cc706f1b336e48867f9d3147f90"

1
Cargo.toml

@ -15,6 +15,7 @@ lazy_static = "1.2.0" @@ -15,6 +15,7 @@ lazy_static = "1.2.0"
log = "0.4"
log4rs = "0.8"
mime_guess = "2.0.0-alpha.6"
postgres = "0.15.2"
qrcode = "0.7"
r2d2 = "0.8"
r2d2-diesel = "1.0"

1
migrations/20190217093945_avatars/down.sql

@ -0,0 +1 @@ @@ -0,0 +1 @@
ALTER TABLE recipients DROP COLUMN avatar_url;

1
migrations/20190217093945_avatars/up.sql

@ -0,0 +1 @@ @@ -0,0 +1 @@
ALTER TABLE recipients ADD COLUMN avatar_url VARCHAR;

6
src/comm.rs

@ -43,11 +43,15 @@ pub enum WhatsappCommand { @@ -43,11 +43,15 @@ pub enum WhatsappCommand {
PersistentChanged(WaPersistentSession),
Disconnect(WaDisconnectReason),
Message(bool, Box<WaMessage>),
MediaFinished(MediaResult)
MediaFinished(MediaResult),
AvatarUrl(PduAddress, Option<String>),
AvatarUpdate(String),
AvatarUpdateAll
}
pub enum ContactFactoryCommand {
ProcessMessages,
ProcessGroups,
ProcessAvatars,
MakeContact(PduAddress, bool),
DropContact(PduAddress),
LoadRecipients,

4
src/config.rs

@ -21,7 +21,9 @@ pub struct Config { @@ -21,7 +21,9 @@ pub struct Config {
#[serde(default)]
pub client: Option<IrcClientConfig>,
#[serde(default)]
pub insp_s2s: Option<InspConfig>
pub insp_s2s: Option<InspConfig>,
#[serde(default)]
pub quassel_database_url: Option<String>
}
#[derive(Deserialize, Debug, Clone)]
pub struct IrcClientConfig {

5
src/contact_factory.rs

@ -44,7 +44,10 @@ impl Future for ContactFactory { @@ -44,7 +44,10 @@ impl Future for ContactFactory {
LoadRecipients => self.load_recipients()?,
MakeContact(addr, wa) => self.make_contact(addr, wa)?,
DropContact(addr) => self.drop_contact(addr)?,
UpdateAway(addr, away) => self.update_away(addr, away)
UpdateAway(addr, away) => self.update_away(addr, away),
ProcessAvatars => {
// FIXME: implement
}
}
}
let mut to_remove = vec![];

45
src/insp_s2s.rs

@ -20,6 +20,7 @@ use control_common::ControlCommon; @@ -20,6 +20,7 @@ use control_common::ControlCommon;
use insp_user::InspUser;
use config::InspConfig;
use std::net::{SocketAddr, ToSocketAddrs};
use postgres::Connection as PgConn;
pub static INSP_PROTOCOL_CAPAB: &str = "PROTOCOL=1203";
struct InspContact {
@ -55,6 +56,7 @@ pub struct InspLink { @@ -55,6 +56,7 @@ pub struct InspLink {
outbox: Vec<Message>,
channels: HashSet<String>,
state: LinkState,
quassel: Option<PgConn>
}
impl Future for InspLink {
@ -233,7 +235,7 @@ impl InspLink { @@ -233,7 +235,7 @@ impl InspLink {
format!("s.{}", self.cfg.server_name)
}
}
pub fn new(p: InitParameters<InspConfig>) -> impl Future<Item = Self, Error = Error> {
pub fn new(p: InitParameters<InspConfig>, qdb: Option<PgConn>) -> impl Future<Item = Self, Error = Error> {
let store = p.store;
let cfg = p.cfg2.clone();
let cf_rx = p.cm.cf_rx.take().unwrap();
@ -263,7 +265,8 @@ impl InspLink { @@ -263,7 +265,8 @@ impl InspLink {
outbox: vec![],
channels: HashSet::new(),
remote_sid: "XXX".into(),
state: LinkState::TcpConnected
state: LinkState::TcpConnected,
quassel: qdb
}
})
.map_err(|e| e.into());
@ -278,6 +281,9 @@ impl InspLink { @@ -278,6 +281,9 @@ impl InspLink {
};
let host = self.host_for_wa(is_wa);
self.outbox.push(Message::new(Some(&uid), "FHOST", vec![&host], None)?);
if let Some(user) = self.users.get_mut(&uid) {
user.displayed_hostname = host;
}
Ok(())
}
fn process_contact_admin_command(&mut self, addr: PduAddress, mesg: String) -> Result<()> {
@ -494,7 +500,7 @@ impl InspLink { @@ -494,7 +500,7 @@ impl InspLink {
self.channel_topics.insert(args[0].to_string(), topic);
},
"FHOST" => {
if args.len() != 1 {
if args.len() < 1 {
// These are pretty common, for some reason.
debug!("Invalid FHOST received: {:?}", args);
return Ok(());
@ -613,6 +619,36 @@ impl InspLink { @@ -613,6 +619,36 @@ impl InspLink {
self.outbox.push(Message::new(Some(uid), kind, vec![target], Some(message))?);
Ok(())
}
fn process_avatars(&mut self) -> Result<()> {
let mut processed = 0;
let qdb = match self.quassel {
Some(ref mut qdb) => qdb,
None => return Ok(())
};
for recip in self.store.get_all_recipients()? {
if let Some(avatar_url) = recip.avatar_url {
let addr = util::un_normalize_address(&recip.phone_number)
.ok_or(format_err!("invalid phone number in db"))?;
if let Some(ic) = self.contacts.get(&addr) {
if let Some(iu) = self.users.get(&ic.uuid) {
let query = format!("{}!{}@%.{}", iu.nick, iu.gecos, self.cfg.server_name);
let res = qdb.execute("UPDATE sender SET avatarurl = $1 WHERE sender LIKE $2",
&[&avatar_url, &query]);
match res {
Ok(p) => {
processed += p;
},
Err(e) => {
warn!("Failed to update avatar for {}: {}", iu.nick, e);
}
}
}
}
}
}
info!("Updated {} Quassel avatar entries.", processed);
Ok(())
}
fn handle_cf_command(&mut self, cfc: ContactFactoryCommand) -> Result<()> {
use self::ContactFactoryCommand::*;
@ -629,7 +665,8 @@ impl InspLink { @@ -629,7 +665,8 @@ impl InspLink {
if let Some(ct) = self.contacts.get(&a) {
self.outbox.push(Message::new(Some(&ct.uuid), "AWAY", vec![], text.as_ref().map(|x| x as &str))?);
}
}
},
ProcessAvatars => self.process_avatars()?
}
Ok(())
}

14
src/main.rs

@ -27,6 +27,7 @@ extern crate mime_guess; @@ -27,6 +27,7 @@ extern crate mime_guess;
extern crate tokio_signal;
extern crate regex;
#[macro_use] extern crate lazy_static;
extern crate postgres;
mod config;
mod store;
@ -125,6 +126,17 @@ fn main() -> Result<(), failure::Error> { @@ -125,6 +126,17 @@ fn main() -> Result<(), failure::Error> {
}
info!("Connecting to database");
let store = Store::new(&config)?;
let quassel = if let Some(ref dbu) = config.quassel_database_url {
info!("Connecting to Quassel database");
postgres::Connection::connect(dbu as &str, postgres::TlsMode::None)
.map_err(|e| {
warn!("Failed to connect to Quassel DB: {}", e);
})
.ok()
}
else {
None
};
info!("Initializing tokio");
let mut core = Core::new()?;
let hdl = core.handle();
@ -194,7 +206,7 @@ fn main() -> Result<(), failure::Error> { @@ -194,7 +206,7 @@ fn main() -> Result<(), failure::Error> {
store: store.clone(),
cm: &mut cm,
hdl: &hdl
}))?;
}, quassel))?;
let _ = core.run(fut.map_err(|e| {
// FIXME: restartability

6
src/models.rs

@ -6,14 +6,16 @@ pub struct Recipient { @@ -6,14 +6,16 @@ pub struct Recipient {
pub id: i32,
pub phone_number: String,
pub nick: String,
pub whatsapp: bool
pub whatsapp: bool,
pub avatar_url: Option<String>
}
#[derive(Insertable)]
#[table_name="recipients"]
pub struct NewRecipient<'a> {
pub phone_number: &'a str,
pub nick: &'a str,
pub whatsapp: bool
pub whatsapp: bool,
pub avatar_url: Option<&'a str>
}
#[derive(Queryable, Debug)]
pub struct Message {

1
src/schema.rs

@ -26,6 +26,7 @@ table! { @@ -26,6 +26,7 @@ table! {
phone_number -> Varchar,
nick -> Varchar,
whatsapp -> Bool,
avatar_url -> Nullable<Varchar>,
}
}

23
src/store.rs

@ -123,7 +123,8 @@ impl Store { @@ -123,7 +123,8 @@ impl Store {
let nr = NewRecipient {
phone_number: &num,
nick,
whatsapp: wa
whatsapp: wa,
avatar_url: None
};
let conn = self.inner.get()?;
@ -143,6 +144,17 @@ impl Store { @@ -143,6 +144,17 @@ impl Store {
.execute(&*conn)?;
Ok(())
}
pub fn update_recipient_avatar_url(&mut self, addr: &PduAddress, a: Option<String>) -> Result<()> {
use schema::recipients::dsl::*;
let conn = self.inner.get()?;
let num = util::normalize_address(addr);
::diesel::update(recipients)
.filter(phone_number.eq(num))
.set(avatar_url.eq(a))
.execute(&*conn)?;
Ok(())
}
pub fn update_recipient_wa(&mut self, addr: &PduAddress, wa: bool) -> Result<()> {
use schema::recipients::dsl::*;
let conn = self.inner.get()?;
@ -163,6 +175,15 @@ impl Store { @@ -163,6 +175,15 @@ impl Store {
.optional()?;
Ok(res)
}
pub fn get_recipient_by_nick_opt(&mut self, n: &str) -> Result<Option<Recipient>> {
use schema::recipients::dsl::*;
let conn = self.inner.get()?;
let res = recipients.filter(nick.eq(n))
.first(&*conn)
.optional()?;
Ok(res)
}
pub fn get_recipient_by_addr_opt(&mut self, addr: &PduAddress) -> Result<Option<Recipient>> {
use schema::recipients::dsl::*;
let conn = self.inner.get()?;

51
src/whatsapp.rs

@ -125,10 +125,59 @@ impl WhatsappManager { @@ -125,10 +125,59 @@ impl WhatsappManager {
self.on_message(msg)?;
}
},
MediaFinished(r) => self.media_finished(r)?
MediaFinished(r) => self.media_finished(r)?,
AvatarUrl(pdua, url) => self.avatar_url(pdua, url)?,
AvatarUpdate(nick) => self.avatar_update_by_nick(&nick)?,
AvatarUpdateAll => self.avatar_update_all()?
}
Ok(())
}
fn avatar_update_by_nick(&mut self, nick: &str) -> Result<()> {
if let Some(recip) = self.store.get_recipient_by_nick_opt(nick)? {
let addr = util::un_normalize_address(&recip.phone_number)
.ok_or(format_err!("invalid phone number in db"))?;
self.cb_respond(format!("Updating nick for {}...", addr));
self.avatar_update(addr)?;
}
else {
self.cb_respond("Nick not found in database.".into());
}
Ok(())
}
fn avatar_update_all(&mut self) -> Result<()> {
for recip in self.store.get_all_recipients()? {
if recip.whatsapp {
let addr = util::un_normalize_address(&recip.phone_number)
.ok_or(format_err!("invalid phone number in db"))?;
self.avatar_update(addr)?;
}
}
Ok(())
}
fn avatar_update(&mut self, pdua: PduAddress) -> Result<()> {
match Jid::from_phonenumber(format!("{}", pdua)) {
Ok(jid) => {
if let Some(ref mut conn) = self.conn {
let tx2 = self.wa_tx.clone();
conn.get_profile_picture(&jid, Box::new(move |pic| {
tx2.unbounded_send(WhatsappCommand::AvatarUrl(pdua.clone(), pic.map(|x| x.to_string())))
.unwrap();
}));
}
},
Err(e) => {
warn!("couldn't make jid from phonenumber {}: {}", pdua, e);
}
}
Ok(())
}
fn avatar_url(&mut self, pdua: PduAddress, url: Option<String>) -> Result<()> {
info!("Got new avatar for {}", pdua);
self.store.update_recipient_avatar_url(&pdua, url)?;
self.cf_tx.unbounded_send(ContactFactoryCommand::ProcessAvatars)
.unwrap();
Ok(())
}
fn media_finished(&mut self, r: MediaResult) -> Result<()> {
match r.result {
Ok(ret) => {

Loading…
Cancel
Save