Commit 262c96b62f
Unregistered key
Layout: unified · split
.gitattributes added +1
| @@ -0,0 +1 @@ | |||
| 1 | * text eol=lf | ||
.github/workflows/ci.yml added +60
| @@ -0,0 +1,60 @@ | |||
| 1 | on: | ||
| 2 | push: | ||
| 3 | branches: | ||
| 4 | - main | ||
| 5 | pull_request: | ||
| 6 | branches: | ||
| 7 | - main | ||
| 8 | |||
| 9 | name: CI | ||
| 10 | |||
| 11 | jobs: | ||
| 12 | clippy_check: | ||
| 13 | runs-on: ubuntu-latest | ||
| 14 | steps: | ||
| 15 | - name: Checkout code | ||
| 16 | uses: actions/checkout@v1 | ||
| 17 | with: | ||
| 18 | submodules: true | ||
| 19 | - name: Install Rust | ||
| 20 | uses: actions-rs/toolchain@v1 | ||
| 21 | with: | ||
| 22 | toolchain: stable | ||
| 23 | components: clippy | ||
| 24 | override: true | ||
| 25 | - name: Check Clippy | ||
| 26 | uses: actions-rs/clippy-check@v1 | ||
| 27 | with: | ||
| 28 | token: ${{ secrets.GITHUB_TOKEN }} | ||
| 29 | toolchain: stable | ||
| 30 | args: | ||
| 31 | test: | ||
| 32 | strategy: | ||
| 33 | matrix: | ||
| 34 | platform: [ubuntu-latest, windows-latest, macos-latest] | ||
| 35 | runs-on: ${{ matrix.platform }} | ||
| 36 | steps: | ||
| 37 | - name: Checkout code | ||
| 38 | uses: actions/checkout@v2 | ||
| 39 | with: | ||
| 40 | submodules: true | ||
| 41 | - name: Install Rust | ||
| 42 | uses: actions-rs/toolchain@v1 | ||
| 43 | with: | ||
| 44 | toolchain: nightly | ||
| 45 | override: true | ||
| 46 | components: rustfmt, clippy | ||
| 47 | - name: Cache cargo registry | ||
| 48 | uses: actions/cache@v1 | ||
| 49 | with: | ||
| 50 | path: ~/.cargo/registry | ||
| 51 | key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} | ||
| 52 | - name: Check formatting | ||
| 53 | uses: actions-rs/cargo@v1 | ||
| 54 | with: | ||
| 55 | command: fmt | ||
| 56 | args: --all -- --check | ||
| 57 | - name: Run tests | ||
| 58 | uses: actions-rs/cargo@v1 | ||
| 59 | with: | ||
| 60 | command: test | ||
.gitignore +1
| @@ -1 +1,2 @@ | |||
| 1 | /target | 1 | /target |
| 2 | /TODO | ||
.rustfmt.toml added +12
| @@ -0,0 +1,12 @@ | |||
| 1 | unstable_features = true | ||
| 2 | max_width = 100 | ||
| 3 | fn_call_width = 90 | ||
| 4 | struct_lit_width = 50 | ||
| 5 | struct_variant_width = 50 | ||
| 6 | chain_width = 75 | ||
| 7 | binop_separator = "Back" | ||
| 8 | force_multiline_blocks = true | ||
| 9 | match_block_trailing_comma = true | ||
| 10 | imports_layout = "HorizontalVertical" | ||
| 11 | newline_style = "Unix" | ||
| 12 | overflow_delimited_expr = true | ||
Cargo.lock +3166
| @@ -2,6 +2,3172 @@ | |||
| 2 | # It is not intended for manual editing. | 2 | # It is not intended for manual editing. |
| 3 | version = 3 | 3 | version = 3 |
| 4 | 4 | ||
| 5 | [[package]] | ||
| 6 | name = "aead" | ||
| 7 | version = "0.4.3" | ||
| 8 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 9 | checksum = "0b613b8e1e3cf911a086f53f03bf286f52fd7a7258e4fa606f0ef220d39d8877" | ||
| 10 | dependencies = [ | ||
| 11 | "generic-array", | ||
| 12 | "rand_core 0.6.4", | ||
| 13 | ] | ||
| 14 | |||
| 15 | [[package]] | ||
| 16 | name = "aes" | ||
| 17 | version = "0.8.2" | ||
| 18 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 19 | checksum = "433cfd6710c9986c576a25ca913c39d66a6474107b406f34f91d4a8923395241" | ||
| 20 | dependencies = [ | ||
| 21 | "cfg-if", | ||
| 22 | "cipher 0.4.3", | ||
| 23 | "cpufeatures", | ||
| 24 | ] | ||
| 25 | |||
| 26 | [[package]] | ||
| 27 | name = "ahash" | ||
| 28 | version = "0.7.6" | ||
| 29 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 30 | checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" | ||
| 31 | dependencies = [ | ||
| 32 | "getrandom 0.2.8", | ||
| 33 | "once_cell", | ||
| 34 | "version_check", | ||
| 35 | ] | ||
| 36 | |||
| 37 | [[package]] | ||
| 38 | name = "aho-corasick" | ||
| 39 | version = "0.7.20" | ||
| 40 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 41 | checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" | ||
| 42 | dependencies = [ | ||
| 43 | "memchr", | ||
| 44 | ] | ||
| 45 | |||
| 46 | [[package]] | ||
| 47 | name = "android_system_properties" | ||
| 48 | version = "0.1.5" | ||
| 49 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 50 | checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" | ||
| 51 | dependencies = [ | ||
| 52 | "libc", | ||
| 53 | ] | ||
| 54 | |||
| 55 | [[package]] | ||
| 56 | name = "anyhow" | ||
| 57 | version = "1.0.67" | ||
| 58 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 59 | checksum = "7724808837b77f4b4de9d283820f9d98bcf496d5692934b857a2399d31ff22e6" | ||
| 60 | |||
| 61 | [[package]] | ||
| 62 | name = "anymap2" | ||
| 63 | version = "0.13.0" | ||
| 64 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 65 | checksum = "d301b3b94cb4b2f23d7917810addbbaff90738e0ca2be692bd027e70d7e0330c" | ||
| 66 | |||
| 67 | [[package]] | ||
| 68 | name = "arrayref" | ||
| 69 | version = "0.3.6" | ||
| 70 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 71 | checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" | ||
| 72 | |||
| 73 | [[package]] | ||
| 74 | name = "arrayvec" | ||
| 75 | version = "0.7.2" | ||
| 76 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 77 | checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" | ||
| 78 | dependencies = [ | ||
| 79 | "serde", | ||
| 80 | ] | ||
| 81 | |||
| 82 | [[package]] | ||
| 83 | name = "assign" | ||
| 84 | version = "1.1.1" | ||
| 85 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 86 | checksum = "5f093eed78becd229346bf859eec0aa4dd7ddde0757287b2b4107a1f09c80002" | ||
| 87 | |||
| 88 | [[package]] | ||
| 89 | name = "async-lock" | ||
| 90 | version = "2.6.0" | ||
| 91 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 92 | checksum = "c8101efe8695a6c17e02911402145357e718ac92d3ff88ae8419e84b1707b685" | ||
| 93 | dependencies = [ | ||
| 94 | "event-listener", | ||
| 95 | "futures-lite", | ||
| 96 | ] | ||
| 97 | |||
| 98 | [[package]] | ||
| 99 | name = "async-once-cell" | ||
| 100 | version = "0.3.1" | ||
| 101 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 102 | checksum = "72faff1fdc615a0199d7bf71e6f389af54d46a66e9beb5d76c39e48eda93ecce" | ||
| 103 | |||
| 104 | [[package]] | ||
| 105 | name = "async-stream" | ||
| 106 | version = "0.3.3" | ||
| 107 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 108 | checksum = "dad5c83079eae9969be7fadefe640a1c566901f05ff91ab221de4b6f68d9507e" | ||
| 109 | dependencies = [ | ||
| 110 | "async-stream-impl", | ||
| 111 | "futures-core", | ||
| 112 | ] | ||
| 113 | |||
| 114 | [[package]] | ||
| 115 | name = "async-stream-impl" | ||
| 116 | version = "0.3.3" | ||
| 117 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 118 | checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27" | ||
| 119 | dependencies = [ | ||
| 120 | "proc-macro2", | ||
| 121 | "quote", | ||
| 122 | "syn", | ||
| 123 | ] | ||
| 124 | |||
| 125 | [[package]] | ||
| 126 | name = "async-trait" | ||
| 127 | version = "0.1.60" | ||
| 128 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 129 | checksum = "677d1d8ab452a3936018a687b20e6f7cf5363d713b732b8884001317b0e48aa3" | ||
| 130 | dependencies = [ | ||
| 131 | "proc-macro2", | ||
| 132 | "quote", | ||
| 133 | "syn", | ||
| 134 | ] | ||
| 135 | |||
| 136 | [[package]] | ||
| 137 | name = "atomic" | ||
| 138 | version = "0.5.1" | ||
| 139 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 140 | checksum = "b88d82667eca772c4aa12f0f1348b3ae643424c8876448f3f7bd5787032e234c" | ||
| 141 | dependencies = [ | ||
| 142 | "autocfg", | ||
| 143 | ] | ||
| 144 | |||
| 145 | [[package]] | ||
| 146 | name = "autocfg" | ||
| 147 | version = "1.1.0" | ||
| 148 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 149 | checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" | ||
| 150 | |||
| 151 | [[package]] | ||
| 152 | name = "backoff" | ||
| 153 | version = "0.4.0" | ||
| 154 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 155 | checksum = "b62ddb9cb1ec0a098ad4bbf9344d0713fa193ae1a80af55febcff2627b6a00c1" | ||
| 156 | dependencies = [ | ||
| 157 | "futures-core", | ||
| 158 | "getrandom 0.2.8", | ||
| 159 | "instant", | ||
| 160 | "pin-project-lite", | ||
| 161 | "rand 0.8.5", | ||
| 162 | "tokio", | ||
| 163 | ] | ||
| 164 | |||
| 165 | [[package]] | ||
| 166 | name = "base64" | ||
| 167 | version = "0.13.1" | ||
| 168 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 169 | checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" | ||
| 170 | |||
| 171 | [[package]] | ||
| 172 | name = "base64ct" | ||
| 173 | version = "1.5.3" | ||
| 174 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 175 | checksum = "b645a089122eccb6111b4f81cbc1a49f5900ac4666bb93ac027feaecf15607bf" | ||
| 176 | |||
| 177 | [[package]] | ||
| 178 | name = "bitflags" | ||
| 179 | version = "1.3.2" | ||
| 180 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 181 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" | ||
| 182 | |||
| 183 | [[package]] | ||
| 184 | name = "blake3" | ||
| 185 | version = "1.3.3" | ||
| 186 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 187 | checksum = "42ae2468a89544a466886840aa467a25b766499f4f04bf7d9fcd10ecee9fccef" | ||
| 188 | dependencies = [ | ||
| 189 | "arrayref", | ||
| 190 | "arrayvec", | ||
| 191 | "cc", | ||
| 192 | "cfg-if", | ||
| 193 | "constant_time_eq", | ||
| 194 | "digest 0.10.6", | ||
| 195 | ] | ||
| 196 | |||
| 197 | [[package]] | ||
| 198 | name = "block-buffer" | ||
| 199 | version = "0.9.0" | ||
| 200 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 201 | checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" | ||
| 202 | dependencies = [ | ||
| 203 | "generic-array", | ||
| 204 | ] | ||
| 205 | |||
| 206 | [[package]] | ||
| 207 | name = "block-buffer" | ||
| 208 | version = "0.10.3" | ||
| 209 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 210 | checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" | ||
| 211 | dependencies = [ | ||
| 212 | "generic-array", | ||
| 213 | ] | ||
| 214 | |||
| 215 | [[package]] | ||
| 216 | name = "block-padding" | ||
| 217 | version = "0.3.2" | ||
| 218 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 219 | checksum = "0a90ec2df9600c28a01c56c4784c9207a96d2451833aeceb8cc97e4c9548bb78" | ||
| 220 | dependencies = [ | ||
| 221 | "generic-array", | ||
| 222 | ] | ||
| 223 | |||
| 224 | [[package]] | ||
| 225 | name = "bumpalo" | ||
| 226 | version = "3.11.1" | ||
| 227 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 228 | checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" | ||
| 229 | |||
| 230 | [[package]] | ||
| 231 | name = "byteorder" | ||
| 232 | version = "1.4.3" | ||
| 233 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 234 | checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" | ||
| 235 | |||
| 236 | [[package]] | ||
| 237 | name = "bytes" | ||
| 238 | version = "1.3.0" | ||
| 239 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 240 | checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" | ||
| 241 | |||
| 242 | [[package]] | ||
| 243 | name = "cassowary" | ||
| 244 | version = "0.3.0" | ||
| 245 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 246 | checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53" | ||
| 247 | |||
| 248 | [[package]] | ||
| 249 | name = "cbc" | ||
| 250 | version = "0.1.2" | ||
| 251 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 252 | checksum = "26b52a9543ae338f279b96b0b9fed9c8093744685043739079ce85cd58f289a6" | ||
| 253 | dependencies = [ | ||
| 254 | "cipher 0.4.3", | ||
| 255 | ] | ||
| 256 | |||
| 257 | [[package]] | ||
| 258 | name = "cc" | ||
| 259 | version = "1.0.78" | ||
| 260 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 261 | checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" | ||
| 262 | |||
| 263 | [[package]] | ||
| 264 | name = "cfg-if" | ||
| 265 | version = "1.0.0" | ||
| 266 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 267 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" | ||
| 268 | |||
| 269 | [[package]] | ||
| 270 | name = "chacha20" | ||
| 271 | version = "0.8.2" | ||
| 272 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 273 | checksum = "5c80e5460aa66fe3b91d40bcbdab953a597b60053e34d684ac6903f863b680a6" | ||
| 274 | dependencies = [ | ||
| 275 | "cfg-if", | ||
| 276 | "cipher 0.3.0", | ||
| 277 | "cpufeatures", | ||
| 278 | "zeroize", | ||
| 279 | ] | ||
| 280 | |||
| 281 | [[package]] | ||
| 282 | name = "chacha20poly1305" | ||
| 283 | version = "0.9.1" | ||
| 284 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 285 | checksum = "a18446b09be63d457bbec447509e85f662f32952b035ce892290396bc0b0cff5" | ||
| 286 | dependencies = [ | ||
| 287 | "aead", | ||
| 288 | "chacha20", | ||
| 289 | "cipher 0.3.0", | ||
| 290 | "poly1305", | ||
| 291 | "zeroize", | ||
| 292 | ] | ||
| 293 | |||
| 294 | [[package]] | ||
| 295 | name = "chrono" | ||
| 296 | version = "0.4.23" | ||
| 297 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 298 | checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" | ||
| 299 | dependencies = [ | ||
| 300 | "iana-time-zone", | ||
| 301 | "js-sys", | ||
| 302 | "num-integer", | ||
| 303 | "num-traits", | ||
| 304 | "time 0.1.45", | ||
| 305 | "wasm-bindgen", | ||
| 306 | "winapi", | ||
| 307 | ] | ||
| 308 | |||
| 309 | [[package]] | ||
| 310 | name = "cipher" | ||
| 311 | version = "0.3.0" | ||
| 312 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 313 | checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" | ||
| 314 | dependencies = [ | ||
| 315 | "generic-array", | ||
| 316 | ] | ||
| 317 | |||
| 318 | [[package]] | ||
| 319 | name = "cipher" | ||
| 320 | version = "0.4.3" | ||
| 321 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 322 | checksum = "d1873270f8f7942c191139cb8a40fd228da6c3fd2fc376d7e92d47aa14aeb59e" | ||
| 323 | dependencies = [ | ||
| 324 | "crypto-common", | ||
| 325 | "inout", | ||
| 326 | ] | ||
| 327 | |||
| 328 | [[package]] | ||
| 329 | name = "clap" | ||
| 330 | version = "4.0.29" | ||
| 331 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 332 | checksum = "4d63b9e9c07271b9957ad22c173bae2a4d9a81127680962039296abcd2f8251d" | ||
| 333 | dependencies = [ | ||
| 334 | "bitflags", | ||
| 335 | "clap_derive", | ||
| 336 | "clap_lex", | ||
| 337 | "is-terminal", | ||
| 338 | "once_cell", | ||
| 339 | "strsim", | ||
| 340 | "termcolor", | ||
| 341 | ] | ||
| 342 | |||
| 343 | [[package]] | ||
| 344 | name = "clap_derive" | ||
| 345 | version = "4.0.21" | ||
| 346 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 347 | checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014" | ||
| 348 | dependencies = [ | ||
| 349 | "heck", | ||
| 350 | "proc-macro-error", | ||
| 351 | "proc-macro2", | ||
| 352 | "quote", | ||
| 353 | "syn", | ||
| 354 | ] | ||
| 355 | |||
| 356 | [[package]] | ||
| 357 | name = "clap_lex" | ||
| 358 | version = "0.3.0" | ||
| 359 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 360 | checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" | ||
| 361 | dependencies = [ | ||
| 362 | "os_str_bytes", | ||
| 363 | ] | ||
| 364 | |||
| 365 | [[package]] | ||
| 366 | name = "codespan-reporting" | ||
| 367 | version = "0.11.1" | ||
| 368 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 369 | checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" | ||
| 370 | dependencies = [ | ||
| 371 | "termcolor", | ||
| 372 | "unicode-width", | ||
| 373 | ] | ||
| 374 | |||
| 375 | [[package]] | ||
| 376 | name = "const-oid" | ||
| 377 | version = "0.7.1" | ||
| 378 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 379 | checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3" | ||
| 380 | |||
| 381 | [[package]] | ||
| 382 | name = "constant_time_eq" | ||
| 383 | version = "0.2.4" | ||
| 384 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 385 | checksum = "f3ad85c1f65dc7b37604eb0e89748faf0b9653065f2a8ef69f96a687ec1e9279" | ||
| 386 | |||
| 387 | [[package]] | ||
| 388 | name = "convert_case" | ||
| 389 | version = "0.4.0" | ||
| 390 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 391 | checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" | ||
| 392 | |||
| 393 | [[package]] | ||
| 394 | name = "core-foundation-sys" | ||
| 395 | version = "0.8.3" | ||
| 396 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 397 | checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" | ||
| 398 | |||
| 399 | [[package]] | ||
| 400 | name = "cpufeatures" | ||
| 401 | version = "0.2.5" | ||
| 402 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 403 | checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" | ||
| 404 | dependencies = [ | ||
| 405 | "libc", | ||
| 406 | ] | ||
| 407 | |||
| 408 | [[package]] | ||
| 409 | name = "crc32fast" | ||
| 410 | version = "1.3.2" | ||
| 411 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 412 | checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" | ||
| 413 | dependencies = [ | ||
| 414 | "cfg-if", | ||
| 415 | ] | ||
| 416 | |||
| 417 | [[package]] | ||
| 418 | name = "crossbeam-channel" | ||
| 419 | version = "0.5.6" | ||
| 420 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 421 | checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" | ||
| 422 | dependencies = [ | ||
| 423 | "cfg-if", | ||
| 424 | "crossbeam-utils", | ||
| 425 | ] | ||
| 426 | |||
| 427 | [[package]] | ||
| 428 | name = "crossbeam-epoch" | ||
| 429 | version = "0.9.13" | ||
| 430 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 431 | checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a" | ||
| 432 | dependencies = [ | ||
| 433 | "autocfg", | ||
| 434 | "cfg-if", | ||
| 435 | "crossbeam-utils", | ||
| 436 | "memoffset", | ||
| 437 | "scopeguard", | ||
| 438 | ] | ||
| 439 | |||
| 440 | [[package]] | ||
| 441 | name = "crossbeam-utils" | ||
| 442 | version = "0.8.14" | ||
| 443 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 444 | checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f" | ||
| 445 | dependencies = [ | ||
| 446 | "cfg-if", | ||
| 447 | ] | ||
| 448 | |||
| 449 | [[package]] | ||
| 450 | name = "crossterm" | ||
| 451 | version = "0.25.0" | ||
| 452 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 453 | checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67" | ||
| 454 | dependencies = [ | ||
| 455 | "bitflags", | ||
| 456 | "crossterm_winapi", | ||
| 457 | "libc", | ||
| 458 | "mio", | ||
| 459 | "parking_lot 0.12.1", | ||
| 460 | "signal-hook", | ||
| 461 | "signal-hook-mio", | ||
| 462 | "winapi", | ||
| 463 | ] | ||
| 464 | |||
| 465 | [[package]] | ||
| 466 | name = "crossterm_winapi" | ||
| 467 | version = "0.9.0" | ||
| 468 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 469 | checksum = "2ae1b35a484aa10e07fe0638d02301c5ad24de82d310ccbd2f3693da5f09bf1c" | ||
| 470 | dependencies = [ | ||
| 471 | "winapi", | ||
| 472 | ] | ||
| 473 | |||
| 474 | [[package]] | ||
| 475 | name = "crypto-common" | ||
| 476 | version = "0.1.6" | ||
| 477 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 478 | checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" | ||
| 479 | dependencies = [ | ||
| 480 | "generic-array", | ||
| 481 | "typenum", | ||
| 482 | ] | ||
| 483 | |||
| 484 | [[package]] | ||
| 485 | name = "ctr" | ||
| 486 | version = "0.9.2" | ||
| 487 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 488 | checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" | ||
| 489 | dependencies = [ | ||
| 490 | "cipher 0.4.3", | ||
| 491 | ] | ||
| 492 | |||
| 493 | [[package]] | ||
| 494 | name = "curve25519-dalek" | ||
| 495 | version = "3.2.1" | ||
| 496 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 497 | checksum = "90f9d052967f590a76e62eb387bd0bbb1b000182c3cefe5364db6b7211651bc0" | ||
| 498 | dependencies = [ | ||
| 499 | "byteorder", | ||
| 500 | "digest 0.9.0", | ||
| 501 | "rand_core 0.5.1", | ||
| 502 | "serde", | ||
| 503 | "subtle", | ||
| 504 | "zeroize", | ||
| 505 | ] | ||
| 506 | |||
| 507 | [[package]] | ||
| 508 | name = "cxx" | ||
| 509 | version = "1.0.84" | ||
| 510 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 511 | checksum = "27874566aca772cb515af4c6e997b5fe2119820bca447689145e39bb734d19a0" | ||
| 512 | dependencies = [ | ||
| 513 | "cc", | ||
| 514 | "cxxbridge-flags", | ||
| 515 | "cxxbridge-macro", | ||
| 516 | "link-cplusplus", | ||
| 517 | ] | ||
| 518 | |||
| 519 | [[package]] | ||
| 520 | name = "cxx-build" | ||
| 521 | version = "1.0.84" | ||
| 522 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 523 | checksum = "e7bb951f2523a49533003656a72121306b225ec16a49a09dc6b0ba0d6f3ec3c0" | ||
| 524 | dependencies = [ | ||
| 525 | "cc", | ||
| 526 | "codespan-reporting", | ||
| 527 | "once_cell", | ||
| 528 | "proc-macro2", | ||
| 529 | "quote", | ||
| 530 | "scratch", | ||
| 531 | "syn", | ||
| 532 | ] | ||
| 533 | |||
| 534 | [[package]] | ||
| 535 | name = "cxxbridge-flags" | ||
| 536 | version = "1.0.84" | ||
| 537 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 538 | checksum = "be778b6327031c1c7b61dd2e48124eee5361e6aa76b8de93692f011b08870ab4" | ||
| 539 | |||
| 540 | [[package]] | ||
| 541 | name = "cxxbridge-macro" | ||
| 542 | version = "1.0.84" | ||
| 543 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 544 | checksum = "7b8a2b87662fe5a0a0b38507756ab66aff32638876a0866e5a5fc82ceb07ee49" | ||
| 545 | dependencies = [ | ||
| 546 | "proc-macro2", | ||
| 547 | "quote", | ||
| 548 | "syn", | ||
| 549 | ] | ||
| 550 | |||
| 551 | [[package]] | ||
| 552 | name = "darling" | ||
| 553 | version = "0.14.2" | ||
| 554 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 555 | checksum = "b0dd3cd20dc6b5a876612a6e5accfe7f3dd883db6d07acfbf14c128f61550dfa" | ||
| 556 | dependencies = [ | ||
| 557 | "darling_core", | ||
| 558 | "darling_macro", | ||
| 559 | ] | ||
| 560 | |||
| 561 | [[package]] | ||
| 562 | name = "darling_core" | ||
| 563 | version = "0.14.2" | ||
| 564 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 565 | checksum = "a784d2ccaf7c98501746bf0be29b2022ba41fd62a2e622af997a03e9f972859f" | ||
| 566 | dependencies = [ | ||
| 567 | "fnv", | ||
| 568 | "ident_case", | ||
| 569 | "proc-macro2", | ||
| 570 | "quote", | ||
| 571 | "strsim", | ||
| 572 | "syn", | ||
| 573 | ] | ||
| 574 | |||
| 575 | [[package]] | ||
| 576 | name = "darling_macro" | ||
| 577 | version = "0.14.2" | ||
| 578 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 579 | checksum = "7618812407e9402654622dd402b0a89dff9ba93badd6540781526117b92aab7e" | ||
| 580 | dependencies = [ | ||
| 581 | "darling_core", | ||
| 582 | "quote", | ||
| 583 | "syn", | ||
| 584 | ] | ||
| 585 | |||
| 586 | [[package]] | ||
| 587 | name = "dashmap" | ||
| 588 | version = "5.4.0" | ||
| 589 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 590 | checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc" | ||
| 591 | dependencies = [ | ||
| 592 | "cfg-if", | ||
| 593 | "hashbrown", | ||
| 594 | "lock_api", | ||
| 595 | "once_cell", | ||
| 596 | "parking_lot_core 0.9.5", | ||
| 597 | ] | ||
| 598 | |||
| 599 | [[package]] | ||
| 600 | name = "der" | ||
| 601 | version = "0.5.1" | ||
| 602 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 603 | checksum = "6919815d73839e7ad218de758883aae3a257ba6759ce7a9992501efbb53d705c" | ||
| 604 | dependencies = [ | ||
| 605 | "const-oid", | ||
| 606 | ] | ||
| 607 | |||
| 608 | [[package]] | ||
| 609 | name = "derive_builder" | ||
| 610 | version = "0.11.2" | ||
| 611 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 612 | checksum = "d07adf7be193b71cc36b193d0f5fe60b918a3a9db4dad0449f57bcfd519704a3" | ||
| 613 | dependencies = [ | ||
| 614 | "derive_builder_macro", | ||
| 615 | ] | ||
| 616 | |||
| 617 | [[package]] | ||
| 618 | name = "derive_builder_core" | ||
| 619 | version = "0.11.2" | ||
| 620 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 621 | checksum = "1f91d4cfa921f1c05904dc3c57b4a32c38aed3340cce209f3a6fd1478babafc4" | ||
| 622 | dependencies = [ | ||
| 623 | "darling", | ||
| 624 | "proc-macro2", | ||
| 625 | "quote", | ||
| 626 | "syn", | ||
| 627 | ] | ||
| 628 | |||
| 629 | [[package]] | ||
| 630 | name = "derive_builder_macro" | ||
| 631 | version = "0.11.2" | ||
| 632 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 633 | checksum = "8f0314b72bed045f3a68671b3c86328386762c93f82d98c65c3cb5e5f573dd68" | ||
| 634 | dependencies = [ | ||
| 635 | "derive_builder_core", | ||
| 636 | "syn", | ||
| 637 | ] | ||
| 638 | |||
| 639 | [[package]] | ||
| 640 | name = "derive_more" | ||
| 641 | version = "0.99.17" | ||
| 642 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 643 | checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" | ||
| 644 | dependencies = [ | ||
| 645 | "convert_case", | ||
| 646 | "proc-macro2", | ||
| 647 | "quote", | ||
| 648 | "rustc_version", | ||
| 649 | "syn", | ||
| 650 | ] | ||
| 651 | |||
| 652 | [[package]] | ||
| 653 | name = "digest" | ||
| 654 | version = "0.9.0" | ||
| 655 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 656 | checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" | ||
| 657 | dependencies = [ | ||
| 658 | "generic-array", | ||
| 659 | ] | ||
| 660 | |||
| 661 | [[package]] | ||
| 662 | name = "digest" | ||
| 663 | version = "0.10.6" | ||
| 664 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 665 | checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" | ||
| 666 | dependencies = [ | ||
| 667 | "block-buffer 0.10.3", | ||
| 668 | "crypto-common", | ||
| 669 | "subtle", | ||
| 670 | ] | ||
| 671 | |||
| 672 | [[package]] | ||
| 673 | name = "dirs" | ||
| 674 | version = "4.0.0" | ||
| 675 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 676 | checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" | ||
| 677 | dependencies = [ | ||
| 678 | "dirs-sys", | ||
| 679 | ] | ||
| 680 | |||
| 681 | [[package]] | ||
| 682 | name = "dirs-sys" | ||
| 683 | version = "0.3.7" | ||
| 684 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 685 | checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" | ||
| 686 | dependencies = [ | ||
| 687 | "libc", | ||
| 688 | "redox_users", | ||
| 689 | "winapi", | ||
| 690 | ] | ||
| 691 | |||
| 692 | [[package]] | ||
| 693 | name = "discard" | ||
| 694 | version = "1.0.4" | ||
| 695 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 696 | checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" | ||
| 697 | |||
| 698 | [[package]] | ||
| 699 | name = "displaydoc" | ||
| 700 | version = "0.2.3" | ||
| 701 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 702 | checksum = "3bf95dc3f046b9da4f2d51833c0d3547d8564ef6910f5c1ed130306a75b92886" | ||
| 703 | dependencies = [ | ||
| 704 | "proc-macro2", | ||
| 705 | "quote", | ||
| 706 | "syn", | ||
| 707 | ] | ||
| 708 | |||
| 709 | [[package]] | ||
| 710 | name = "ed25519" | ||
| 711 | version = "1.5.2" | ||
| 712 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 713 | checksum = "1e9c280362032ea4203659fc489832d0204ef09f247a0506f170dafcac08c369" | ||
| 714 | dependencies = [ | ||
| 715 | "serde", | ||
| 716 | "signature", | ||
| 717 | ] | ||
| 718 | |||
| 719 | [[package]] | ||
| 720 | name = "ed25519-dalek" | ||
| 721 | version = "1.0.1" | ||
| 722 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 723 | checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" | ||
| 724 | dependencies = [ | ||
| 725 | "curve25519-dalek", | ||
| 726 | "ed25519", | ||
| 727 | "rand 0.7.3", | ||
| 728 | "serde", | ||
| 729 | "serde_bytes", | ||
| 730 | "sha2 0.9.9", | ||
| 731 | "zeroize", | ||
| 732 | ] | ||
| 733 | |||
| 734 | [[package]] | ||
| 735 | name = "either" | ||
| 736 | version = "1.8.0" | ||
| 737 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 738 | checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" | ||
| 739 | |||
| 740 | [[package]] | ||
| 741 | name = "encoding_rs" | ||
| 742 | version = "0.8.31" | ||
| 743 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 744 | checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" | ||
| 745 | dependencies = [ | ||
| 746 | "cfg-if", | ||
| 747 | ] | ||
| 748 | |||
| 749 | [[package]] | ||
| 750 | name = "errno" | ||
| 751 | version = "0.2.8" | ||
| 752 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 753 | checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" | ||
| 754 | dependencies = [ | ||
| 755 | "errno-dragonfly", | ||
| 756 | "libc", | ||
| 757 | "winapi", | ||
| 758 | ] | ||
| 759 | |||
| 760 | [[package]] | ||
| 761 | name = "errno-dragonfly" | ||
| 762 | version = "0.1.2" | ||
| 763 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 764 | checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" | ||
| 765 | dependencies = [ | ||
| 766 | "cc", | ||
| 767 | "libc", | ||
| 768 | ] | ||
| 769 | |||
| 770 | [[package]] | ||
| 771 | name = "event-listener" | ||
| 772 | version = "2.5.3" | ||
| 773 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 774 | checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" | ||
| 775 | |||
| 776 | [[package]] | ||
| 777 | name = "fastrand" | ||
| 778 | version = "1.8.0" | ||
| 779 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 780 | checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" | ||
| 781 | dependencies = [ | ||
| 782 | "instant", | ||
| 783 | ] | ||
| 784 | |||
| 785 | [[package]] | ||
| 786 | name = "fnv" | ||
| 787 | version = "1.0.7" | ||
| 788 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 789 | checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" | ||
| 790 | |||
| 791 | [[package]] | ||
| 792 | name = "form_urlencoded" | ||
| 793 | version = "1.1.0" | ||
| 794 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 795 | checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" | ||
| 796 | dependencies = [ | ||
| 797 | "percent-encoding", | ||
| 798 | ] | ||
| 799 | |||
| 800 | [[package]] | ||
| 801 | name = "fs2" | ||
| 802 | version = "0.4.3" | ||
| 803 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 804 | checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" | ||
| 805 | dependencies = [ | ||
| 806 | "libc", | ||
| 807 | "winapi", | ||
| 808 | ] | ||
| 809 | |||
| 810 | [[package]] | ||
| 811 | name = "fs_extra" | ||
| 812 | version = "1.2.0" | ||
| 813 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 814 | checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" | ||
| 815 | |||
| 816 | [[package]] | ||
| 817 | name = "futures" | ||
| 818 | version = "0.3.25" | ||
| 819 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 820 | checksum = "38390104763dc37a5145a53c29c63c1290b5d316d6086ec32c293f6736051bb0" | ||
| 821 | dependencies = [ | ||
| 822 | "futures-channel", | ||
| 823 | "futures-core", | ||
| 824 | "futures-executor", | ||
| 825 | "futures-io", | ||
| 826 | "futures-sink", | ||
| 827 | "futures-task", | ||
| 828 | "futures-util", | ||
| 829 | ] | ||
| 830 | |||
| 831 | [[package]] | ||
| 832 | name = "futures-channel" | ||
| 833 | version = "0.3.25" | ||
| 834 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 835 | checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed" | ||
| 836 | dependencies = [ | ||
| 837 | "futures-core", | ||
| 838 | "futures-sink", | ||
| 839 | ] | ||
| 840 | |||
| 841 | [[package]] | ||
| 842 | name = "futures-core" | ||
| 843 | version = "0.3.25" | ||
| 844 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 845 | checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" | ||
| 846 | |||
| 847 | [[package]] | ||
| 848 | name = "futures-executor" | ||
| 849 | version = "0.3.25" | ||
| 850 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 851 | checksum = "7acc85df6714c176ab5edf386123fafe217be88c0840ec11f199441134a074e2" | ||
| 852 | dependencies = [ | ||
| 853 | "futures-core", | ||
| 854 | "futures-task", | ||
| 855 | "futures-util", | ||
| 856 | ] | ||
| 857 | |||
| 858 | [[package]] | ||
| 859 | name = "futures-io" | ||
| 860 | version = "0.3.25" | ||
| 861 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 862 | checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb" | ||
| 863 | |||
| 864 | [[package]] | ||
| 865 | name = "futures-lite" | ||
| 866 | version = "1.12.0" | ||
| 867 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 868 | checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48" | ||
| 869 | dependencies = [ | ||
| 870 | "fastrand", | ||
| 871 | "futures-core", | ||
| 872 | "futures-io", | ||
| 873 | "memchr", | ||
| 874 | "parking", | ||
| 875 | "pin-project-lite", | ||
| 876 | "waker-fn", | ||
| 877 | ] | ||
| 878 | |||
| 879 | [[package]] | ||
| 880 | name = "futures-macro" | ||
| 881 | version = "0.3.25" | ||
| 882 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 883 | checksum = "bdfb8ce053d86b91919aad980c220b1fb8401a9394410e1c289ed7e66b61835d" | ||
| 884 | dependencies = [ | ||
| 885 | "proc-macro2", | ||
| 886 | "quote", | ||
| 887 | "syn", | ||
| 888 | ] | ||
| 889 | |||
| 890 | [[package]] | ||
| 891 | name = "futures-signals" | ||
| 892 | version = "0.3.31" | ||
| 893 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 894 | checksum = "a3acc659ba666cff13fdf65242d16428f2f11935b688f82e4024ad39667a5132" | ||
| 895 | dependencies = [ | ||
| 896 | "discard", | ||
| 897 | "futures-channel", | ||
| 898 | "futures-core", | ||
| 899 | "futures-util", | ||
| 900 | "pin-project", | ||
| 901 | ] | ||
| 902 | |||
| 903 | [[package]] | ||
| 904 | name = "futures-sink" | ||
| 905 | version = "0.3.25" | ||
| 906 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 907 | checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9" | ||
| 908 | |||
| 909 | [[package]] | ||
| 910 | name = "futures-task" | ||
| 911 | version = "0.3.25" | ||
| 912 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 913 | checksum = "2ffb393ac5d9a6eaa9d3fdf37ae2776656b706e200c8e16b1bdb227f5198e6ea" | ||
| 914 | |||
| 915 | [[package]] | ||
| 916 | name = "futures-util" | ||
| 917 | version = "0.3.25" | ||
| 918 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 919 | checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6" | ||
| 920 | dependencies = [ | ||
| 921 | "futures-channel", | ||
| 922 | "futures-core", | ||
| 923 | "futures-io", | ||
| 924 | "futures-macro", | ||
| 925 | "futures-sink", | ||
| 926 | "futures-task", | ||
| 927 | "memchr", | ||
| 928 | "pin-project-lite", | ||
| 929 | "pin-utils", | ||
| 930 | "slab", | ||
| 931 | ] | ||
| 932 | |||
| 933 | [[package]] | ||
| 934 | name = "fxhash" | ||
| 935 | version = "0.2.1" | ||
| 936 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 937 | checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" | ||
| 938 | dependencies = [ | ||
| 939 | "byteorder", | ||
| 940 | ] | ||
| 941 | |||
| 942 | [[package]] | ||
| 943 | name = "generic-array" | ||
| 944 | version = "0.14.6" | ||
| 945 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 946 | checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" | ||
| 947 | dependencies = [ | ||
| 948 | "typenum", | ||
| 949 | "version_check", | ||
| 950 | ] | ||
| 951 | |||
| 952 | [[package]] | ||
| 953 | name = "gethostname" | ||
| 954 | version = "0.4.1" | ||
| 955 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 956 | checksum = "8a329e22866dd78b35d2c639a4a23d7b950aeae300dfd79f4fb19f74055c2404" | ||
| 957 | dependencies = [ | ||
| 958 | "libc", | ||
| 959 | "windows", | ||
| 960 | ] | ||
| 961 | |||
| 962 | [[package]] | ||
| 963 | name = "getrandom" | ||
| 964 | version = "0.1.16" | ||
| 965 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 966 | checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" | ||
| 967 | dependencies = [ | ||
| 968 | "cfg-if", | ||
| 969 | "js-sys", | ||
| 970 | "libc", | ||
| 971 | "wasi 0.9.0+wasi-snapshot-preview1", | ||
| 972 | "wasm-bindgen", | ||
| 973 | ] | ||
| 974 | |||
| 975 | [[package]] | ||
| 976 | name = "getrandom" | ||
| 977 | version = "0.2.8" | ||
| 978 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 979 | checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" | ||
| 980 | dependencies = [ | ||
| 981 | "cfg-if", | ||
| 982 | "js-sys", | ||
| 983 | "libc", | ||
| 984 | "wasi 0.11.0+wasi-snapshot-preview1", | ||
| 985 | "wasm-bindgen", | ||
| 986 | ] | ||
| 987 | |||
| 988 | [[package]] | ||
| 989 | name = "h2" | ||
| 990 | version = "0.3.15" | ||
| 991 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 992 | checksum = "5f9f29bc9dda355256b2916cf526ab02ce0aeaaaf2bad60d65ef3f12f11dd0f4" | ||
| 993 | dependencies = [ | ||
| 994 | "bytes", | ||
| 995 | "fnv", | ||
| 996 | "futures-core", | ||
| 997 | "futures-sink", | ||
| 998 | "futures-util", | ||
| 999 | "http", | ||
| 1000 | "indexmap", | ||
| 1001 | "slab", | ||
| 1002 | "tokio", | ||
| 1003 | "tokio-util", | ||
| 1004 | "tracing", | ||
| 1005 | ] | ||
| 1006 | |||
| 1007 | [[package]] | ||
| 1008 | name = "hashbrown" | ||
| 1009 | version = "0.12.3" | ||
| 1010 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1011 | checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" | ||
| 1012 | dependencies = [ | ||
| 1013 | "ahash", | ||
| 1014 | ] | ||
| 1015 | |||
| 1016 | [[package]] | ||
| 1017 | name = "heck" | ||
| 1018 | version = "0.4.0" | ||
| 1019 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1020 | checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" | ||
| 1021 | |||
| 1022 | [[package]] | ||
| 1023 | name = "hermit-abi" | ||
| 1024 | version = "0.1.19" | ||
| 1025 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1026 | checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" | ||
| 1027 | dependencies = [ | ||
| 1028 | "libc", | ||
| 1029 | ] | ||
| 1030 | |||
| 1031 | [[package]] | ||
| 1032 | name = "hermit-abi" | ||
| 1033 | version = "0.2.6" | ||
| 1034 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1035 | checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" | ||
| 1036 | dependencies = [ | ||
| 1037 | "libc", | ||
| 1038 | ] | ||
| 1039 | |||
| 1040 | [[package]] | ||
| 1041 | name = "hkdf" | ||
| 1042 | version = "0.12.3" | ||
| 1043 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1044 | checksum = "791a029f6b9fc27657f6f188ec6e5e43f6911f6f878e0dc5501396e09809d437" | ||
| 1045 | dependencies = [ | ||
| 1046 | "hmac", | ||
| 1047 | ] | ||
| 1048 | |||
| 1049 | [[package]] | ||
| 1050 | name = "hmac" | ||
| 1051 | version = "0.12.1" | ||
| 1052 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1053 | checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" | ||
| 1054 | dependencies = [ | ||
| 1055 | "digest 0.10.6", | ||
| 1056 | ] | ||
| 1057 | |||
| 1058 | [[package]] | ||
| 1059 | name = "http" | ||
| 1060 | version = "0.2.8" | ||
| 1061 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1062 | checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" | ||
| 1063 | dependencies = [ | ||
| 1064 | "bytes", | ||
| 1065 | "fnv", | ||
| 1066 | "itoa", | ||
| 1067 | ] | ||
| 1068 | |||
| 1069 | [[package]] | ||
| 1070 | name = "http-body" | ||
| 1071 | version = "0.4.5" | ||
| 1072 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1073 | checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" | ||
| 1074 | dependencies = [ | ||
| 1075 | "bytes", | ||
| 1076 | "http", | ||
| 1077 | "pin-project-lite", | ||
| 1078 | ] | ||
| 1079 | |||
| 1080 | [[package]] | ||
| 1081 | name = "httparse" | ||
| 1082 | version = "1.8.0" | ||
| 1083 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1084 | checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" | ||
| 1085 | |||
| 1086 | [[package]] | ||
| 1087 | name = "httpdate" | ||
| 1088 | version = "1.0.2" | ||
| 1089 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1090 | checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" | ||
| 1091 | |||
| 1092 | [[package]] | ||
| 1093 | name = "hyper" | ||
| 1094 | version = "0.14.23" | ||
| 1095 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1096 | checksum = "034711faac9d2166cb1baf1a2fb0b60b1f277f8492fd72176c17f3515e1abd3c" | ||
| 1097 | dependencies = [ | ||
| 1098 | "bytes", | ||
| 1099 | "futures-channel", | ||
| 1100 | "futures-core", | ||
| 1101 | "futures-util", | ||
| 1102 | "h2", | ||
| 1103 | "http", | ||
| 1104 | "http-body", | ||
| 1105 | "httparse", | ||
| 1106 | "httpdate", | ||
| 1107 | "itoa", | ||
| 1108 | "pin-project-lite", | ||
| 1109 | "socket2", | ||
| 1110 | "tokio", | ||
| 1111 | "tower-service", | ||
| 1112 | "tracing", | ||
| 1113 | "want", | ||
| 1114 | ] | ||
| 1115 | |||
| 1116 | [[package]] | ||
| 1117 | name = "hyper-rustls" | ||
| 1118 | version = "0.23.2" | ||
| 1119 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1120 | checksum = "1788965e61b367cd03a62950836d5cd41560c3577d90e40e0819373194d1661c" | ||
| 1121 | dependencies = [ | ||
| 1122 | "http", | ||
| 1123 | "hyper", | ||
| 1124 | "rustls", | ||
| 1125 | "tokio", | ||
| 1126 | "tokio-rustls", | ||
| 1127 | ] | ||
| 1128 | |||
| 5 | [[package]] | 1129 | [[package]] |
| 6 | name = "iamb" | 1130 | name = "iamb" |
| 7 | version = "0.0.1" | 1131 | version = "0.0.1" |
| 1132 | dependencies = [ | ||
| 1133 | "chrono", | ||
| 1134 | "clap", | ||
| 1135 | "dirs", | ||
| 1136 | "futures", | ||
| 1137 | "gethostname", | ||
| 1138 | "lazy_static", | ||
| 1139 | "matrix-sdk", | ||
| 1140 | "modalkit", | ||
| 1141 | "regex", | ||
| 1142 | "rpassword", | ||
| 1143 | "serde", | ||
| 1144 | "serde_json", | ||
| 1145 | "sled", | ||
| 1146 | "thiserror", | ||
| 1147 | "tokio", | ||
| 1148 | "tracing", | ||
| 1149 | "tracing-appender", | ||
| 1150 | "tracing-subscriber", | ||
| 1151 | "unicode-segmentation", | ||
| 1152 | "unicode-width", | ||
| 1153 | "url", | ||
| 1154 | ] | ||
| 1155 | |||
| 1156 | [[package]] | ||
| 1157 | name = "iana-time-zone" | ||
| 1158 | version = "0.1.53" | ||
| 1159 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1160 | checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" | ||
| 1161 | dependencies = [ | ||
| 1162 | "android_system_properties", | ||
| 1163 | "core-foundation-sys", | ||
| 1164 | "iana-time-zone-haiku", | ||
| 1165 | "js-sys", | ||
| 1166 | "wasm-bindgen", | ||
| 1167 | "winapi", | ||
| 1168 | ] | ||
| 1169 | |||
| 1170 | [[package]] | ||
| 1171 | name = "iana-time-zone-haiku" | ||
| 1172 | version = "0.1.1" | ||
| 1173 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1174 | checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" | ||
| 1175 | dependencies = [ | ||
| 1176 | "cxx", | ||
| 1177 | "cxx-build", | ||
| 1178 | ] | ||
| 1179 | |||
| 1180 | [[package]] | ||
| 1181 | name = "ident_case" | ||
| 1182 | version = "1.0.1" | ||
| 1183 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1184 | checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" | ||
| 1185 | |||
| 1186 | [[package]] | ||
| 1187 | name = "idna" | ||
| 1188 | version = "0.3.0" | ||
| 1189 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1190 | checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" | ||
| 1191 | dependencies = [ | ||
| 1192 | "unicode-bidi", | ||
| 1193 | "unicode-normalization", | ||
| 1194 | ] | ||
| 1195 | |||
| 1196 | [[package]] | ||
| 1197 | name = "indexed_db_futures" | ||
| 1198 | version = "0.2.3" | ||
| 1199 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1200 | checksum = "d26ac735f676c52305becf53264b91cea9866a8de61ccbf464405b377b9cbca9" | ||
| 1201 | dependencies = [ | ||
| 1202 | "cfg-if", | ||
| 1203 | "js-sys", | ||
| 1204 | "uuid 0.8.2", | ||
| 1205 | "wasm-bindgen", | ||
| 1206 | "wasm-bindgen-futures", | ||
| 1207 | "web-sys", | ||
| 1208 | ] | ||
| 1209 | |||
| 1210 | [[package]] | ||
| 1211 | name = "indexmap" | ||
| 1212 | version = "1.9.2" | ||
| 1213 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1214 | checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" | ||
| 1215 | dependencies = [ | ||
| 1216 | "autocfg", | ||
| 1217 | "hashbrown", | ||
| 1218 | "serde", | ||
| 1219 | ] | ||
| 1220 | |||
| 1221 | [[package]] | ||
| 1222 | name = "inout" | ||
| 1223 | version = "0.1.3" | ||
| 1224 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1225 | checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" | ||
| 1226 | dependencies = [ | ||
| 1227 | "block-padding", | ||
| 1228 | "generic-array", | ||
| 1229 | ] | ||
| 1230 | |||
| 1231 | [[package]] | ||
| 1232 | name = "instant" | ||
| 1233 | version = "0.1.12" | ||
| 1234 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1235 | checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" | ||
| 1236 | dependencies = [ | ||
| 1237 | "cfg-if", | ||
| 1238 | "js-sys", | ||
| 1239 | "wasm-bindgen", | ||
| 1240 | "web-sys", | ||
| 1241 | ] | ||
| 1242 | |||
| 1243 | [[package]] | ||
| 1244 | name = "intervaltree" | ||
| 1245 | version = "0.2.7" | ||
| 1246 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1247 | checksum = "270bc34e57047cab801a8c871c124d9dc7132f6473c6401f645524f4e6edd111" | ||
| 1248 | dependencies = [ | ||
| 1249 | "smallvec", | ||
| 1250 | ] | ||
| 1251 | |||
| 1252 | [[package]] | ||
| 1253 | name = "io-lifetimes" | ||
| 1254 | version = "1.0.3" | ||
| 1255 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1256 | checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" | ||
| 1257 | dependencies = [ | ||
| 1258 | "libc", | ||
| 1259 | "windows-sys", | ||
| 1260 | ] | ||
| 1261 | |||
| 1262 | [[package]] | ||
| 1263 | name = "ipnet" | ||
| 1264 | version = "2.7.0" | ||
| 1265 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1266 | checksum = "11b0d96e660696543b251e58030cf9787df56da39dab19ad60eae7353040917e" | ||
| 1267 | |||
| 1268 | [[package]] | ||
| 1269 | name = "is-terminal" | ||
| 1270 | version = "0.4.1" | ||
| 1271 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1272 | checksum = "927609f78c2913a6f6ac3c27a4fe87f43e2a35367c0c4b0f8265e8f49a104330" | ||
| 1273 | dependencies = [ | ||
| 1274 | "hermit-abi 0.2.6", | ||
| 1275 | "io-lifetimes", | ||
| 1276 | "rustix", | ||
| 1277 | "windows-sys", | ||
| 1278 | ] | ||
| 1279 | |||
| 1280 | [[package]] | ||
| 1281 | name = "itertools" | ||
| 1282 | version = "0.10.5" | ||
| 1283 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1284 | checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" | ||
| 1285 | dependencies = [ | ||
| 1286 | "either", | ||
| 1287 | ] | ||
| 1288 | |||
| 1289 | [[package]] | ||
| 1290 | name = "itoa" | ||
| 1291 | version = "1.0.5" | ||
| 1292 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1293 | checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" | ||
| 1294 | |||
| 1295 | [[package]] | ||
| 1296 | name = "js-sys" | ||
| 1297 | version = "0.3.60" | ||
| 1298 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1299 | checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" | ||
| 1300 | dependencies = [ | ||
| 1301 | "wasm-bindgen", | ||
| 1302 | ] | ||
| 1303 | |||
| 1304 | [[package]] | ||
| 1305 | name = "js_int" | ||
| 1306 | version = "0.2.2" | ||
| 1307 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1308 | checksum = "d937f95470b270ce8b8950207715d71aa8e153c0d44c6684d59397ed4949160a" | ||
| 1309 | dependencies = [ | ||
| 1310 | "serde", | ||
| 1311 | ] | ||
| 1312 | |||
| 1313 | [[package]] | ||
| 1314 | name = "js_option" | ||
| 1315 | version = "0.1.1" | ||
| 1316 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1317 | checksum = "68421373957a1593a767013698dbf206e2b221eefe97a44d98d18672ff38423c" | ||
| 1318 | dependencies = [ | ||
| 1319 | "serde", | ||
| 1320 | ] | ||
| 1321 | |||
| 1322 | [[package]] | ||
| 1323 | name = "lazy_static" | ||
| 1324 | version = "1.4.0" | ||
| 1325 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1326 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" | ||
| 1327 | |||
| 1328 | [[package]] | ||
| 1329 | name = "libc" | ||
| 1330 | version = "0.2.138" | ||
| 1331 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1332 | checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" | ||
| 1333 | |||
| 1334 | [[package]] | ||
| 1335 | name = "link-cplusplus" | ||
| 1336 | version = "1.0.8" | ||
| 1337 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1338 | checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5" | ||
| 1339 | dependencies = [ | ||
| 1340 | "cc", | ||
| 1341 | ] | ||
| 1342 | |||
| 1343 | [[package]] | ||
| 1344 | name = "linux-raw-sys" | ||
| 1345 | version = "0.1.4" | ||
| 1346 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1347 | checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" | ||
| 1348 | |||
| 1349 | [[package]] | ||
| 1350 | name = "lock_api" | ||
| 1351 | version = "0.4.9" | ||
| 1352 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1353 | checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" | ||
| 1354 | dependencies = [ | ||
| 1355 | "autocfg", | ||
| 1356 | "scopeguard", | ||
| 1357 | ] | ||
| 1358 | |||
| 1359 | [[package]] | ||
| 1360 | name = "log" | ||
| 1361 | version = "0.4.17" | ||
| 1362 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1363 | checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" | ||
| 1364 | dependencies = [ | ||
| 1365 | "cfg-if", | ||
| 1366 | ] | ||
| 1367 | |||
| 1368 | [[package]] | ||
| 1369 | name = "lru" | ||
| 1370 | version = "0.8.1" | ||
| 1371 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1372 | checksum = "b6e8aaa3f231bb4bd57b84b2d5dc3ae7f350265df8aa96492e0bc394a1571909" | ||
| 1373 | dependencies = [ | ||
| 1374 | "hashbrown", | ||
| 1375 | ] | ||
| 1376 | |||
| 1377 | [[package]] | ||
| 1378 | name = "maplit" | ||
| 1379 | version = "1.0.2" | ||
| 1380 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1381 | checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" | ||
| 1382 | |||
| 1383 | [[package]] | ||
| 1384 | name = "matrix-sdk" | ||
| 1385 | version = "0.6.2" | ||
| 1386 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1387 | checksum = "cbeafb4809f33f377165f2fbcf10e0613053ad206762194c3050a727fd3abcb2" | ||
| 1388 | dependencies = [ | ||
| 1389 | "anymap2", | ||
| 1390 | "async-once-cell", | ||
| 1391 | "async-stream", | ||
| 1392 | "async-trait", | ||
| 1393 | "backoff", | ||
| 1394 | "bytes", | ||
| 1395 | "dashmap", | ||
| 1396 | "derive_builder", | ||
| 1397 | "event-listener", | ||
| 1398 | "futures-core", | ||
| 1399 | "futures-signals", | ||
| 1400 | "futures-util", | ||
| 1401 | "http", | ||
| 1402 | "matrix-sdk-base", | ||
| 1403 | "matrix-sdk-common", | ||
| 1404 | "matrix-sdk-indexeddb", | ||
| 1405 | "matrix-sdk-sled", | ||
| 1406 | "mime", | ||
| 1407 | "reqwest", | ||
| 1408 | "ruma", | ||
| 1409 | "serde", | ||
| 1410 | "serde_json", | ||
| 1411 | "thiserror", | ||
| 1412 | "tokio", | ||
| 1413 | "tracing", | ||
| 1414 | "url", | ||
| 1415 | "wasm-timer", | ||
| 1416 | "zeroize", | ||
| 1417 | ] | ||
| 1418 | |||
| 1419 | [[package]] | ||
| 1420 | name = "matrix-sdk-base" | ||
| 1421 | version = "0.6.1" | ||
| 1422 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1423 | checksum = "b944f6d1fc8779ba790dd0b942ceff45c626c1f5da847f01122d355ad06511bd" | ||
| 1424 | dependencies = [ | ||
| 1425 | "async-stream", | ||
| 1426 | "async-trait", | ||
| 1427 | "dashmap", | ||
| 1428 | "futures-channel", | ||
| 1429 | "futures-core", | ||
| 1430 | "futures-signals", | ||
| 1431 | "futures-util", | ||
| 1432 | "lru", | ||
| 1433 | "matrix-sdk-common", | ||
| 1434 | "matrix-sdk-crypto", | ||
| 1435 | "once_cell", | ||
| 1436 | "ruma", | ||
| 1437 | "serde", | ||
| 1438 | "serde_json", | ||
| 1439 | "thiserror", | ||
| 1440 | "tracing", | ||
| 1441 | "zeroize", | ||
| 1442 | ] | ||
| 1443 | |||
| 1444 | [[package]] | ||
| 1445 | name = "matrix-sdk-common" | ||
| 1446 | version = "0.6.0" | ||
| 1447 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1448 | checksum = "b85a6a743cc9dcf9385e61a26db78276078beddd27f3762d9d82baa2030695f1" | ||
| 1449 | dependencies = [ | ||
| 1450 | "async-lock", | ||
| 1451 | "futures-core", | ||
| 1452 | "futures-util", | ||
| 1453 | "instant", | ||
| 1454 | "ruma", | ||
| 1455 | "serde", | ||
| 1456 | "tokio", | ||
| 1457 | "wasm-bindgen-futures", | ||
| 1458 | "wasm-timer", | ||
| 1459 | ] | ||
| 1460 | |||
| 1461 | [[package]] | ||
| 1462 | name = "matrix-sdk-crypto" | ||
| 1463 | version = "0.6.0" | ||
| 1464 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1465 | checksum = "68fa699e8dd54578a4b92e3fcd18a50da8e415a0c042da1706b0330fc2d8f949" | ||
| 1466 | dependencies = [ | ||
| 1467 | "aes", | ||
| 1468 | "async-trait", | ||
| 1469 | "atomic", | ||
| 1470 | "base64", | ||
| 1471 | "byteorder", | ||
| 1472 | "ctr", | ||
| 1473 | "dashmap", | ||
| 1474 | "event-listener", | ||
| 1475 | "futures-util", | ||
| 1476 | "hmac", | ||
| 1477 | "matrix-sdk-common", | ||
| 1478 | "pbkdf2", | ||
| 1479 | "rand 0.8.5", | ||
| 1480 | "ruma", | ||
| 1481 | "serde", | ||
| 1482 | "serde_json", | ||
| 1483 | "sha2 0.10.6", | ||
| 1484 | "thiserror", | ||
| 1485 | "tokio", | ||
| 1486 | "tracing", | ||
| 1487 | "vodozemac", | ||
| 1488 | "zeroize", | ||
| 1489 | ] | ||
| 1490 | |||
| 1491 | [[package]] | ||
| 1492 | name = "matrix-sdk-indexeddb" | ||
| 1493 | version = "0.2.0" | ||
| 1494 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1495 | checksum = "7847d36bba832bc787214323bc042b71dca7fdf2aee9f0e3eb573b64f2f7eb7f" | ||
| 1496 | dependencies = [ | ||
| 1497 | "anyhow", | ||
| 1498 | "async-trait", | ||
| 1499 | "base64", | ||
| 1500 | "dashmap", | ||
| 1501 | "derive_builder", | ||
| 1502 | "getrandom 0.2.8", | ||
| 1503 | "indexed_db_futures", | ||
| 1504 | "js-sys", | ||
| 1505 | "matrix-sdk-base", | ||
| 1506 | "matrix-sdk-crypto", | ||
| 1507 | "matrix-sdk-store-encryption", | ||
| 1508 | "ruma", | ||
| 1509 | "serde", | ||
| 1510 | "serde_json", | ||
| 1511 | "thiserror", | ||
| 1512 | "tracing", | ||
| 1513 | "wasm-bindgen", | ||
| 1514 | "web-sys", | ||
| 1515 | ] | ||
| 1516 | |||
| 1517 | [[package]] | ||
| 1518 | name = "matrix-sdk-sled" | ||
| 1519 | version = "0.2.0" | ||
| 1520 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1521 | checksum = "5ded5a703ad8a82b8edfde808228711315c8761a5fbf7ac2b98ab4951dadd066" | ||
| 1522 | dependencies = [ | ||
| 1523 | "async-stream", | ||
| 1524 | "async-trait", | ||
| 1525 | "dashmap", | ||
| 1526 | "derive_builder", | ||
| 1527 | "fs_extra", | ||
| 1528 | "futures-core", | ||
| 1529 | "futures-util", | ||
| 1530 | "matrix-sdk-base", | ||
| 1531 | "matrix-sdk-common", | ||
| 1532 | "matrix-sdk-crypto", | ||
| 1533 | "matrix-sdk-store-encryption", | ||
| 1534 | "ruma", | ||
| 1535 | "serde", | ||
| 1536 | "serde_json", | ||
| 1537 | "sled", | ||
| 1538 | "thiserror", | ||
| 1539 | "tokio", | ||
| 1540 | "tracing", | ||
| 1541 | ] | ||
| 1542 | |||
| 1543 | [[package]] | ||
| 1544 | name = "matrix-sdk-store-encryption" | ||
| 1545 | version = "0.2.0" | ||
| 1546 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1547 | checksum = "9ddee75c3cca58f3a323283dc4e849d19d52988903f907ed0fb53dcad5d6fd25" | ||
| 1548 | dependencies = [ | ||
| 1549 | "blake3", | ||
| 1550 | "chacha20poly1305", | ||
| 1551 | "displaydoc", | ||
| 1552 | "hmac", | ||
| 1553 | "pbkdf2", | ||
| 1554 | "rand 0.8.5", | ||
| 1555 | "serde", | ||
| 1556 | "serde_json", | ||
| 1557 | "sha2 0.10.6", | ||
| 1558 | "thiserror", | ||
| 1559 | "zeroize", | ||
| 1560 | ] | ||
| 1561 | |||
| 1562 | [[package]] | ||
| 1563 | name = "memchr" | ||
| 1564 | version = "2.5.0" | ||
| 1565 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1566 | checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" | ||
| 1567 | |||
| 1568 | [[package]] | ||
| 1569 | name = "memoffset" | ||
| 1570 | version = "0.7.1" | ||
| 1571 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1572 | checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" | ||
| 1573 | dependencies = [ | ||
| 1574 | "autocfg", | ||
| 1575 | ] | ||
| 1576 | |||
| 1577 | [[package]] | ||
| 1578 | name = "mime" | ||
| 1579 | version = "0.3.16" | ||
| 1580 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1581 | checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" | ||
| 1582 | |||
| 1583 | [[package]] | ||
| 1584 | name = "minimal-lexical" | ||
| 1585 | version = "0.2.1" | ||
| 1586 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1587 | checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" | ||
| 1588 | |||
| 1589 | [[package]] | ||
| 1590 | name = "mio" | ||
| 1591 | version = "0.8.5" | ||
| 1592 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1593 | checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" | ||
| 1594 | dependencies = [ | ||
| 1595 | "libc", | ||
| 1596 | "log", | ||
| 1597 | "wasi 0.11.0+wasi-snapshot-preview1", | ||
| 1598 | "windows-sys", | ||
| 1599 | ] | ||
| 1600 | |||
| 1601 | [[package]] | ||
| 1602 | name = "modalkit" | ||
| 1603 | version = "0.0.7" | ||
| 1604 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1605 | checksum = "dc4385b7136847cd063fbf093f0aa21a098398e26dc9213137fdd4e4f593d6bf" | ||
| 1606 | dependencies = [ | ||
| 1607 | "anymap2", | ||
| 1608 | "bitflags", | ||
| 1609 | "crossterm", | ||
| 1610 | "derive_more", | ||
| 1611 | "intervaltree", | ||
| 1612 | "libc", | ||
| 1613 | "nom", | ||
| 1614 | "regex", | ||
| 1615 | "ropey", | ||
| 1616 | "thiserror", | ||
| 1617 | "tui", | ||
| 1618 | ] | ||
| 1619 | |||
| 1620 | [[package]] | ||
| 1621 | name = "nom" | ||
| 1622 | version = "7.1.1" | ||
| 1623 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1624 | checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" | ||
| 1625 | dependencies = [ | ||
| 1626 | "memchr", | ||
| 1627 | "minimal-lexical", | ||
| 1628 | ] | ||
| 1629 | |||
| 1630 | [[package]] | ||
| 1631 | name = "nu-ansi-term" | ||
| 1632 | version = "0.46.0" | ||
| 1633 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1634 | checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" | ||
| 1635 | dependencies = [ | ||
| 1636 | "overload", | ||
| 1637 | "winapi", | ||
| 1638 | ] | ||
| 1639 | |||
| 1640 | [[package]] | ||
| 1641 | name = "num-integer" | ||
| 1642 | version = "0.1.45" | ||
| 1643 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1644 | checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" | ||
| 1645 | dependencies = [ | ||
| 1646 | "autocfg", | ||
| 1647 | "num-traits", | ||
| 1648 | ] | ||
| 1649 | |||
| 1650 | [[package]] | ||
| 1651 | name = "num-traits" | ||
| 1652 | version = "0.2.15" | ||
| 1653 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1654 | checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" | ||
| 1655 | dependencies = [ | ||
| 1656 | "autocfg", | ||
| 1657 | ] | ||
| 1658 | |||
| 1659 | [[package]] | ||
| 1660 | name = "num_cpus" | ||
| 1661 | version = "1.14.0" | ||
| 1662 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1663 | checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" | ||
| 1664 | dependencies = [ | ||
| 1665 | "hermit-abi 0.1.19", | ||
| 1666 | "libc", | ||
| 1667 | ] | ||
| 1668 | |||
| 1669 | [[package]] | ||
| 1670 | name = "once_cell" | ||
| 1671 | version = "1.16.0" | ||
| 1672 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1673 | checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" | ||
| 1674 | |||
| 1675 | [[package]] | ||
| 1676 | name = "opaque-debug" | ||
| 1677 | version = "0.3.0" | ||
| 1678 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1679 | checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" | ||
| 1680 | |||
| 1681 | [[package]] | ||
| 1682 | name = "os_str_bytes" | ||
| 1683 | version = "6.4.1" | ||
| 1684 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1685 | checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" | ||
| 1686 | |||
| 1687 | [[package]] | ||
| 1688 | name = "overload" | ||
| 1689 | version = "0.1.1" | ||
| 1690 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1691 | checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" | ||
| 1692 | |||
| 1693 | [[package]] | ||
| 1694 | name = "parking" | ||
| 1695 | version = "2.0.0" | ||
| 1696 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1697 | checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" | ||
| 1698 | |||
| 1699 | [[package]] | ||
| 1700 | name = "parking_lot" | ||
| 1701 | version = "0.11.2" | ||
| 1702 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1703 | checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" | ||
| 1704 | dependencies = [ | ||
| 1705 | "instant", | ||
| 1706 | "lock_api", | ||
| 1707 | "parking_lot_core 0.8.6", | ||
| 1708 | ] | ||
| 1709 | |||
| 1710 | [[package]] | ||
| 1711 | name = "parking_lot" | ||
| 1712 | version = "0.12.1" | ||
| 1713 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1714 | checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" | ||
| 1715 | dependencies = [ | ||
| 1716 | "lock_api", | ||
| 1717 | "parking_lot_core 0.9.5", | ||
| 1718 | ] | ||
| 1719 | |||
| 1720 | [[package]] | ||
| 1721 | name = "parking_lot_core" | ||
| 1722 | version = "0.8.6" | ||
| 1723 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1724 | checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" | ||
| 1725 | dependencies = [ | ||
| 1726 | "cfg-if", | ||
| 1727 | "instant", | ||
| 1728 | "libc", | ||
| 1729 | "redox_syscall", | ||
| 1730 | "smallvec", | ||
| 1731 | "winapi", | ||
| 1732 | ] | ||
| 1733 | |||
| 1734 | [[package]] | ||
| 1735 | name = "parking_lot_core" | ||
| 1736 | version = "0.9.5" | ||
| 1737 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1738 | checksum = "7ff9f3fef3968a3ec5945535ed654cb38ff72d7495a25619e2247fb15a2ed9ba" | ||
| 1739 | dependencies = [ | ||
| 1740 | "cfg-if", | ||
| 1741 | "libc", | ||
| 1742 | "redox_syscall", | ||
| 1743 | "smallvec", | ||
| 1744 | "windows-sys", | ||
| 1745 | ] | ||
| 1746 | |||
| 1747 | [[package]] | ||
| 1748 | name = "password-hash" | ||
| 1749 | version = "0.4.2" | ||
| 1750 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1751 | checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" | ||
| 1752 | dependencies = [ | ||
| 1753 | "base64ct", | ||
| 1754 | "rand_core 0.6.4", | ||
| 1755 | "subtle", | ||
| 1756 | ] | ||
| 1757 | |||
| 1758 | [[package]] | ||
| 1759 | name = "pbkdf2" | ||
| 1760 | version = "0.11.0" | ||
| 1761 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1762 | checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" | ||
| 1763 | dependencies = [ | ||
| 1764 | "digest 0.10.6", | ||
| 1765 | "hmac", | ||
| 1766 | "password-hash", | ||
| 1767 | "sha2 0.10.6", | ||
| 1768 | ] | ||
| 1769 | |||
| 1770 | [[package]] | ||
| 1771 | name = "percent-encoding" | ||
| 1772 | version = "2.2.0" | ||
| 1773 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1774 | checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" | ||
| 1775 | |||
| 1776 | [[package]] | ||
| 1777 | name = "pin-project" | ||
| 1778 | version = "1.0.12" | ||
| 1779 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1780 | checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" | ||
| 1781 | dependencies = [ | ||
| 1782 | "pin-project-internal", | ||
| 1783 | ] | ||
| 1784 | |||
| 1785 | [[package]] | ||
| 1786 | name = "pin-project-internal" | ||
| 1787 | version = "1.0.12" | ||
| 1788 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1789 | checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" | ||
| 1790 | dependencies = [ | ||
| 1791 | "proc-macro2", | ||
| 1792 | "quote", | ||
| 1793 | "syn", | ||
| 1794 | ] | ||
| 1795 | |||
| 1796 | [[package]] | ||
| 1797 | name = "pin-project-lite" | ||
| 1798 | version = "0.2.9" | ||
| 1799 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1800 | checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" | ||
| 1801 | |||
| 1802 | [[package]] | ||
| 1803 | name = "pin-utils" | ||
| 1804 | version = "0.1.0" | ||
| 1805 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1806 | checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" | ||
| 1807 | |||
| 1808 | [[package]] | ||
| 1809 | name = "pkcs7" | ||
| 1810 | version = "0.3.0" | ||
| 1811 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1812 | checksum = "1f7364e6d0e236473de91e042395d71e0e64715f99a60620b014a4a4c7d1619b" | ||
| 1813 | dependencies = [ | ||
| 1814 | "der", | ||
| 1815 | "spki", | ||
| 1816 | ] | ||
| 1817 | |||
| 1818 | [[package]] | ||
| 1819 | name = "poly1305" | ||
| 1820 | version = "0.7.2" | ||
| 1821 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1822 | checksum = "048aeb476be11a4b6ca432ca569e375810de9294ae78f4774e78ea98a9246ede" | ||
| 1823 | dependencies = [ | ||
| 1824 | "cpufeatures", | ||
| 1825 | "opaque-debug", | ||
| 1826 | "universal-hash", | ||
| 1827 | ] | ||
| 1828 | |||
| 1829 | [[package]] | ||
| 1830 | name = "ppv-lite86" | ||
| 1831 | version = "0.2.17" | ||
| 1832 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1833 | checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" | ||
| 1834 | |||
| 1835 | [[package]] | ||
| 1836 | name = "proc-macro-crate" | ||
| 1837 | version = "1.2.1" | ||
| 1838 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1839 | checksum = "eda0fc3b0fb7c975631757e14d9049da17374063edb6ebbcbc54d880d4fe94e9" | ||
| 1840 | dependencies = [ | ||
| 1841 | "once_cell", | ||
| 1842 | "thiserror", | ||
| 1843 | "toml", | ||
| 1844 | ] | ||
| 1845 | |||
| 1846 | [[package]] | ||
| 1847 | name = "proc-macro-error" | ||
| 1848 | version = "1.0.4" | ||
| 1849 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1850 | checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" | ||
| 1851 | dependencies = [ | ||
| 1852 | "proc-macro-error-attr", | ||
| 1853 | "proc-macro2", | ||
| 1854 | "quote", | ||
| 1855 | "syn", | ||
| 1856 | "version_check", | ||
| 1857 | ] | ||
| 1858 | |||
| 1859 | [[package]] | ||
| 1860 | name = "proc-macro-error-attr" | ||
| 1861 | version = "1.0.4" | ||
| 1862 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1863 | checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" | ||
| 1864 | dependencies = [ | ||
| 1865 | "proc-macro2", | ||
| 1866 | "quote", | ||
| 1867 | "version_check", | ||
| 1868 | ] | ||
| 1869 | |||
| 1870 | [[package]] | ||
| 1871 | name = "proc-macro2" | ||
| 1872 | version = "1.0.48" | ||
| 1873 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1874 | checksum = "e9d89e5dba24725ae5678020bf8f1357a9aa7ff10736b551adbcd3f8d17d766f" | ||
| 1875 | dependencies = [ | ||
| 1876 | "unicode-ident", | ||
| 1877 | ] | ||
| 1878 | |||
| 1879 | [[package]] | ||
| 1880 | name = "prost" | ||
| 1881 | version = "0.11.3" | ||
| 1882 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1883 | checksum = "c0b18e655c21ff5ac2084a5ad0611e827b3f92badf79f4910b5a5c58f4d87ff0" | ||
| 1884 | dependencies = [ | ||
| 1885 | "bytes", | ||
| 1886 | "prost-derive", | ||
| 1887 | ] | ||
| 1888 | |||
| 1889 | [[package]] | ||
| 1890 | name = "prost-derive" | ||
| 1891 | version = "0.11.2" | ||
| 1892 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1893 | checksum = "164ae68b6587001ca506d3bf7f1000bfa248d0e1217b618108fba4ec1d0cc306" | ||
| 1894 | dependencies = [ | ||
| 1895 | "anyhow", | ||
| 1896 | "itertools", | ||
| 1897 | "proc-macro2", | ||
| 1898 | "quote", | ||
| 1899 | "syn", | ||
| 1900 | ] | ||
| 1901 | |||
| 1902 | [[package]] | ||
| 1903 | name = "quote" | ||
| 1904 | version = "1.0.22" | ||
| 1905 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1906 | checksum = "556d0f47a940e895261e77dc200d5eadfc6ef644c179c6f5edfc105e3a2292c8" | ||
| 1907 | dependencies = [ | ||
| 1908 | "proc-macro2", | ||
| 1909 | ] | ||
| 1910 | |||
| 1911 | [[package]] | ||
| 1912 | name = "rand" | ||
| 1913 | version = "0.7.3" | ||
| 1914 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1915 | checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" | ||
| 1916 | dependencies = [ | ||
| 1917 | "getrandom 0.1.16", | ||
| 1918 | "libc", | ||
| 1919 | "rand_chacha 0.2.2", | ||
| 1920 | "rand_core 0.5.1", | ||
| 1921 | "rand_hc", | ||
| 1922 | ] | ||
| 1923 | |||
| 1924 | [[package]] | ||
| 1925 | name = "rand" | ||
| 1926 | version = "0.8.5" | ||
| 1927 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1928 | checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" | ||
| 1929 | dependencies = [ | ||
| 1930 | "libc", | ||
| 1931 | "rand_chacha 0.3.1", | ||
| 1932 | "rand_core 0.6.4", | ||
| 1933 | ] | ||
| 1934 | |||
| 1935 | [[package]] | ||
| 1936 | name = "rand_chacha" | ||
| 1937 | version = "0.2.2" | ||
| 1938 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1939 | checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" | ||
| 1940 | dependencies = [ | ||
| 1941 | "ppv-lite86", | ||
| 1942 | "rand_core 0.5.1", | ||
| 1943 | ] | ||
| 1944 | |||
| 1945 | [[package]] | ||
| 1946 | name = "rand_chacha" | ||
| 1947 | version = "0.3.1" | ||
| 1948 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1949 | checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" | ||
| 1950 | dependencies = [ | ||
| 1951 | "ppv-lite86", | ||
| 1952 | "rand_core 0.6.4", | ||
| 1953 | ] | ||
| 1954 | |||
| 1955 | [[package]] | ||
| 1956 | name = "rand_core" | ||
| 1957 | version = "0.5.1" | ||
| 1958 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1959 | checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" | ||
| 1960 | dependencies = [ | ||
| 1961 | "getrandom 0.1.16", | ||
| 1962 | ] | ||
| 1963 | |||
| 1964 | [[package]] | ||
| 1965 | name = "rand_core" | ||
| 1966 | version = "0.6.4" | ||
| 1967 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1968 | checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" | ||
| 1969 | dependencies = [ | ||
| 1970 | "getrandom 0.2.8", | ||
| 1971 | ] | ||
| 1972 | |||
| 1973 | [[package]] | ||
| 1974 | name = "rand_hc" | ||
| 1975 | version = "0.2.0" | ||
| 1976 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1977 | checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" | ||
| 1978 | dependencies = [ | ||
| 1979 | "rand_core 0.5.1", | ||
| 1980 | ] | ||
| 1981 | |||
| 1982 | [[package]] | ||
| 1983 | name = "redox_syscall" | ||
| 1984 | version = "0.2.16" | ||
| 1985 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1986 | checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" | ||
| 1987 | dependencies = [ | ||
| 1988 | "bitflags", | ||
| 1989 | ] | ||
| 1990 | |||
| 1991 | [[package]] | ||
| 1992 | name = "redox_users" | ||
| 1993 | version = "0.4.3" | ||
| 1994 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1995 | checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" | ||
| 1996 | dependencies = [ | ||
| 1997 | "getrandom 0.2.8", | ||
| 1998 | "redox_syscall", | ||
| 1999 | "thiserror", | ||
| 2000 | ] | ||
| 2001 | |||
| 2002 | [[package]] | ||
| 2003 | name = "regex" | ||
| 2004 | version = "1.7.0" | ||
| 2005 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2006 | checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" | ||
| 2007 | dependencies = [ | ||
| 2008 | "aho-corasick", | ||
| 2009 | "memchr", | ||
| 2010 | "regex-syntax", | ||
| 2011 | ] | ||
| 2012 | |||
| 2013 | [[package]] | ||
| 2014 | name = "regex-syntax" | ||
| 2015 | version = "0.6.28" | ||
| 2016 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2017 | checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" | ||
| 2018 | |||
| 2019 | [[package]] | ||
| 2020 | name = "reqwest" | ||
| 2021 | version = "0.11.13" | ||
| 2022 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2023 | checksum = "68cc60575865c7831548863cc02356512e3f1dc2f3f82cb837d7fc4cc8f3c97c" | ||
| 2024 | dependencies = [ | ||
| 2025 | "base64", | ||
| 2026 | "bytes", | ||
| 2027 | "encoding_rs", | ||
| 2028 | "futures-core", | ||
| 2029 | "futures-util", | ||
| 2030 | "h2", | ||
| 2031 | "http", | ||
| 2032 | "http-body", | ||
| 2033 | "hyper", | ||
| 2034 | "hyper-rustls", | ||
| 2035 | "ipnet", | ||
| 2036 | "js-sys", | ||
| 2037 | "log", | ||
| 2038 | "mime", | ||
| 2039 | "once_cell", | ||
| 2040 | "percent-encoding", | ||
| 2041 | "pin-project-lite", | ||
| 2042 | "rustls", | ||
| 2043 | "rustls-pemfile", | ||
| 2044 | "serde", | ||
| 2045 | "serde_json", | ||
| 2046 | "serde_urlencoded", | ||
| 2047 | "tokio", | ||
| 2048 | "tokio-rustls", | ||
| 2049 | "tower-service", | ||
| 2050 | "url", | ||
| 2051 | "wasm-bindgen", | ||
| 2052 | "wasm-bindgen-futures", | ||
| 2053 | "web-sys", | ||
| 2054 | "webpki-roots", | ||
| 2055 | "winreg", | ||
| 2056 | ] | ||
| 2057 | |||
| 2058 | [[package]] | ||
| 2059 | name = "ring" | ||
| 2060 | version = "0.16.20" | ||
| 2061 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2062 | checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" | ||
| 2063 | dependencies = [ | ||
| 2064 | "cc", | ||
| 2065 | "libc", | ||
| 2066 | "once_cell", | ||
| 2067 | "spin", | ||
| 2068 | "untrusted", | ||
| 2069 | "web-sys", | ||
| 2070 | "winapi", | ||
| 2071 | ] | ||
| 2072 | |||
| 2073 | [[package]] | ||
| 2074 | name = "ropey" | ||
| 2075 | version = "1.5.0" | ||
| 2076 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2077 | checksum = "bbd22239fafefc42138ca5da064f3c17726a80d2379d817a3521240e78dd0064" | ||
| 2078 | dependencies = [ | ||
| 2079 | "smallvec", | ||
| 2080 | "str_indices", | ||
| 2081 | ] | ||
| 2082 | |||
| 2083 | [[package]] | ||
| 2084 | name = "rpassword" | ||
| 2085 | version = "7.2.0" | ||
| 2086 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2087 | checksum = "6678cf63ab3491898c0d021b493c94c9b221d91295294a2a5746eacbe5928322" | ||
| 2088 | dependencies = [ | ||
| 2089 | "libc", | ||
| 2090 | "rtoolbox", | ||
| 2091 | "winapi", | ||
| 2092 | ] | ||
| 2093 | |||
| 2094 | [[package]] | ||
| 2095 | name = "rtoolbox" | ||
| 2096 | version = "0.0.1" | ||
| 2097 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2098 | checksum = "034e22c514f5c0cb8a10ff341b9b048b5ceb21591f31c8f44c43b960f9b3524a" | ||
| 2099 | dependencies = [ | ||
| 2100 | "libc", | ||
| 2101 | "winapi", | ||
| 2102 | ] | ||
| 2103 | |||
| 2104 | [[package]] | ||
| 2105 | name = "ruma" | ||
| 2106 | version = "0.7.4" | ||
| 2107 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2108 | checksum = "8dc348e3a4a18abc4e97fffa5e2e623f6edd50ba3a1dd5f47eb249fea713b69f" | ||
| 2109 | dependencies = [ | ||
| 2110 | "assign", | ||
| 2111 | "js_int", | ||
| 2112 | "js_option", | ||
| 2113 | "ruma-client-api", | ||
| 2114 | "ruma-common", | ||
| 2115 | "ruma-federation-api", | ||
| 2116 | ] | ||
| 2117 | |||
| 2118 | [[package]] | ||
| 2119 | name = "ruma-client-api" | ||
| 2120 | version = "0.15.3" | ||
| 2121 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2122 | checksum = "d1e72bc731b4dc8b569aa83915f13e419144b67110d858c65bb74aa05e2dc4b7" | ||
| 2123 | dependencies = [ | ||
| 2124 | "assign", | ||
| 2125 | "bytes", | ||
| 2126 | "http", | ||
| 2127 | "js_int", | ||
| 2128 | "maplit", | ||
| 2129 | "percent-encoding", | ||
| 2130 | "ruma-common", | ||
| 2131 | "serde", | ||
| 2132 | "serde_json", | ||
| 2133 | ] | ||
| 2134 | |||
| 2135 | [[package]] | ||
| 2136 | name = "ruma-common" | ||
| 2137 | version = "0.10.5" | ||
| 2138 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2139 | checksum = "716889595f4edc3cfeb94d9f122e413f73e37d7d80ea1c14196e1004241a3889" | ||
| 2140 | dependencies = [ | ||
| 2141 | "base64", | ||
| 2142 | "bytes", | ||
| 2143 | "form_urlencoded", | ||
| 2144 | "getrandom 0.2.8", | ||
| 2145 | "http", | ||
| 2146 | "indexmap", | ||
| 2147 | "itoa", | ||
| 2148 | "js-sys", | ||
| 2149 | "js_int", | ||
| 2150 | "js_option", | ||
| 2151 | "percent-encoding", | ||
| 2152 | "rand 0.8.5", | ||
| 2153 | "regex", | ||
| 2154 | "ruma-identifiers-validation", | ||
| 2155 | "ruma-macros", | ||
| 2156 | "serde", | ||
| 2157 | "serde_json", | ||
| 2158 | "thiserror", | ||
| 2159 | "tracing", | ||
| 2160 | "url", | ||
| 2161 | "uuid 1.2.2", | ||
| 2162 | "wildmatch", | ||
| 2163 | ] | ||
| 2164 | |||
| 2165 | [[package]] | ||
| 2166 | name = "ruma-federation-api" | ||
| 2167 | version = "0.6.0" | ||
| 2168 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2169 | checksum = "9f905d12f6144c7a754bd0339fa6893698c03d03a908abb20cc6eeb4ec7f9466" | ||
| 2170 | dependencies = [ | ||
| 2171 | "js_int", | ||
| 2172 | "ruma-common", | ||
| 2173 | "serde", | ||
| 2174 | "serde_json", | ||
| 2175 | ] | ||
| 2176 | |||
| 2177 | [[package]] | ||
| 2178 | name = "ruma-identifiers-validation" | ||
| 2179 | version = "0.9.0" | ||
| 2180 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2181 | checksum = "eabac62d16465a87435579c779d74dceabb93b09e44c766af6085050f3cc4275" | ||
| 2182 | dependencies = [ | ||
| 2183 | "js_int", | ||
| 2184 | "thiserror", | ||
| 2185 | ] | ||
| 2186 | |||
| 2187 | [[package]] | ||
| 2188 | name = "ruma-macros" | ||
| 2189 | version = "0.10.5" | ||
| 2190 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2191 | checksum = "0f82e91eb61cd86d9287303133ee55b54618eccb75a522cc22a42c15f5bda340" | ||
| 2192 | dependencies = [ | ||
| 2193 | "once_cell", | ||
| 2194 | "proc-macro-crate", | ||
| 2195 | "proc-macro2", | ||
| 2196 | "quote", | ||
| 2197 | "ruma-identifiers-validation", | ||
| 2198 | "serde", | ||
| 2199 | "syn", | ||
| 2200 | "toml", | ||
| 2201 | ] | ||
| 2202 | |||
| 2203 | [[package]] | ||
| 2204 | name = "rustc_version" | ||
| 2205 | version = "0.4.0" | ||
| 2206 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2207 | checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" | ||
| 2208 | dependencies = [ | ||
| 2209 | "semver", | ||
| 2210 | ] | ||
| 2211 | |||
| 2212 | [[package]] | ||
| 2213 | name = "rustix" | ||
| 2214 | version = "0.36.5" | ||
| 2215 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2216 | checksum = "a3807b5d10909833d3e9acd1eb5fb988f79376ff10fce42937de71a449c4c588" | ||
| 2217 | dependencies = [ | ||
| 2218 | "bitflags", | ||
| 2219 | "errno", | ||
| 2220 | "io-lifetimes", | ||
| 2221 | "libc", | ||
| 2222 | "linux-raw-sys", | ||
| 2223 | "windows-sys", | ||
| 2224 | ] | ||
| 2225 | |||
| 2226 | [[package]] | ||
| 2227 | name = "rustls" | ||
| 2228 | version = "0.20.7" | ||
| 2229 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2230 | checksum = "539a2bfe908f471bfa933876bd1eb6a19cf2176d375f82ef7f99530a40e48c2c" | ||
| 2231 | dependencies = [ | ||
| 2232 | "log", | ||
| 2233 | "ring", | ||
| 2234 | "sct", | ||
| 2235 | "webpki", | ||
| 2236 | ] | ||
| 2237 | |||
| 2238 | [[package]] | ||
| 2239 | name = "rustls-pemfile" | ||
| 2240 | version = "1.0.1" | ||
| 2241 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2242 | checksum = "0864aeff53f8c05aa08d86e5ef839d3dfcf07aeba2db32f12db0ef716e87bd55" | ||
| 2243 | dependencies = [ | ||
| 2244 | "base64", | ||
| 2245 | ] | ||
| 2246 | |||
| 2247 | [[package]] | ||
| 2248 | name = "ryu" | ||
| 2249 | version = "1.0.12" | ||
| 2250 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2251 | checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" | ||
| 2252 | |||
| 2253 | [[package]] | ||
| 2254 | name = "scopeguard" | ||
| 2255 | version = "1.1.0" | ||
| 2256 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2257 | checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" | ||
| 2258 | |||
| 2259 | [[package]] | ||
| 2260 | name = "scratch" | ||
| 2261 | version = "1.0.3" | ||
| 2262 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2263 | checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2" | ||
| 2264 | |||
| 2265 | [[package]] | ||
| 2266 | name = "sct" | ||
| 2267 | version = "0.7.0" | ||
| 2268 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2269 | checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" | ||
| 2270 | dependencies = [ | ||
| 2271 | "ring", | ||
| 2272 | "untrusted", | ||
| 2273 | ] | ||
| 2274 | |||
| 2275 | [[package]] | ||
| 2276 | name = "semver" | ||
| 2277 | version = "1.0.15" | ||
| 2278 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2279 | checksum = "3bfa246f936730408c0abee392cc1a50b118ece708c7f630516defd64480c7d8" | ||
| 2280 | |||
| 2281 | [[package]] | ||
| 2282 | name = "serde" | ||
| 2283 | version = "1.0.151" | ||
| 2284 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2285 | checksum = "97fed41fc1a24994d044e6db6935e69511a1153b52c15eb42493b26fa87feba0" | ||
| 2286 | dependencies = [ | ||
| 2287 | "serde_derive", | ||
| 2288 | ] | ||
| 2289 | |||
| 2290 | [[package]] | ||
| 2291 | name = "serde_bytes" | ||
| 2292 | version = "0.11.8" | ||
| 2293 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2294 | checksum = "718dc5fff5b36f99093fc49b280cfc96ce6fc824317783bff5a1fed0c7a64819" | ||
| 2295 | dependencies = [ | ||
| 2296 | "serde", | ||
| 2297 | ] | ||
| 2298 | |||
| 2299 | [[package]] | ||
| 2300 | name = "serde_derive" | ||
| 2301 | version = "1.0.151" | ||
| 2302 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2303 | checksum = "255abe9a125a985c05190d687b320c12f9b1f0b99445e608c21ba0782c719ad8" | ||
| 2304 | dependencies = [ | ||
| 2305 | "proc-macro2", | ||
| 2306 | "quote", | ||
| 2307 | "syn", | ||
| 2308 | ] | ||
| 2309 | |||
| 2310 | [[package]] | ||
| 2311 | name = "serde_json" | ||
| 2312 | version = "1.0.90" | ||
| 2313 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2314 | checksum = "8778cc0b528968fe72abec38b5db5a20a70d148116cd9325d2bc5f5180ca3faf" | ||
| 2315 | dependencies = [ | ||
| 2316 | "itoa", | ||
| 2317 | "ryu", | ||
| 2318 | "serde", | ||
| 2319 | ] | ||
| 2320 | |||
| 2321 | [[package]] | ||
| 2322 | name = "serde_urlencoded" | ||
| 2323 | version = "0.7.1" | ||
| 2324 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2325 | checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" | ||
| 2326 | dependencies = [ | ||
| 2327 | "form_urlencoded", | ||
| 2328 | "itoa", | ||
| 2329 | "ryu", | ||
| 2330 | "serde", | ||
| 2331 | ] | ||
| 2332 | |||
| 2333 | [[package]] | ||
| 2334 | name = "sha2" | ||
| 2335 | version = "0.9.9" | ||
| 2336 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2337 | checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" | ||
| 2338 | dependencies = [ | ||
| 2339 | "block-buffer 0.9.0", | ||
| 2340 | "cfg-if", | ||
| 2341 | "cpufeatures", | ||
| 2342 | "digest 0.9.0", | ||
| 2343 | "opaque-debug", | ||
| 2344 | ] | ||
| 2345 | |||
| 2346 | [[package]] | ||
| 2347 | name = "sha2" | ||
| 2348 | version = "0.10.6" | ||
| 2349 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2350 | checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" | ||
| 2351 | dependencies = [ | ||
| 2352 | "cfg-if", | ||
| 2353 | "cpufeatures", | ||
| 2354 | "digest 0.10.6", | ||
| 2355 | ] | ||
| 2356 | |||
| 2357 | [[package]] | ||
| 2358 | name = "sharded-slab" | ||
| 2359 | version = "0.1.4" | ||
| 2360 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2361 | checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" | ||
| 2362 | dependencies = [ | ||
| 2363 | "lazy_static", | ||
| 2364 | ] | ||
| 2365 | |||
| 2366 | [[package]] | ||
| 2367 | name = "signal-hook" | ||
| 2368 | version = "0.3.14" | ||
| 2369 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2370 | checksum = "a253b5e89e2698464fc26b545c9edceb338e18a89effeeecfea192c3025be29d" | ||
| 2371 | dependencies = [ | ||
| 2372 | "libc", | ||
| 2373 | "signal-hook-registry", | ||
| 2374 | ] | ||
| 2375 | |||
| 2376 | [[package]] | ||
| 2377 | name = "signal-hook-mio" | ||
| 2378 | version = "0.2.3" | ||
| 2379 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2380 | checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" | ||
| 2381 | dependencies = [ | ||
| 2382 | "libc", | ||
| 2383 | "mio", | ||
| 2384 | "signal-hook", | ||
| 2385 | ] | ||
| 2386 | |||
| 2387 | [[package]] | ||
| 2388 | name = "signal-hook-registry" | ||
| 2389 | version = "1.4.0" | ||
| 2390 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2391 | checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" | ||
| 2392 | dependencies = [ | ||
| 2393 | "libc", | ||
| 2394 | ] | ||
| 2395 | |||
| 2396 | [[package]] | ||
| 2397 | name = "signature" | ||
| 2398 | version = "1.6.4" | ||
| 2399 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2400 | checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" | ||
| 2401 | |||
| 2402 | [[package]] | ||
| 2403 | name = "slab" | ||
| 2404 | version = "0.4.7" | ||
| 2405 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2406 | checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" | ||
| 2407 | dependencies = [ | ||
| 2408 | "autocfg", | ||
| 2409 | ] | ||
| 2410 | |||
| 2411 | [[package]] | ||
| 2412 | name = "sled" | ||
| 2413 | version = "0.34.7" | ||
| 2414 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2415 | checksum = "7f96b4737c2ce5987354855aed3797279def4ebf734436c6aa4552cf8e169935" | ||
| 2416 | dependencies = [ | ||
| 2417 | "crc32fast", | ||
| 2418 | "crossbeam-epoch", | ||
| 2419 | "crossbeam-utils", | ||
| 2420 | "fs2", | ||
| 2421 | "fxhash", | ||
| 2422 | "libc", | ||
| 2423 | "log", | ||
| 2424 | "parking_lot 0.11.2", | ||
| 2425 | ] | ||
| 2426 | |||
| 2427 | [[package]] | ||
| 2428 | name = "smallvec" | ||
| 2429 | version = "1.10.0" | ||
| 2430 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2431 | checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" | ||
| 2432 | |||
| 2433 | [[package]] | ||
| 2434 | name = "socket2" | ||
| 2435 | version = "0.4.7" | ||
| 2436 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2437 | checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" | ||
| 2438 | dependencies = [ | ||
| 2439 | "libc", | ||
| 2440 | "winapi", | ||
| 2441 | ] | ||
| 2442 | |||
| 2443 | [[package]] | ||
| 2444 | name = "spin" | ||
| 2445 | version = "0.5.2" | ||
| 2446 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2447 | checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" | ||
| 2448 | |||
| 2449 | [[package]] | ||
| 2450 | name = "spki" | ||
| 2451 | version = "0.5.4" | ||
| 2452 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2453 | checksum = "44d01ac02a6ccf3e07db148d2be087da624fea0221a16152ed01f0496a6b0a27" | ||
| 2454 | dependencies = [ | ||
| 2455 | "der", | ||
| 2456 | ] | ||
| 2457 | |||
| 2458 | [[package]] | ||
| 2459 | name = "str_indices" | ||
| 2460 | version = "0.4.0" | ||
| 2461 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2462 | checksum = "9d9199fa80c817e074620be84374a520062ebac833f358d74b37060ce4a0f2c0" | ||
| 2463 | |||
| 2464 | [[package]] | ||
| 2465 | name = "strsim" | ||
| 2466 | version = "0.10.0" | ||
| 2467 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2468 | checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" | ||
| 2469 | |||
| 2470 | [[package]] | ||
| 2471 | name = "subtle" | ||
| 2472 | version = "2.4.1" | ||
| 2473 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2474 | checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" | ||
| 2475 | |||
| 2476 | [[package]] | ||
| 2477 | name = "syn" | ||
| 2478 | version = "1.0.106" | ||
| 2479 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2480 | checksum = "09ee3a69cd2c7e06684677e5629b3878b253af05e4714964204279c6bc02cf0b" | ||
| 2481 | dependencies = [ | ||
| 2482 | "proc-macro2", | ||
| 2483 | "quote", | ||
| 2484 | "unicode-ident", | ||
| 2485 | ] | ||
| 2486 | |||
| 2487 | [[package]] | ||
| 2488 | name = "synstructure" | ||
| 2489 | version = "0.12.6" | ||
| 2490 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2491 | checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" | ||
| 2492 | dependencies = [ | ||
| 2493 | "proc-macro2", | ||
| 2494 | "quote", | ||
| 2495 | "syn", | ||
| 2496 | "unicode-xid", | ||
| 2497 | ] | ||
| 2498 | |||
| 2499 | [[package]] | ||
| 2500 | name = "termcolor" | ||
| 2501 | version = "1.1.3" | ||
| 2502 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2503 | checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" | ||
| 2504 | dependencies = [ | ||
| 2505 | "winapi-util", | ||
| 2506 | ] | ||
| 2507 | |||
| 2508 | [[package]] | ||
| 2509 | name = "thiserror" | ||
| 2510 | version = "1.0.38" | ||
| 2511 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2512 | checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" | ||
| 2513 | dependencies = [ | ||
| 2514 | "thiserror-impl", | ||
| 2515 | ] | ||
| 2516 | |||
| 2517 | [[package]] | ||
| 2518 | name = "thiserror-impl" | ||
| 2519 | version = "1.0.38" | ||
| 2520 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2521 | checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" | ||
| 2522 | dependencies = [ | ||
| 2523 | "proc-macro2", | ||
| 2524 | "quote", | ||
| 2525 | "syn", | ||
| 2526 | ] | ||
| 2527 | |||
| 2528 | [[package]] | ||
| 2529 | name = "thread_local" | ||
| 2530 | version = "1.1.4" | ||
| 2531 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2532 | checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" | ||
| 2533 | dependencies = [ | ||
| 2534 | "once_cell", | ||
| 2535 | ] | ||
| 2536 | |||
| 2537 | [[package]] | ||
| 2538 | name = "time" | ||
| 2539 | version = "0.1.45" | ||
| 2540 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2541 | checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" | ||
| 2542 | dependencies = [ | ||
| 2543 | "libc", | ||
| 2544 | "wasi 0.10.0+wasi-snapshot-preview1", | ||
| 2545 | "winapi", | ||
| 2546 | ] | ||
| 2547 | |||
| 2548 | [[package]] | ||
| 2549 | name = "time" | ||
| 2550 | version = "0.3.17" | ||
| 2551 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2552 | checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376" | ||
| 2553 | dependencies = [ | ||
| 2554 | "itoa", | ||
| 2555 | "serde", | ||
| 2556 | "time-core", | ||
| 2557 | "time-macros", | ||
| 2558 | ] | ||
| 2559 | |||
| 2560 | [[package]] | ||
| 2561 | name = "time-core" | ||
| 2562 | version = "0.1.0" | ||
| 2563 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2564 | checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" | ||
| 2565 | |||
| 2566 | [[package]] | ||
| 2567 | name = "time-macros" | ||
| 2568 | version = "0.2.6" | ||
| 2569 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2570 | checksum = "d967f99f534ca7e495c575c62638eebc2898a8c84c119b89e250477bc4ba16b2" | ||
| 2571 | dependencies = [ | ||
| 2572 | "time-core", | ||
| 2573 | ] | ||
| 2574 | |||
| 2575 | [[package]] | ||
| 2576 | name = "tinyvec" | ||
| 2577 | version = "1.6.0" | ||
| 2578 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2579 | checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" | ||
| 2580 | dependencies = [ | ||
| 2581 | "tinyvec_macros", | ||
| 2582 | ] | ||
| 2583 | |||
| 2584 | [[package]] | ||
| 2585 | name = "tinyvec_macros" | ||
| 2586 | version = "0.1.0" | ||
| 2587 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2588 | checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" | ||
| 2589 | |||
| 2590 | [[package]] | ||
| 2591 | name = "tokio" | ||
| 2592 | version = "1.23.0" | ||
| 2593 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2594 | checksum = "eab6d665857cc6ca78d6e80303a02cea7a7851e85dfbd77cbdc09bd129f1ef46" | ||
| 2595 | dependencies = [ | ||
| 2596 | "autocfg", | ||
| 2597 | "bytes", | ||
| 2598 | "libc", | ||
| 2599 | "memchr", | ||
| 2600 | "mio", | ||
| 2601 | "num_cpus", | ||
| 2602 | "parking_lot 0.12.1", | ||
| 2603 | "pin-project-lite", | ||
| 2604 | "signal-hook-registry", | ||
| 2605 | "socket2", | ||
| 2606 | "tokio-macros", | ||
| 2607 | "windows-sys", | ||
| 2608 | ] | ||
| 2609 | |||
| 2610 | [[package]] | ||
| 2611 | name = "tokio-macros" | ||
| 2612 | version = "1.8.2" | ||
| 2613 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2614 | checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" | ||
| 2615 | dependencies = [ | ||
| 2616 | "proc-macro2", | ||
| 2617 | "quote", | ||
| 2618 | "syn", | ||
| 2619 | ] | ||
| 2620 | |||
| 2621 | [[package]] | ||
| 2622 | name = "tokio-rustls" | ||
| 2623 | version = "0.23.4" | ||
| 2624 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2625 | checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" | ||
| 2626 | dependencies = [ | ||
| 2627 | "rustls", | ||
| 2628 | "tokio", | ||
| 2629 | "webpki", | ||
| 2630 | ] | ||
| 2631 | |||
| 2632 | [[package]] | ||
| 2633 | name = "tokio-util" | ||
| 2634 | version = "0.7.4" | ||
| 2635 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2636 | checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" | ||
| 2637 | dependencies = [ | ||
| 2638 | "bytes", | ||
| 2639 | "futures-core", | ||
| 2640 | "futures-sink", | ||
| 2641 | "pin-project-lite", | ||
| 2642 | "tokio", | ||
| 2643 | "tracing", | ||
| 2644 | ] | ||
| 2645 | |||
| 2646 | [[package]] | ||
| 2647 | name = "toml" | ||
| 2648 | version = "0.5.10" | ||
| 2649 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2650 | checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f" | ||
| 2651 | dependencies = [ | ||
| 2652 | "serde", | ||
| 2653 | ] | ||
| 2654 | |||
| 2655 | [[package]] | ||
| 2656 | name = "tower-service" | ||
| 2657 | version = "0.3.2" | ||
| 2658 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2659 | checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" | ||
| 2660 | |||
| 2661 | [[package]] | ||
| 2662 | name = "tracing" | ||
| 2663 | version = "0.1.37" | ||
| 2664 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2665 | checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" | ||
| 2666 | dependencies = [ | ||
| 2667 | "cfg-if", | ||
| 2668 | "pin-project-lite", | ||
| 2669 | "tracing-attributes", | ||
| 2670 | "tracing-core", | ||
| 2671 | ] | ||
| 2672 | |||
| 2673 | [[package]] | ||
| 2674 | name = "tracing-appender" | ||
| 2675 | version = "0.2.2" | ||
| 2676 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2677 | checksum = "09d48f71a791638519505cefafe162606f706c25592e4bde4d97600c0195312e" | ||
| 2678 | dependencies = [ | ||
| 2679 | "crossbeam-channel", | ||
| 2680 | "time 0.3.17", | ||
| 2681 | "tracing-subscriber", | ||
| 2682 | ] | ||
| 2683 | |||
| 2684 | [[package]] | ||
| 2685 | name = "tracing-attributes" | ||
| 2686 | version = "0.1.23" | ||
| 2687 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2688 | checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" | ||
| 2689 | dependencies = [ | ||
| 2690 | "proc-macro2", | ||
| 2691 | "quote", | ||
| 2692 | "syn", | ||
| 2693 | ] | ||
| 2694 | |||
| 2695 | [[package]] | ||
| 2696 | name = "tracing-core" | ||
| 2697 | version = "0.1.30" | ||
| 2698 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2699 | checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" | ||
| 2700 | dependencies = [ | ||
| 2701 | "once_cell", | ||
| 2702 | "valuable", | ||
| 2703 | ] | ||
| 2704 | |||
| 2705 | [[package]] | ||
| 2706 | name = "tracing-log" | ||
| 2707 | version = "0.1.3" | ||
| 2708 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2709 | checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" | ||
| 2710 | dependencies = [ | ||
| 2711 | "lazy_static", | ||
| 2712 | "log", | ||
| 2713 | "tracing-core", | ||
| 2714 | ] | ||
| 2715 | |||
| 2716 | [[package]] | ||
| 2717 | name = "tracing-subscriber" | ||
| 2718 | version = "0.3.16" | ||
| 2719 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2720 | checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70" | ||
| 2721 | dependencies = [ | ||
| 2722 | "nu-ansi-term", | ||
| 2723 | "sharded-slab", | ||
| 2724 | "smallvec", | ||
| 2725 | "thread_local", | ||
| 2726 | "tracing-core", | ||
| 2727 | "tracing-log", | ||
| 2728 | ] | ||
| 2729 | |||
| 2730 | [[package]] | ||
| 2731 | name = "try-lock" | ||
| 2732 | version = "0.2.3" | ||
| 2733 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2734 | checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" | ||
| 2735 | |||
| 2736 | [[package]] | ||
| 2737 | name = "tui" | ||
| 2738 | version = "0.19.0" | ||
| 2739 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2740 | checksum = "ccdd26cbd674007e649a272da4475fb666d3aa0ad0531da7136db6fab0e5bad1" | ||
| 2741 | dependencies = [ | ||
| 2742 | "bitflags", | ||
| 2743 | "cassowary", | ||
| 2744 | "crossterm", | ||
| 2745 | "unicode-segmentation", | ||
| 2746 | "unicode-width", | ||
| 2747 | ] | ||
| 2748 | |||
| 2749 | [[package]] | ||
| 2750 | name = "typenum" | ||
| 2751 | version = "1.16.0" | ||
| 2752 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2753 | checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" | ||
| 2754 | |||
| 2755 | [[package]] | ||
| 2756 | name = "unicode-bidi" | ||
| 2757 | version = "0.3.8" | ||
| 2758 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2759 | checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" | ||
| 2760 | |||
| 2761 | [[package]] | ||
| 2762 | name = "unicode-ident" | ||
| 2763 | version = "1.0.6" | ||
| 2764 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2765 | checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" | ||
| 2766 | |||
| 2767 | [[package]] | ||
| 2768 | name = "unicode-normalization" | ||
| 2769 | version = "0.1.22" | ||
| 2770 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2771 | checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" | ||
| 2772 | dependencies = [ | ||
| 2773 | "tinyvec", | ||
| 2774 | ] | ||
| 2775 | |||
| 2776 | [[package]] | ||
| 2777 | name = "unicode-segmentation" | ||
| 2778 | version = "1.10.0" | ||
| 2779 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2780 | checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a" | ||
| 2781 | |||
| 2782 | [[package]] | ||
| 2783 | name = "unicode-width" | ||
| 2784 | version = "0.1.10" | ||
| 2785 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2786 | checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" | ||
| 2787 | |||
| 2788 | [[package]] | ||
| 2789 | name = "unicode-xid" | ||
| 2790 | version = "0.2.4" | ||
| 2791 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2792 | checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" | ||
| 2793 | |||
| 2794 | [[package]] | ||
| 2795 | name = "universal-hash" | ||
| 2796 | version = "0.4.1" | ||
| 2797 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2798 | checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05" | ||
| 2799 | dependencies = [ | ||
| 2800 | "generic-array", | ||
| 2801 | "subtle", | ||
| 2802 | ] | ||
| 2803 | |||
| 2804 | [[package]] | ||
| 2805 | name = "untrusted" | ||
| 2806 | version = "0.7.1" | ||
| 2807 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2808 | checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" | ||
| 2809 | |||
| 2810 | [[package]] | ||
| 2811 | name = "url" | ||
| 2812 | version = "2.3.1" | ||
| 2813 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2814 | checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" | ||
| 2815 | dependencies = [ | ||
| 2816 | "form_urlencoded", | ||
| 2817 | "idna", | ||
| 2818 | "percent-encoding", | ||
| 2819 | "serde", | ||
| 2820 | ] | ||
| 2821 | |||
| 2822 | [[package]] | ||
| 2823 | name = "uuid" | ||
| 2824 | version = "0.8.2" | ||
| 2825 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2826 | checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" | ||
| 2827 | dependencies = [ | ||
| 2828 | "getrandom 0.2.8", | ||
| 2829 | ] | ||
| 2830 | |||
| 2831 | [[package]] | ||
| 2832 | name = "uuid" | ||
| 2833 | version = "1.2.2" | ||
| 2834 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2835 | checksum = "422ee0de9031b5b948b97a8fc04e3aa35230001a722ddd27943e0be31564ce4c" | ||
| 2836 | dependencies = [ | ||
| 2837 | "getrandom 0.2.8", | ||
| 2838 | "wasm-bindgen", | ||
| 2839 | ] | ||
| 2840 | |||
| 2841 | [[package]] | ||
| 2842 | name = "valuable" | ||
| 2843 | version = "0.1.0" | ||
| 2844 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2845 | checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" | ||
| 2846 | |||
| 2847 | [[package]] | ||
| 2848 | name = "version_check" | ||
| 2849 | version = "0.9.4" | ||
| 2850 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2851 | checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" | ||
| 2852 | |||
| 2853 | [[package]] | ||
| 2854 | name = "vodozemac" | ||
| 2855 | version = "0.3.0" | ||
| 2856 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2857 | checksum = "f6f20153a1c82ac5f1243b62e80f067ae608facc415c6ef82f88426a61c79886" | ||
| 2858 | dependencies = [ | ||
| 2859 | "aes", | ||
| 2860 | "arrayvec", | ||
| 2861 | "base64", | ||
| 2862 | "cbc", | ||
| 2863 | "ed25519-dalek", | ||
| 2864 | "hkdf", | ||
| 2865 | "hmac", | ||
| 2866 | "pkcs7", | ||
| 2867 | "prost", | ||
| 2868 | "rand 0.7.3", | ||
| 2869 | "serde", | ||
| 2870 | "serde_json", | ||
| 2871 | "sha2 0.10.6", | ||
| 2872 | "subtle", | ||
| 2873 | "thiserror", | ||
| 2874 | "x25519-dalek", | ||
| 2875 | "zeroize", | ||
| 2876 | ] | ||
| 2877 | |||
| 2878 | [[package]] | ||
| 2879 | name = "waker-fn" | ||
| 2880 | version = "1.1.0" | ||
| 2881 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2882 | checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" | ||
| 2883 | |||
| 2884 | [[package]] | ||
| 2885 | name = "want" | ||
| 2886 | version = "0.3.0" | ||
| 2887 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2888 | checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" | ||
| 2889 | dependencies = [ | ||
| 2890 | "log", | ||
| 2891 | "try-lock", | ||
| 2892 | ] | ||
| 2893 | |||
| 2894 | [[package]] | ||
| 2895 | name = "wasi" | ||
| 2896 | version = "0.9.0+wasi-snapshot-preview1" | ||
| 2897 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2898 | checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" | ||
| 2899 | |||
| 2900 | [[package]] | ||
| 2901 | name = "wasi" | ||
| 2902 | version = "0.10.0+wasi-snapshot-preview1" | ||
| 2903 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2904 | checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" | ||
| 2905 | |||
| 2906 | [[package]] | ||
| 2907 | name = "wasi" | ||
| 2908 | version = "0.11.0+wasi-snapshot-preview1" | ||
| 2909 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2910 | checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" | ||
| 2911 | |||
| 2912 | [[package]] | ||
| 2913 | name = "wasm-bindgen" | ||
| 2914 | version = "0.2.83" | ||
| 2915 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2916 | checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" | ||
| 2917 | dependencies = [ | ||
| 2918 | "cfg-if", | ||
| 2919 | "serde", | ||
| 2920 | "serde_json", | ||
| 2921 | "wasm-bindgen-macro", | ||
| 2922 | ] | ||
| 2923 | |||
| 2924 | [[package]] | ||
| 2925 | name = "wasm-bindgen-backend" | ||
| 2926 | version = "0.2.83" | ||
| 2927 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2928 | checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" | ||
| 2929 | dependencies = [ | ||
| 2930 | "bumpalo", | ||
| 2931 | "log", | ||
| 2932 | "once_cell", | ||
| 2933 | "proc-macro2", | ||
| 2934 | "quote", | ||
| 2935 | "syn", | ||
| 2936 | "wasm-bindgen-shared", | ||
| 2937 | ] | ||
| 2938 | |||
| 2939 | [[package]] | ||
| 2940 | name = "wasm-bindgen-futures" | ||
| 2941 | version = "0.4.33" | ||
| 2942 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2943 | checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" | ||
| 2944 | dependencies = [ | ||
| 2945 | "cfg-if", | ||
| 2946 | "js-sys", | ||
| 2947 | "wasm-bindgen", | ||
| 2948 | "web-sys", | ||
| 2949 | ] | ||
| 2950 | |||
| 2951 | [[package]] | ||
| 2952 | name = "wasm-bindgen-macro" | ||
| 2953 | version = "0.2.83" | ||
| 2954 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2955 | checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" | ||
| 2956 | dependencies = [ | ||
| 2957 | "quote", | ||
| 2958 | "wasm-bindgen-macro-support", | ||
| 2959 | ] | ||
| 2960 | |||
| 2961 | [[package]] | ||
| 2962 | name = "wasm-bindgen-macro-support" | ||
| 2963 | version = "0.2.83" | ||
| 2964 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2965 | checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" | ||
| 2966 | dependencies = [ | ||
| 2967 | "proc-macro2", | ||
| 2968 | "quote", | ||
| 2969 | "syn", | ||
| 2970 | "wasm-bindgen-backend", | ||
| 2971 | "wasm-bindgen-shared", | ||
| 2972 | ] | ||
| 2973 | |||
| 2974 | [[package]] | ||
| 2975 | name = "wasm-bindgen-shared" | ||
| 2976 | version = "0.2.83" | ||
| 2977 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2978 | checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" | ||
| 2979 | |||
| 2980 | [[package]] | ||
| 2981 | name = "wasm-timer" | ||
| 2982 | version = "0.2.5" | ||
| 2983 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2984 | checksum = "be0ecb0db480561e9a7642b5d3e4187c128914e58aa84330b9493e3eb68c5e7f" | ||
| 2985 | dependencies = [ | ||
| 2986 | "futures", | ||
| 2987 | "js-sys", | ||
| 2988 | "parking_lot 0.11.2", | ||
| 2989 | "pin-utils", | ||
| 2990 | "wasm-bindgen", | ||
| 2991 | "wasm-bindgen-futures", | ||
| 2992 | "web-sys", | ||
| 2993 | ] | ||
| 2994 | |||
| 2995 | [[package]] | ||
| 2996 | name = "web-sys" | ||
| 2997 | version = "0.3.60" | ||
| 2998 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2999 | checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" | ||
| 3000 | dependencies = [ | ||
| 3001 | "js-sys", | ||
| 3002 | "wasm-bindgen", | ||
| 3003 | ] | ||
| 3004 | |||
| 3005 | [[package]] | ||
| 3006 | name = "webpki" | ||
| 3007 | version = "0.22.0" | ||
| 3008 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3009 | checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" | ||
| 3010 | dependencies = [ | ||
| 3011 | "ring", | ||
| 3012 | "untrusted", | ||
| 3013 | ] | ||
| 3014 | |||
| 3015 | [[package]] | ||
| 3016 | name = "webpki-roots" | ||
| 3017 | version = "0.22.6" | ||
| 3018 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3019 | checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" | ||
| 3020 | dependencies = [ | ||
| 3021 | "webpki", | ||
| 3022 | ] | ||
| 3023 | |||
| 3024 | [[package]] | ||
| 3025 | name = "wildmatch" | ||
| 3026 | version = "2.1.1" | ||
| 3027 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3028 | checksum = "ee583bdc5ff1cf9db20e9db5bb3ff4c3089a8f6b8b31aff265c9aba85812db86" | ||
| 3029 | |||
| 3030 | [[package]] | ||
| 3031 | name = "winapi" | ||
| 3032 | version = "0.3.9" | ||
| 3033 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3034 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" | ||
| 3035 | dependencies = [ | ||
| 3036 | "winapi-i686-pc-windows-gnu", | ||
| 3037 | "winapi-x86_64-pc-windows-gnu", | ||
| 3038 | ] | ||
| 3039 | |||
| 3040 | [[package]] | ||
| 3041 | name = "winapi-i686-pc-windows-gnu" | ||
| 3042 | version = "0.4.0" | ||
| 3043 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3044 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" | ||
| 3045 | |||
| 3046 | [[package]] | ||
| 3047 | name = "winapi-util" | ||
| 3048 | version = "0.1.5" | ||
| 3049 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3050 | checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" | ||
| 3051 | dependencies = [ | ||
| 3052 | "winapi", | ||
| 3053 | ] | ||
| 3054 | |||
| 3055 | [[package]] | ||
| 3056 | name = "winapi-x86_64-pc-windows-gnu" | ||
| 3057 | version = "0.4.0" | ||
| 3058 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3059 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" | ||
| 3060 | |||
| 3061 | [[package]] | ||
| 3062 | name = "windows" | ||
| 3063 | version = "0.43.0" | ||
| 3064 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3065 | checksum = "04662ed0e3e5630dfa9b26e4cb823b817f1a9addda855d973a9458c236556244" | ||
| 3066 | dependencies = [ | ||
| 3067 | "windows_aarch64_gnullvm", | ||
| 3068 | "windows_aarch64_msvc", | ||
| 3069 | "windows_i686_gnu", | ||
| 3070 | "windows_i686_msvc", | ||
| 3071 | "windows_x86_64_gnu", | ||
| 3072 | "windows_x86_64_gnullvm", | ||
| 3073 | "windows_x86_64_msvc", | ||
| 3074 | ] | ||
| 3075 | |||
| 3076 | [[package]] | ||
| 3077 | name = "windows-sys" | ||
| 3078 | version = "0.42.0" | ||
| 3079 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3080 | checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" | ||
| 3081 | dependencies = [ | ||
| 3082 | "windows_aarch64_gnullvm", | ||
| 3083 | "windows_aarch64_msvc", | ||
| 3084 | "windows_i686_gnu", | ||
| 3085 | "windows_i686_msvc", | ||
| 3086 | "windows_x86_64_gnu", | ||
| 3087 | "windows_x86_64_gnullvm", | ||
| 3088 | "windows_x86_64_msvc", | ||
| 3089 | ] | ||
| 3090 | |||
| 3091 | [[package]] | ||
| 3092 | name = "windows_aarch64_gnullvm" | ||
| 3093 | version = "0.42.0" | ||
| 3094 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3095 | checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" | ||
| 3096 | |||
| 3097 | [[package]] | ||
| 3098 | name = "windows_aarch64_msvc" | ||
| 3099 | version = "0.42.0" | ||
| 3100 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3101 | checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" | ||
| 3102 | |||
| 3103 | [[package]] | ||
| 3104 | name = "windows_i686_gnu" | ||
| 3105 | version = "0.42.0" | ||
| 3106 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3107 | checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" | ||
| 3108 | |||
| 3109 | [[package]] | ||
| 3110 | name = "windows_i686_msvc" | ||
| 3111 | version = "0.42.0" | ||
| 3112 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3113 | checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" | ||
| 3114 | |||
| 3115 | [[package]] | ||
| 3116 | name = "windows_x86_64_gnu" | ||
| 3117 | version = "0.42.0" | ||
| 3118 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3119 | checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" | ||
| 3120 | |||
| 3121 | [[package]] | ||
| 3122 | name = "windows_x86_64_gnullvm" | ||
| 3123 | version = "0.42.0" | ||
| 3124 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3125 | checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" | ||
| 3126 | |||
| 3127 | [[package]] | ||
| 3128 | name = "windows_x86_64_msvc" | ||
| 3129 | version = "0.42.0" | ||
| 3130 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3131 | checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" | ||
| 3132 | |||
| 3133 | [[package]] | ||
| 3134 | name = "winreg" | ||
| 3135 | version = "0.10.1" | ||
| 3136 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3137 | checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" | ||
| 3138 | dependencies = [ | ||
| 3139 | "winapi", | ||
| 3140 | ] | ||
| 3141 | |||
| 3142 | [[package]] | ||
| 3143 | name = "x25519-dalek" | ||
| 3144 | version = "1.2.0" | ||
| 3145 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3146 | checksum = "2392b6b94a576b4e2bf3c5b2757d63f10ada8020a2e4d08ac849ebcf6ea8e077" | ||
| 3147 | dependencies = [ | ||
| 3148 | "curve25519-dalek", | ||
| 3149 | "rand_core 0.5.1", | ||
| 3150 | "serde", | ||
| 3151 | "zeroize", | ||
| 3152 | ] | ||
| 3153 | |||
| 3154 | [[package]] | ||
| 3155 | name = "zeroize" | ||
| 3156 | version = "1.3.0" | ||
| 3157 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3158 | checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd" | ||
| 3159 | dependencies = [ | ||
| 3160 | "zeroize_derive", | ||
| 3161 | ] | ||
| 3162 | |||
| 3163 | [[package]] | ||
| 3164 | name = "zeroize_derive" | ||
| 3165 | version = "1.3.3" | ||
| 3166 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3167 | checksum = "44bf07cb3e50ea2003396695d58bf46bc9887a1f362260446fad6bc4e79bd36c" | ||
| 3168 | dependencies = [ | ||
| 3169 | "proc-macro2", | ||
| 3170 | "quote", | ||
| 3171 | "syn", | ||
| 3172 | "synstructure", | ||
| 3173 | ] | ||
Cargo.toml +27 −2
| @@ -1,13 +1,38 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | name = "iamb" | 2 | name = "iamb" |
| 3 | version = "0.0.1" | 3 | version = "0.0.1" |
| 4 | edition = "2018" | ||
| 4 | authors = ["Ulyssa <git@ulyssa.dev>"] | 5 | authors = ["Ulyssa <git@ulyssa.dev>"] |
| 5 | repository = "https://github.com/ulyssa/iamb" | 6 | repository = "https://github.com/ulyssa/iamb" |
| 6 | homepage = "http://iamb.chat" | 7 | homepage = "http://iamb.chat" |
| 7 | readme = "README.md" | 8 | readme = "README.md" |
| 8 | description = "A Matrix chat client with vim-style editing and keybindings" | 9 | description = "A Matrix chat client that uses Vim keybindings" |
| 9 | license = "Apache-2.0" | 10 | license = "Apache-2.0" |
| 10 | edition = "2018" | ||
| 11 | exclude = [".github", "CONTRIBUTING.md"] | 11 | exclude = [".github", "CONTRIBUTING.md"] |
| 12 | keywords = ["matrix", "chat", "tui", "vim"] | ||
| 13 | rust-version = "1.65" | ||
| 12 | 14 | ||
| 13 | [dependencies] | 15 | [dependencies] |
| 16 | chrono = "0.4" | ||
| 17 | clap = {version = "4.0", features = ["derive"]} | ||
| 18 | dirs = "4.0.0" | ||
| 19 | futures = "0.3.21" | ||
| 20 | gethostname = "0.4.1" | ||
| 21 | matrix-sdk = {version = "0.6", default-features = false, features = ["e2e-encryption", "sled", "rustls-tls"]} | ||
| 22 | modalkit = "0.0.7" | ||
| 23 | regex = "^1.5" | ||
| 24 | rpassword = "^7.2" | ||
| 25 | serde = "^1.0" | ||
| 26 | serde_json = "^1.0" | ||
| 27 | sled = "0.34" | ||
| 28 | thiserror = "^1.0.37" | ||
| 29 | tokio = {version = "1.17.0", features = ["full"]} | ||
| 30 | tracing = "~0.1.36" | ||
| 31 | tracing-appender = "~0.2.2" | ||
| 32 | tracing-subscriber = "0.3.16" | ||
| 33 | unicode-segmentation = "^1.7" | ||
| 34 | unicode-width = "0.1.10" | ||
| 35 | url = {version = "^2.2.2", features = ["serde"]} | ||
| 36 | |||
| 37 | [dev-dependencies] | ||
| 38 | lazy_static = "1.4.0" | ||
README.md +18 −3
| @@ -2,10 +2,10 @@ | |||
| 2 | 2 | ||
| 3 | ## About | 3 | ## About |
| 4 | 4 | ||
| 5 | This is a vi-inspired terminal chat client for the Matrix protocol. | 5 | `iamb` is a Matrix client for the terminal that uses Vim keybindings. |
| 6 | 6 | ||
| 7 | __*Note that this project is still very much in its early stages and a | 7 | This project is a work-in-progress, and there's still a lot to be implemented, |
| 8 | lot is subject to eventually change.*__ | 8 | but much of the basic client functionality is already present. |
| 9 | 9 | ||
| 10 | ## Installation | 10 | ## Installation |
| 11 | 11 | ||
| @@ -15,6 +15,21 @@ Install Rust and Cargo, and then run: | |||
| 15 | cargo install iamb | 15 | cargo install iamb |
| 16 | ``` | 16 | ``` |
| 17 | 17 | ||
| 18 | ## Configuration | ||
| 19 | |||
| 20 | You can create a basic configuration in `$CONFIG_DIR/iamb/config.json` that looks like: | ||
| 21 | |||
| 22 | ```json | ||
| 23 | { | ||
| 24 | "profiles": { | ||
| 25 | "example.com": { | ||
| 26 | "url": "https://example.com", | ||
| 27 | "@user:example.com" | ||
| 28 | } | ||
| 29 | } | ||
| 30 | } | ||
| 31 | ``` | ||
| 32 | |||
| 18 | ## License | 33 | ## License |
| 19 | 34 | ||
| 20 | iamb is released under the [Apache License, Version 2.0]. | 35 | iamb is released under the [Apache License, Version 2.0]. |
src/base.rs added +328
| @@ -0,0 +1,328 @@ | |||
| 1 | use std::collections::{HashMap, HashSet}; | ||
| 2 | use std::hash::Hash; | ||
| 3 | use std::sync::Arc; | ||
| 4 | use std::time::{Duration, Instant}; | ||
| 5 | |||
| 6 | use tokio::sync::Mutex as AsyncMutex; | ||
| 7 | use tracing::warn; | ||
| 8 | |||
| 9 | use matrix_sdk::{ | ||
| 10 | encryption::verification::SasVerification, | ||
| 11 | ruma::{OwnedRoomId, RoomId}, | ||
| 12 | }; | ||
| 13 | |||
| 14 | use modalkit::{ | ||
| 15 | editing::{ | ||
| 16 | action::{Action, UIError, UIResult}, | ||
| 17 | application::{ | ||
| 18 | ApplicationAction, | ||
| 19 | ApplicationContentId, | ||
| 20 | ApplicationError, | ||
| 21 | ApplicationInfo, | ||
| 22 | ApplicationStore, | ||
| 23 | ApplicationWindowId, | ||
| 24 | }, | ||
| 25 | context::EditContext, | ||
| 26 | store::Store, | ||
| 27 | }, | ||
| 28 | env::vim::{ | ||
| 29 | command::{VimCommand, VimCommandMachine}, | ||
| 30 | keybindings::VimMachine, | ||
| 31 | VimContext, | ||
| 32 | }, | ||
| 33 | input::bindings::SequenceStatus, | ||
| 34 | input::key::TerminalKey, | ||
| 35 | }; | ||
| 36 | |||
| 37 | use crate::{ | ||
| 38 | message::{Message, Messages}, | ||
| 39 | worker::Requester, | ||
| 40 | ApplicationSettings, | ||
| 41 | }; | ||
| 42 | |||
| 43 | const ROOM_FETCH_DEBOUNCE: Duration = Duration::from_secs(3); | ||
| 44 | |||
| 45 | #[derive(Clone, Debug, Eq, PartialEq)] | ||
| 46 | pub enum IambInfo {} | ||
| 47 | |||
| 48 | #[derive(Clone, Debug, Eq, PartialEq)] | ||
| 49 | pub enum VerifyAction { | ||
| 50 | Accept, | ||
| 51 | Cancel, | ||
| 52 | Confirm, | ||
| 53 | Mismatch, | ||
| 54 | } | ||
| 55 | |||
| 56 | #[derive(Clone, Debug, Eq, PartialEq)] | ||
| 57 | pub enum IambAction { | ||
| 58 | Verify(VerifyAction, String), | ||
| 59 | VerifyRequest(String), | ||
| 60 | SendMessage(OwnedRoomId, String), | ||
| 61 | ToggleScrollbackFocus, | ||
| 62 | } | ||
| 63 | |||
| 64 | impl ApplicationAction for IambAction { | ||
| 65 | fn is_edit_sequence<C: EditContext>(&self, _: &C) -> SequenceStatus { | ||
| 66 | match self { | ||
| 67 | IambAction::SendMessage(..) => SequenceStatus::Break, | ||
| 68 | IambAction::ToggleScrollbackFocus => SequenceStatus::Break, | ||
| 69 | IambAction::Verify(..) => SequenceStatus::Break, | ||
| 70 | IambAction::VerifyRequest(..) => SequenceStatus::Break, | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | fn is_last_action<C: EditContext>(&self, _: &C) -> SequenceStatus { | ||
| 75 | match self { | ||
| 76 | IambAction::SendMessage(..) => SequenceStatus::Atom, | ||
| 77 | IambAction::ToggleScrollbackFocus => SequenceStatus::Atom, | ||
| 78 | IambAction::Verify(..) => SequenceStatus::Atom, | ||
| 79 | IambAction::VerifyRequest(..) => SequenceStatus::Atom, | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | fn is_last_selection<C: EditContext>(&self, _: &C) -> SequenceStatus { | ||
| 84 | match self { | ||
| 85 | IambAction::SendMessage(..) => SequenceStatus::Ignore, | ||
| 86 | IambAction::ToggleScrollbackFocus => SequenceStatus::Ignore, | ||
| 87 | IambAction::Verify(..) => SequenceStatus::Ignore, | ||
| 88 | IambAction::VerifyRequest(..) => SequenceStatus::Ignore, | ||
| 89 | } | ||
| 90 | } | ||
| 91 | |||
| 92 | fn is_switchable<C: EditContext>(&self, _: &C) -> bool { | ||
| 93 | match self { | ||
| 94 | IambAction::SendMessage(..) => false, | ||
| 95 | IambAction::ToggleScrollbackFocus => false, | ||
| 96 | IambAction::Verify(..) => false, | ||
| 97 | IambAction::VerifyRequest(..) => false, | ||
| 98 | } | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | impl From<IambAction> for ProgramAction { | ||
| 103 | fn from(act: IambAction) -> Self { | ||
| 104 | Action::Application(act) | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | pub type ProgramAction = Action<IambInfo>; | ||
| 109 | pub type ProgramContext = VimContext<IambInfo>; | ||
| 110 | pub type Keybindings = VimMachine<TerminalKey, IambInfo>; | ||
| 111 | pub type ProgramCommand = VimCommand<ProgramContext, IambInfo>; | ||
| 112 | pub type ProgramCommands = VimCommandMachine<ProgramContext, IambInfo>; | ||
| 113 | pub type ProgramStore = Store<IambInfo>; | ||
| 114 | pub type AsyncProgramStore = Arc<AsyncMutex<ProgramStore>>; | ||
| 115 | |||
| 116 | pub type IambResult<T> = UIResult<T, IambInfo>; | ||
| 117 | |||
| 118 | #[derive(thiserror::Error, Debug)] | ||
| 119 | pub enum IambError { | ||
| 120 | #[error("Unknown room identifier: {0}")] | ||
| 121 | InvalidUserId(String), | ||
| 122 | |||
| 123 | #[error("Invalid verification user/device pair: {0}")] | ||
| 124 | InvalidVerificationId(String), | ||
| 125 | |||
| 126 | #[error("Cryptographic storage error: {0}")] | ||
| 127 | CryptoStore(#[from] matrix_sdk::encryption::CryptoStoreError), | ||
| 128 | |||
| 129 | #[error("HTTP client error: {0}")] | ||
| 130 | Http(#[from] matrix_sdk::HttpError), | ||
| 131 | |||
| 132 | #[error("Matrix client error: {0}")] | ||
| 133 | Matrix(#[from] matrix_sdk::Error), | ||
| 134 | |||
| 135 | #[error("Matrix client storage error: {0}")] | ||
| 136 | Store(#[from] matrix_sdk::StoreError), | ||
| 137 | |||
| 138 | #[error("Serialization/deserialization error: {0}")] | ||
| 139 | Serde(#[from] serde_json::Error), | ||
| 140 | |||
| 141 | #[error("Unknown room identifier: {0}")] | ||
| 142 | UnknownRoom(OwnedRoomId), | ||
| 143 | |||
| 144 | #[error("Verification request error: {0}")] | ||
| 145 | VerificationRequestError(#[from] matrix_sdk::encryption::identities::RequestVerificationError), | ||
| 146 | } | ||
| 147 | |||
| 148 | impl From<IambError> for UIError<IambInfo> { | ||
| 149 | fn from(err: IambError) -> Self { | ||
| 150 | UIError::Application(err) | ||
| 151 | } | ||
| 152 | } | ||
| 153 | |||
| 154 | impl ApplicationError for IambError {} | ||
| 155 | |||
| 156 | #[derive(Default)] | ||
| 157 | pub enum RoomFetchStatus { | ||
| 158 | Done, | ||
| 159 | HaveMore(String), | ||
| 160 | #[default] | ||
| 161 | NotStarted, | ||
| 162 | } | ||
| 163 | |||
| 164 | #[derive(Default)] | ||
| 165 | pub struct RoomInfo { | ||
| 166 | pub name: Option<String>, | ||
| 167 | pub messages: Messages, | ||
| 168 | pub fetch_id: RoomFetchStatus, | ||
| 169 | pub fetch_last: Option<Instant>, | ||
| 170 | } | ||
| 171 | |||
| 172 | impl RoomInfo { | ||
| 173 | fn recently_fetched(&self) -> bool { | ||
| 174 | self.fetch_last.map_or(false, |i| i.elapsed() < ROOM_FETCH_DEBOUNCE) | ||
| 175 | } | ||
| 176 | } | ||
| 177 | |||
| 178 | pub struct ChatStore { | ||
| 179 | pub worker: Requester, | ||
| 180 | pub rooms: HashMap<OwnedRoomId, RoomInfo>, | ||
| 181 | pub names: HashMap<String, OwnedRoomId>, | ||
| 182 | pub verifications: HashMap<String, SasVerification>, | ||
| 183 | pub settings: ApplicationSettings, | ||
| 184 | pub need_load: HashSet<OwnedRoomId>, | ||
| 185 | } | ||
| 186 | |||
| 187 | impl ChatStore { | ||
| 188 | pub fn new(worker: Requester, settings: ApplicationSettings) -> Self { | ||
| 189 | ChatStore { | ||
| 190 | worker, | ||
| 191 | settings, | ||
| 192 | |||
| 193 | names: Default::default(), | ||
| 194 | rooms: Default::default(), | ||
| 195 | verifications: Default::default(), | ||
| 196 | need_load: Default::default(), | ||
| 197 | } | ||
| 198 | } | ||
| 199 | |||
| 200 | pub fn mark_for_load(&mut self, room_id: OwnedRoomId) { | ||
| 201 | self.need_load.insert(room_id); | ||
| 202 | } | ||
| 203 | |||
| 204 | pub fn load_older(&mut self, limit: u32) { | ||
| 205 | let ChatStore { need_load, rooms, worker, .. } = self; | ||
| 206 | |||
| 207 | for room_id in std::mem::take(need_load).into_iter() { | ||
| 208 | let info = rooms.entry(room_id.clone()).or_default(); | ||
| 209 | |||
| 210 | if info.recently_fetched() { | ||
| 211 | need_load.insert(room_id); | ||
| 212 | continue; | ||
| 213 | } else { | ||
| 214 | info.fetch_last = Instant::now().into(); | ||
| 215 | } | ||
| 216 | |||
| 217 | let fetch_id = match &info.fetch_id { | ||
| 218 | RoomFetchStatus::Done => continue, | ||
| 219 | RoomFetchStatus::HaveMore(fetch_id) => Some(fetch_id.clone()), | ||
| 220 | RoomFetchStatus::NotStarted => None, | ||
| 221 | }; | ||
| 222 | |||
| 223 | let res = worker.load_older(room_id.clone(), fetch_id, limit); | ||
| 224 | |||
| 225 | match res { | ||
| 226 | Ok((fetch_id, msgs)) => { | ||
| 227 | for msg in msgs.into_iter() { | ||
| 228 | let key = (msg.origin_server_ts().into(), msg.event_id().to_owned()); | ||
| 229 | |||
| 230 | info.messages.insert(key, Message::from(msg)); | ||
| 231 | } | ||
| 232 | |||
| 233 | info.fetch_id = | ||
| 234 | fetch_id.map_or(RoomFetchStatus::Done, RoomFetchStatus::HaveMore); | ||
| 235 | }, | ||
| 236 | Err(e) => { | ||
| 237 | warn!( | ||
| 238 | room_id = room_id.as_str(), | ||
| 239 | err = e.to_string(), | ||
| 240 | "Failed to load older messages" | ||
| 241 | ); | ||
| 242 | |||
| 243 | // Wait and try again. | ||
| 244 | need_load.insert(room_id); | ||
| 245 | }, | ||
| 246 | } | ||
| 247 | } | ||
| 248 | } | ||
| 249 | |||
| 250 | pub fn get_room_info(&mut self, room_id: OwnedRoomId) -> &mut RoomInfo { | ||
| 251 | self.rooms.entry(room_id).or_default() | ||
| 252 | } | ||
| 253 | |||
| 254 | pub fn set_room_name(&mut self, room_id: &RoomId, name: &str) { | ||
| 255 | self.rooms.entry(room_id.to_owned()).or_default().name = name.to_string().into(); | ||
| 256 | } | ||
| 257 | |||
| 258 | pub fn insert_sas(&mut self, sas: SasVerification) { | ||
| 259 | let key = format!("{}/{}", sas.other_user_id(), sas.other_device().device_id()); | ||
| 260 | |||
| 261 | self.verifications.insert(key, sas); | ||
| 262 | } | ||
| 263 | } | ||
| 264 | |||
| 265 | impl ApplicationStore for ChatStore {} | ||
| 266 | |||
| 267 | #[derive(Clone, Debug, Eq, Hash, PartialEq)] | ||
| 268 | pub enum IambId { | ||
| 269 | Room(OwnedRoomId), | ||
| 270 | DirectList, | ||
| 271 | RoomList, | ||
| 272 | SpaceList, | ||
| 273 | VerifyList, | ||
| 274 | Welcome, | ||
| 275 | } | ||
| 276 | |||
| 277 | impl ApplicationWindowId for IambId {} | ||
| 278 | |||
| 279 | #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] | ||
| 280 | pub enum RoomFocus { | ||
| 281 | Scrollback, | ||
| 282 | MessageBar, | ||
| 283 | } | ||
| 284 | |||
| 285 | impl RoomFocus { | ||
| 286 | pub fn is_scrollback(&self) -> bool { | ||
| 287 | matches!(self, RoomFocus::Scrollback) | ||
| 288 | } | ||
| 289 | |||
| 290 | pub fn is_msgbar(&self) -> bool { | ||
| 291 | matches!(self, RoomFocus::MessageBar) | ||
| 292 | } | ||
| 293 | } | ||
| 294 | |||
| 295 | #[derive(Clone, Debug, Eq, Hash, PartialEq)] | ||
| 296 | pub enum IambBufferId { | ||
| 297 | Command, | ||
| 298 | Room(OwnedRoomId, RoomFocus), | ||
| 299 | DirectList, | ||
| 300 | RoomList, | ||
| 301 | SpaceList, | ||
| 302 | VerifyList, | ||
| 303 | Welcome, | ||
| 304 | } | ||
| 305 | |||
| 306 | impl IambBufferId { | ||
| 307 | pub fn to_window(&self) -> Option<IambId> { | ||
| 308 | match self { | ||
| 309 | IambBufferId::Command => None, | ||
| 310 | IambBufferId::Room(room, _) => Some(IambId::Room(room.clone())), | ||
| 311 | IambBufferId::DirectList => Some(IambId::DirectList), | ||
| 312 | IambBufferId::RoomList => Some(IambId::RoomList), | ||
| 313 | IambBufferId::SpaceList => Some(IambId::SpaceList), | ||
| 314 | IambBufferId::VerifyList => Some(IambId::VerifyList), | ||
| 315 | IambBufferId::Welcome => Some(IambId::Welcome), | ||
| 316 | } | ||
| 317 | } | ||
| 318 | } | ||
| 319 | |||
| 320 | impl ApplicationContentId for IambBufferId {} | ||
| 321 | |||
| 322 | impl ApplicationInfo for IambInfo { | ||
| 323 | type Error = IambError; | ||
| 324 | type Store = ChatStore; | ||
| 325 | type Action = IambAction; | ||
| 326 | type WindowId = IambId; | ||
| 327 | type ContentId = IambBufferId; | ||
| 328 | } | ||
src/commands.rs added +202
| @@ -0,0 +1,202 @@ | |||
| 1 | use modalkit::{ | ||
| 2 | editing::{action::WindowAction, base::OpenTarget}, | ||
| 3 | env::vim::command::{CommandContext, CommandDescription}, | ||
| 4 | input::commands::{CommandError, CommandResult, CommandStep}, | ||
| 5 | input::InputContext, | ||
| 6 | }; | ||
| 7 | |||
| 8 | use crate::base::{ | ||
| 9 | IambAction, | ||
| 10 | IambId, | ||
| 11 | ProgramCommand, | ||
| 12 | ProgramCommands, | ||
| 13 | ProgramContext, | ||
| 14 | VerifyAction, | ||
| 15 | }; | ||
| 16 | |||
| 17 | type ProgContext = CommandContext<ProgramContext>; | ||
| 18 | type ProgResult = CommandResult<ProgramCommand>; | ||
| 19 | |||
| 20 | fn iamb_verify(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | ||
| 21 | let mut args = desc.arg.strings()?; | ||
| 22 | |||
| 23 | match args.len() { | ||
| 24 | 0 => { | ||
| 25 | let open = WindowAction::Switch(OpenTarget::Application(IambId::VerifyList)); | ||
| 26 | let step = CommandStep::Continue(open.into(), ctx.context.take()); | ||
| 27 | |||
| 28 | return Ok(step); | ||
| 29 | }, | ||
| 30 | 1 => { | ||
| 31 | return Result::Err(CommandError::InvalidArgument); | ||
| 32 | }, | ||
| 33 | 2 => { | ||
| 34 | let act = match args[0].as_str() { | ||
| 35 | "accept" => VerifyAction::Accept, | ||
| 36 | "cancel" => VerifyAction::Cancel, | ||
| 37 | "confirm" => VerifyAction::Confirm, | ||
| 38 | "mismatch" => VerifyAction::Mismatch, | ||
| 39 | "request" => { | ||
| 40 | let iact = IambAction::VerifyRequest(args.remove(1)); | ||
| 41 | let step = CommandStep::Continue(iact.into(), ctx.context.take()); | ||
| 42 | |||
| 43 | return Ok(step); | ||
| 44 | }, | ||
| 45 | _ => return Result::Err(CommandError::InvalidArgument), | ||
| 46 | }; | ||
| 47 | |||
| 48 | let vact = IambAction::Verify(act, args.remove(1)); | ||
| 49 | let step = CommandStep::Continue(vact.into(), ctx.context.take()); | ||
| 50 | |||
| 51 | return Ok(step); | ||
| 52 | }, | ||
| 53 | _ => { | ||
| 54 | return Result::Err(CommandError::InvalidArgument); | ||
| 55 | }, | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | fn iamb_dms(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | ||
| 60 | if !desc.arg.text.is_empty() { | ||
| 61 | return Result::Err(CommandError::InvalidArgument); | ||
| 62 | } | ||
| 63 | |||
| 64 | let open = WindowAction::Switch(OpenTarget::Application(IambId::DirectList)); | ||
| 65 | let step = CommandStep::Continue(open.into(), ctx.context.take()); | ||
| 66 | |||
| 67 | return Ok(step); | ||
| 68 | } | ||
| 69 | |||
| 70 | fn iamb_rooms(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | ||
| 71 | if !desc.arg.text.is_empty() { | ||
| 72 | return Result::Err(CommandError::InvalidArgument); | ||
| 73 | } | ||
| 74 | |||
| 75 | let open = WindowAction::Switch(OpenTarget::Application(IambId::RoomList)); | ||
| 76 | let step = CommandStep::Continue(open.into(), ctx.context.take()); | ||
| 77 | |||
| 78 | return Ok(step); | ||
| 79 | } | ||
| 80 | |||
| 81 | fn iamb_spaces(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | ||
| 82 | if !desc.arg.text.is_empty() { | ||
| 83 | return Result::Err(CommandError::InvalidArgument); | ||
| 84 | } | ||
| 85 | |||
| 86 | let open = WindowAction::Switch(OpenTarget::Application(IambId::SpaceList)); | ||
| 87 | let step = CommandStep::Continue(open.into(), ctx.context.take()); | ||
| 88 | |||
| 89 | return Ok(step); | ||
| 90 | } | ||
| 91 | |||
| 92 | fn iamb_welcome(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | ||
| 93 | if !desc.arg.text.is_empty() { | ||
| 94 | return Result::Err(CommandError::InvalidArgument); | ||
| 95 | } | ||
| 96 | |||
| 97 | let open = WindowAction::Switch(OpenTarget::Application(IambId::Welcome)); | ||
| 98 | let step = CommandStep::Continue(open.into(), ctx.context.take()); | ||
| 99 | |||
| 100 | return Ok(step); | ||
| 101 | } | ||
| 102 | |||
| 103 | fn iamb_join(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | ||
| 104 | let mut args = desc.arg.filenames()?; | ||
| 105 | |||
| 106 | if args.len() != 1 { | ||
| 107 | return Result::Err(CommandError::InvalidArgument); | ||
| 108 | } | ||
| 109 | |||
| 110 | let open = WindowAction::Switch(args.remove(0)); | ||
| 111 | let step = CommandStep::Continue(open.into(), ctx.context.take()); | ||
| 112 | |||
| 113 | return Ok(step); | ||
| 114 | } | ||
| 115 | |||
| 116 | fn add_iamb_commands(cmds: &mut ProgramCommands) { | ||
| 117 | cmds.add_command(ProgramCommand { names: vec!["dms".into()], f: iamb_dms }); | ||
| 118 | cmds.add_command(ProgramCommand { names: vec!["join".into()], f: iamb_join }); | ||
| 119 | cmds.add_command(ProgramCommand { names: vec!["rooms".into()], f: iamb_rooms }); | ||
| 120 | cmds.add_command(ProgramCommand { names: vec!["spaces".into()], f: iamb_spaces }); | ||
| 121 | cmds.add_command(ProgramCommand { names: vec!["verify".into()], f: iamb_verify }); | ||
| 122 | cmds.add_command(ProgramCommand { names: vec!["welcome".into()], f: iamb_welcome }); | ||
| 123 | } | ||
| 124 | |||
| 125 | pub fn setup_commands() -> ProgramCommands { | ||
| 126 | let mut cmds = ProgramCommands::default(); | ||
| 127 | |||
| 128 | add_iamb_commands(&mut cmds); | ||
| 129 | |||
| 130 | return cmds; | ||
| 131 | } | ||
| 132 | |||
| 133 | #[cfg(test)] | ||
| 134 | mod tests { | ||
| 135 | use super::*; | ||
| 136 | #[test] | ||
| 137 | fn test_cmd_verify() { | ||
| 138 | let mut cmds = setup_commands(); | ||
| 139 | let ctx = ProgramContext::default(); | ||
| 140 | |||
| 141 | let res = cmds.input_cmd(":verify", ctx.clone()).unwrap(); | ||
| 142 | let act = WindowAction::Switch(OpenTarget::Application(IambId::VerifyList)); | ||
| 143 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | ||
| 144 | |||
| 145 | let res = cmds.input_cmd(":verify request @user1:example.com", ctx.clone()).unwrap(); | ||
| 146 | let act = IambAction::VerifyRequest("@user1:example.com".into()); | ||
| 147 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | ||
| 148 | |||
| 149 | let res = cmds | ||
| 150 | .input_cmd(":verify accept @user1:example.com/FOOBAR", ctx.clone()) | ||
| 151 | .unwrap(); | ||
| 152 | let act = IambAction::Verify(VerifyAction::Accept, "@user1:example.com/FOOBAR".into()); | ||
| 153 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | ||
| 154 | |||
| 155 | let res = cmds | ||
| 156 | .input_cmd(":verify mismatch @user2:example.com/QUUXBAZ", ctx.clone()) | ||
| 157 | .unwrap(); | ||
| 158 | let act = IambAction::Verify(VerifyAction::Mismatch, "@user2:example.com/QUUXBAZ".into()); | ||
| 159 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | ||
| 160 | |||
| 161 | let res = cmds | ||
| 162 | .input_cmd(":verify cancel @user3:example.com/MYDEVICE", ctx.clone()) | ||
| 163 | .unwrap(); | ||
| 164 | let act = IambAction::Verify(VerifyAction::Cancel, "@user3:example.com/MYDEVICE".into()); | ||
| 165 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | ||
| 166 | |||
| 167 | let res = cmds | ||
| 168 | .input_cmd(":verify confirm @user4:example.com/GOODDEV", ctx.clone()) | ||
| 169 | .unwrap(); | ||
| 170 | let act = IambAction::Verify(VerifyAction::Confirm, "@user4:example.com/GOODDEV".into()); | ||
| 171 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | ||
| 172 | |||
| 173 | let res = cmds.input_cmd(":verify confirm", ctx.clone()); | ||
| 174 | assert_eq!(res, Err(CommandError::InvalidArgument)); | ||
| 175 | |||
| 176 | let res = cmds.input_cmd(":verify cancel @user4:example.com MYDEVICE", ctx.clone()); | ||
| 177 | assert_eq!(res, Err(CommandError::InvalidArgument)); | ||
| 178 | |||
| 179 | let res = cmds.input_cmd(":verify mismatch a b c d e f", ctx.clone()); | ||
| 180 | assert_eq!(res, Err(CommandError::InvalidArgument)); | ||
| 181 | } | ||
| 182 | |||
| 183 | #[test] | ||
| 184 | fn test_cmd_join() { | ||
| 185 | let mut cmds = setup_commands(); | ||
| 186 | let ctx = ProgramContext::default(); | ||
| 187 | |||
| 188 | let res = cmds.input_cmd("join #foobar:example.com", ctx.clone()).unwrap(); | ||
| 189 | let act = WindowAction::Switch(OpenTarget::Name("#foobar:example.com".into())); | ||
| 190 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | ||
| 191 | |||
| 192 | let res = cmds.input_cmd("join #", ctx.clone()).unwrap(); | ||
| 193 | let act = WindowAction::Switch(OpenTarget::Alternate); | ||
| 194 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | ||
| 195 | |||
| 196 | let res = cmds.input_cmd("join", ctx.clone()); | ||
| 197 | assert_eq!(res, Err(CommandError::InvalidArgument)); | ||
| 198 | |||
| 199 | let res = cmds.input_cmd("join foo bar", ctx.clone()); | ||
| 200 | assert_eq!(res, Err(CommandError::InvalidArgument)); | ||
| 201 | } | ||
| 202 | } | ||
src/config.rs added +203
| @@ -0,0 +1,203 @@ | |||
| 1 | use std::collections::HashMap; | ||
| 2 | use std::fs::File; | ||
| 3 | use std::io::BufReader; | ||
| 4 | use std::path::{Path, PathBuf}; | ||
| 5 | use std::process; | ||
| 6 | |||
| 7 | use clap::Parser; | ||
| 8 | use matrix_sdk::ruma::OwnedUserId; | ||
| 9 | use serde::Deserialize; | ||
| 10 | use url::Url; | ||
| 11 | |||
| 12 | macro_rules! usage { | ||
| 13 | ( $($args: tt)* ) => { | ||
| 14 | println!($($args)*); | ||
| 15 | process::exit(2); | ||
| 16 | } | ||
| 17 | } | ||
| 18 | |||
| 19 | fn is_profile_char(c: char) -> bool { | ||
| 20 | c.is_ascii_alphanumeric() || c == '.' || c == '-' | ||
| 21 | } | ||
| 22 | |||
| 23 | fn validate_profile_name(name: &str) -> bool { | ||
| 24 | if name.is_empty() { | ||
| 25 | return false; | ||
| 26 | } | ||
| 27 | |||
| 28 | let mut chars = name.chars(); | ||
| 29 | |||
| 30 | if !chars.next().map_or(false, |c| c.is_ascii_alphanumeric()) { | ||
| 31 | return false; | ||
| 32 | } | ||
| 33 | |||
| 34 | name.chars().all(is_profile_char) | ||
| 35 | } | ||
| 36 | |||
| 37 | fn validate_profile_names(names: &HashMap<String, ProfileConfig>) { | ||
| 38 | for name in names.keys() { | ||
| 39 | if validate_profile_name(name.as_str()) { | ||
| 40 | continue; | ||
| 41 | } | ||
| 42 | |||
| 43 | usage!( | ||
| 44 | "{:?} is not a valid profile name.\n\n\ | ||
| 45 | Profile names can only contain the characters \ | ||
| 46 | a-z, A-Z, and 0-9. Period (.) and hyphen (-) are allowed after the first character.", | ||
| 47 | name | ||
| 48 | ); | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | #[derive(Parser)] | ||
| 53 | #[clap(version, about, long_about = None)] | ||
| 54 | #[clap(propagate_version = true)] | ||
| 55 | pub struct Iamb { | ||
| 56 | #[clap(short = 'P', long, value_parser)] | ||
| 57 | pub profile: Option<String>, | ||
| 58 | |||
| 59 | #[clap(short = 'C', long, value_parser)] | ||
| 60 | pub config_directory: Option<PathBuf>, | ||
| 61 | } | ||
| 62 | |||
| 63 | #[derive(thiserror::Error, Debug)] | ||
| 64 | pub enum ConfigError { | ||
| 65 | #[error("Error reading configuration file: {0}")] | ||
| 66 | IO(#[from] std::io::Error), | ||
| 67 | |||
| 68 | #[error("Error loading configuration file: {0}")] | ||
| 69 | Invalid(#[from] serde_json::Error), | ||
| 70 | } | ||
| 71 | |||
| 72 | #[derive(Clone, Deserialize)] | ||
| 73 | pub struct ProfileConfig { | ||
| 74 | pub user_id: OwnedUserId, | ||
| 75 | pub url: Url, | ||
| 76 | } | ||
| 77 | |||
| 78 | #[derive(Clone, Deserialize)] | ||
| 79 | pub struct IambConfig { | ||
| 80 | pub profiles: HashMap<String, ProfileConfig>, | ||
| 81 | pub default_profile: Option<String>, | ||
| 82 | pub cache: Option<PathBuf>, | ||
| 83 | } | ||
| 84 | |||
| 85 | impl IambConfig { | ||
| 86 | pub fn load(config_json: &Path) -> Result<Self, ConfigError> { | ||
| 87 | if !config_json.is_file() { | ||
| 88 | usage!( | ||
| 89 | "Please create a configuration file at {}\n\n\ | ||
| 90 | For more information try '--help'", | ||
| 91 | config_json.display(), | ||
| 92 | ); | ||
| 93 | } | ||
| 94 | |||
| 95 | let file = File::open(config_json)?; | ||
| 96 | let reader = BufReader::new(file); | ||
| 97 | let config = serde_json::from_reader(reader)?; | ||
| 98 | |||
| 99 | Ok(config) | ||
| 100 | } | ||
| 101 | } | ||
| 102 | |||
| 103 | #[derive(Clone)] | ||
| 104 | pub struct ApplicationSettings { | ||
| 105 | pub matrix_dir: PathBuf, | ||
| 106 | pub cache_dir: PathBuf, | ||
| 107 | pub session_json: PathBuf, | ||
| 108 | pub profile_name: String, | ||
| 109 | pub profile: ProfileConfig, | ||
| 110 | } | ||
| 111 | |||
| 112 | impl ApplicationSettings { | ||
| 113 | pub fn load(cli: Iamb) -> Result<Self, Box<dyn std::error::Error>> { | ||
| 114 | let mut config_dir = cli.config_directory.or_else(dirs::config_dir).unwrap_or_else(|| { | ||
| 115 | usage!( | ||
| 116 | "No user configuration directory found;\ | ||
| 117 | please specify one via -C.\n\n | ||
| 118 | For more information try '--help'" | ||
| 119 | ); | ||
| 120 | }); | ||
| 121 | config_dir.push("iamb"); | ||
| 122 | let mut config_json = config_dir.clone(); | ||
| 123 | config_json.push("config.json"); | ||
| 124 | |||
| 125 | let IambConfig { mut profiles, default_profile, cache } = | ||
| 126 | IambConfig::load(config_json.as_path())?; | ||
| 127 | |||
| 128 | validate_profile_names(&profiles); | ||
| 129 | |||
| 130 | let (profile_name, profile) = if let Some(profile) = cli.profile.or(default_profile) { | ||
| 131 | profiles.remove_entry(&profile).unwrap_or_else(|| { | ||
| 132 | usage!( | ||
| 133 | "No configured profile with the name {:?} in {}", | ||
| 134 | profile, | ||
| 135 | config_json.display() | ||
| 136 | ); | ||
| 137 | }) | ||
| 138 | } else if profiles.len() == 1 { | ||
| 139 | profiles.into_iter().next().unwrap() | ||
| 140 | } else { | ||
| 141 | usage!( | ||
| 142 | "No profile specified. \ | ||
| 143 | Please use -P or add \"default_profile\" to {}.\n\n\ | ||
| 144 | For more information try '--help'", | ||
| 145 | config_json.display() | ||
| 146 | ); | ||
| 147 | }; | ||
| 148 | |||
| 149 | let mut profile_dir = config_dir.clone(); | ||
| 150 | profile_dir.push("profiles"); | ||
| 151 | profile_dir.push(profile_name.as_str()); | ||
| 152 | |||
| 153 | let mut matrix_dir = profile_dir.clone(); | ||
| 154 | matrix_dir.push("matrix"); | ||
| 155 | |||
| 156 | let mut session_json = profile_dir; | ||
| 157 | session_json.push("session.json"); | ||
| 158 | |||
| 159 | let cache_dir = cache.unwrap_or_else(|| { | ||
| 160 | let mut cache = dirs::cache_dir().expect("no user cache directory"); | ||
| 161 | cache.push("iamb"); | ||
| 162 | cache | ||
| 163 | }); | ||
| 164 | |||
| 165 | let settings = ApplicationSettings { | ||
| 166 | matrix_dir, | ||
| 167 | cache_dir, | ||
| 168 | session_json, | ||
| 169 | profile_name, | ||
| 170 | profile, | ||
| 171 | }; | ||
| 172 | |||
| 173 | Ok(settings) | ||
| 174 | } | ||
| 175 | } | ||
| 176 | |||
| 177 | #[cfg(test)] | ||
| 178 | mod tests { | ||
| 179 | use super::*; | ||
| 180 | |||
| 181 | #[test] | ||
| 182 | fn test_profile_name_invalid() { | ||
| 183 | assert_eq!(validate_profile_name(""), false); | ||
| 184 | assert_eq!(validate_profile_name(" "), false); | ||
| 185 | assert_eq!(validate_profile_name("a b"), false); | ||
| 186 | assert_eq!(validate_profile_name("foo^bar"), false); | ||
| 187 | assert_eq!(validate_profile_name("FOO/BAR"), false); | ||
| 188 | assert_eq!(validate_profile_name("-b-c"), false); | ||
| 189 | assert_eq!(validate_profile_name("-B-c"), false); | ||
| 190 | assert_eq!(validate_profile_name(".b-c"), false); | ||
| 191 | assert_eq!(validate_profile_name(".B-c"), false); | ||
| 192 | } | ||
| 193 | |||
| 194 | #[test] | ||
| 195 | fn test_profile_name_valid() { | ||
| 196 | assert_eq!(validate_profile_name("foo"), true); | ||
| 197 | assert_eq!(validate_profile_name("FOO"), true); | ||
| 198 | assert_eq!(validate_profile_name("a-b-c"), true); | ||
| 199 | assert_eq!(validate_profile_name("a-B-c"), true); | ||
| 200 | assert_eq!(validate_profile_name("a.b-c"), true); | ||
| 201 | assert_eq!(validate_profile_name("a.B-c"), true); | ||
| 202 | } | ||
| 203 | } | ||
src/keybindings.rs added +62
| @@ -0,0 +1,62 @@ | |||
| 1 | use modalkit::{ | ||
| 2 | editing::action::WindowAction, | ||
| 3 | editing::base::WordStyle, | ||
| 4 | env::vim::keybindings::{InputStep, VimBindings}, | ||
| 5 | env::vim::VimMode, | ||
| 6 | input::bindings::{EdgeEvent, EdgeRepeat, InputBindings}, | ||
| 7 | input::key::TerminalKey, | ||
| 8 | }; | ||
| 9 | |||
| 10 | use crate::base::{IambAction, Keybindings}; | ||
| 11 | |||
| 12 | /// Find the boundaries for a Matrix username, room alias, or room ID. | ||
| 13 | /// | ||
| 14 | /// Technically "[" and "]" should be here since IPv6 addresses are allowed | ||
| 15 | /// in the server name, but in practice that should be uncommon, and people | ||
| 16 | /// can just use `gf` and friends in Visual mode instead. | ||
| 17 | fn is_mxid_char(c: char) -> bool { | ||
| 18 | return c >= 'a' && c <= 'z' || | ||
| 19 | c >= 'A' && c <= 'Z' || | ||
| 20 | c >= '0' && c <= '9' || | ||
| 21 | ":-./@_#!".contains(c); | ||
| 22 | } | ||
| 23 | |||
| 24 | pub fn setup_keybindings() -> Keybindings { | ||
| 25 | let mut ism = Keybindings::empty(); | ||
| 26 | |||
| 27 | let vim = VimBindings::default() | ||
| 28 | .submit_on_enter() | ||
| 29 | .cursor_open(WordStyle::CharSet(is_mxid_char)); | ||
| 30 | |||
| 31 | vim.setup(&mut ism); | ||
| 32 | |||
| 33 | let ctrl_w = EdgeEvent::Key("<C-W>".parse::<TerminalKey>().unwrap()); | ||
| 34 | let ctrl_m = EdgeEvent::Key("<C-M>".parse::<TerminalKey>().unwrap()); | ||
| 35 | let ctrl_z = EdgeEvent::Key("<C-Z>".parse::<TerminalKey>().unwrap()); | ||
| 36 | let key_m_lc = EdgeEvent::Key("m".parse::<TerminalKey>().unwrap()); | ||
| 37 | let key_z_lc = EdgeEvent::Key("z".parse::<TerminalKey>().unwrap()); | ||
| 38 | |||
| 39 | let cwz = vec![ | ||
| 40 | (EdgeRepeat::Once, ctrl_w.clone()), | ||
| 41 | (EdgeRepeat::Once, key_z_lc), | ||
| 42 | ]; | ||
| 43 | let cwcz = vec![ | ||
| 44 | (EdgeRepeat::Once, ctrl_w.clone()), | ||
| 45 | (EdgeRepeat::Once, ctrl_z), | ||
| 46 | ]; | ||
| 47 | let zoom = InputStep::new().actions(vec![WindowAction::ZoomToggle.into()]); | ||
| 48 | |||
| 49 | ism.add_mapping(VimMode::Normal, &cwz, &zoom); | ||
| 50 | ism.add_mapping(VimMode::Normal, &cwcz, &zoom); | ||
| 51 | |||
| 52 | let cwm = vec![ | ||
| 53 | (EdgeRepeat::Once, ctrl_w.clone()), | ||
| 54 | (EdgeRepeat::Once, key_m_lc), | ||
| 55 | ]; | ||
| 56 | let cwcm = vec![(EdgeRepeat::Once, ctrl_w), (EdgeRepeat::Once, ctrl_m)]; | ||
| 57 | let stoggle = InputStep::new().actions(vec![IambAction::ToggleScrollbackFocus.into()]); | ||
| 58 | ism.add_mapping(VimMode::Normal, &cwm, &stoggle); | ||
| 59 | ism.add_mapping(VimMode::Normal, &cwcm, &stoggle); | ||
| 60 | |||
| 61 | return ism; | ||
| 62 | } | ||
src/main.rs +492 −2
| @@ -1,3 +1,493 @@ | |||
| 1 | fn main() { | 1 | #![allow(clippy::manual_range_contains)] |
| 2 | unimplemented!(); | 2 | #![allow(clippy::needless_return)] |
| 3 | #![allow(clippy::result_large_err)] | ||
| 4 | #![allow(clippy::bool_assert_comparison)] | ||
| 5 | use std::collections::VecDeque; | ||
| 6 | use std::convert::TryFrom; | ||
| 7 | use std::fmt::Display; | ||
| 8 | use std::fs::{create_dir_all, File}; | ||
| 9 | use std::io::{stdout, BufReader, Stdout}; | ||
| 10 | use std::ops::DerefMut; | ||
| 11 | use std::process; | ||
| 12 | use std::sync::Arc; | ||
| 13 | use std::time::Duration; | ||
| 14 | |||
| 15 | use clap::Parser; | ||
| 16 | use tokio::sync::Mutex as AsyncMutex; | ||
| 17 | use tracing::{self, Level}; | ||
| 18 | use tracing_subscriber::FmtSubscriber; | ||
| 19 | |||
| 20 | use matrix_sdk::ruma::OwnedUserId; | ||
| 21 | |||
| 22 | use modalkit::crossterm::{ | ||
| 23 | self, | ||
| 24 | cursor::Show as CursorShow, | ||
| 25 | event::{poll, read, Event}, | ||
| 26 | execute, | ||
| 27 | terminal::{EnterAlternateScreen, LeaveAlternateScreen, SetTitle}, | ||
| 28 | }; | ||
| 29 | |||
| 30 | use modalkit::tui::{ | ||
| 31 | backend::CrosstermBackend, | ||
| 32 | layout::Rect, | ||
| 33 | style::{Color, Style}, | ||
| 34 | text::Span, | ||
| 35 | widgets::Paragraph, | ||
| 36 | Terminal, | ||
| 37 | }; | ||
| 38 | |||
| 39 | mod base; | ||
| 40 | mod commands; | ||
| 41 | mod config; | ||
| 42 | mod keybindings; | ||
| 43 | mod message; | ||
| 44 | mod windows; | ||
| 45 | mod worker; | ||
| 46 | |||
| 47 | #[cfg(test)] | ||
| 48 | mod tests; | ||
| 49 | |||
| 50 | use crate::{ | ||
| 51 | base::{ | ||
| 52 | AsyncProgramStore, | ||
| 53 | ChatStore, | ||
| 54 | IambAction, | ||
| 55 | IambBufferId, | ||
| 56 | IambError, | ||
| 57 | IambId, | ||
| 58 | IambInfo, | ||
| 59 | IambResult, | ||
| 60 | ProgramAction, | ||
| 61 | ProgramCommands, | ||
| 62 | ProgramContext, | ||
| 63 | ProgramStore, | ||
| 64 | }, | ||
| 65 | config::{ApplicationSettings, Iamb}, | ||
| 66 | message::{Message, MessageContent, MessageTimeStamp}, | ||
| 67 | windows::IambWindow, | ||
| 68 | worker::{ClientWorker, LoginStyle, Requester}, | ||
| 69 | }; | ||
| 70 | |||
| 71 | use modalkit::{ | ||
| 72 | editing::{ | ||
| 73 | action::{ | ||
| 74 | Action, | ||
| 75 | Commandable, | ||
| 76 | EditError, | ||
| 77 | EditInfo, | ||
| 78 | Editable, | ||
| 79 | Jumpable, | ||
| 80 | Promptable, | ||
| 81 | Scrollable, | ||
| 82 | TabContainer, | ||
| 83 | TabCount, | ||
| 84 | WindowAction, | ||
| 85 | WindowContainer, | ||
| 86 | }, | ||
| 87 | base::{OpenTarget, RepeatType}, | ||
| 88 | context::Resolve, | ||
| 89 | key::KeyManager, | ||
| 90 | store::Store, | ||
| 91 | }, | ||
| 92 | input::{bindings::BindingMachine, key::TerminalKey}, | ||
| 93 | widgets::{ | ||
| 94 | cmdbar::CommandBarState, | ||
| 95 | screen::{Screen, ScreenState}, | ||
| 96 | TerminalCursor, | ||
| 97 | TerminalExtOps, | ||
| 98 | Window, | ||
| 99 | }, | ||
| 100 | }; | ||
| 101 | |||
| 102 | struct Application { | ||
| 103 | store: AsyncProgramStore, | ||
| 104 | worker: Requester, | ||
| 105 | terminal: Terminal<CrosstermBackend<Stdout>>, | ||
| 106 | bindings: KeyManager<TerminalKey, ProgramAction, RepeatType, ProgramContext>, | ||
| 107 | actstack: VecDeque<(ProgramAction, ProgramContext)>, | ||
| 108 | cmds: ProgramCommands, | ||
| 109 | screen: ScreenState<IambWindow, IambInfo>, | ||
| 110 | } | ||
| 111 | |||
| 112 | impl Application { | ||
| 113 | pub async fn new( | ||
| 114 | settings: ApplicationSettings, | ||
| 115 | store: AsyncProgramStore, | ||
| 116 | ) -> IambResult<Application> { | ||
| 117 | let mut stdout = stdout(); | ||
| 118 | crossterm::terminal::enable_raw_mode()?; | ||
| 119 | crossterm::execute!(stdout, EnterAlternateScreen)?; | ||
| 120 | |||
| 121 | let title = format!("iamb ({})", settings.profile.user_id); | ||
| 122 | crossterm::execute!(stdout, SetTitle(title))?; | ||
| 123 | |||
| 124 | let backend = CrosstermBackend::new(stdout); | ||
| 125 | let terminal = Terminal::new(backend)?; | ||
| 126 | |||
| 127 | let bindings = crate::keybindings::setup_keybindings(); | ||
| 128 | let bindings = KeyManager::new(bindings); | ||
| 129 | let cmds = crate::commands::setup_commands(); | ||
| 130 | |||
| 131 | let mut locked = store.lock().await; | ||
| 132 | let win = IambWindow::open(IambId::Welcome, locked.deref_mut()).unwrap(); | ||
| 133 | let cmd = CommandBarState::new(IambBufferId::Command, locked.deref_mut()); | ||
| 134 | let screen = ScreenState::new(win, cmd); | ||
| 135 | |||
| 136 | let worker = locked.application.worker.clone(); | ||
| 137 | drop(locked); | ||
| 138 | |||
| 139 | let actstack = VecDeque::new(); | ||
| 140 | |||
| 141 | Ok(Application { | ||
| 142 | store, | ||
| 143 | worker, | ||
| 144 | terminal, | ||
| 145 | bindings, | ||
| 146 | actstack, | ||
| 147 | cmds, | ||
| 148 | screen, | ||
| 149 | }) | ||
| 150 | } | ||
| 151 | |||
| 152 | fn redraw(&mut self, full: bool, store: &mut ProgramStore) -> Result<(), std::io::Error> { | ||
| 153 | let modestr = self.bindings.showmode(); | ||
| 154 | let cursor = self.bindings.get_cursor_indicator(); | ||
| 155 | let sstate = &mut self.screen; | ||
| 156 | let term = &mut self.terminal; | ||
| 157 | |||
| 158 | if full { | ||
| 159 | term.clear()?; | ||
| 160 | } | ||
| 161 | |||
| 162 | term.draw(|f| { | ||
| 163 | let area = f.size(); | ||
| 164 | |||
| 165 | let screen = Screen::new(store).showmode(modestr); | ||
| 166 | f.render_stateful_widget(screen, area, sstate); | ||
| 167 | |||
| 168 | if let Some((cx, cy)) = sstate.get_term_cursor() { | ||
| 169 | if let Some(c) = cursor { | ||
| 170 | let style = Style::default().fg(Color::Green); | ||
| 171 | let span = Span::styled(c.to_string(), style); | ||
| 172 | let para = Paragraph::new(span); | ||
| 173 | let inner = Rect::new(cx, cy, 1, 1); | ||
| 174 | f.render_widget(para, inner) | ||
| 175 | } | ||
| 176 | f.set_cursor(cx, cy); | ||
| 177 | } | ||
| 178 | |||
| 179 | store.application.load_older(area.height as u32); | ||
| 180 | })?; | ||
| 181 | |||
| 182 | Ok(()) | ||
| 183 | } | ||
| 184 | |||
| 185 | async fn step(&mut self) -> Result<TerminalKey, std::io::Error> { | ||
| 186 | loop { | ||
| 187 | self.redraw(false, self.store.clone().lock().await.deref_mut())?; | ||
| 188 | |||
| 189 | if !poll(Duration::from_millis(500))? { | ||
| 190 | continue; | ||
| 191 | } | ||
| 192 | |||
| 193 | match read()? { | ||
| 194 | Event::Key(ke) => return Ok(ke.into()), | ||
| 195 | Event::Mouse(_) => { | ||
| 196 | // Do nothing for now. | ||
| 197 | }, | ||
| 198 | Event::FocusGained | Event::FocusLost => { | ||
| 199 | // Do nothing for now. | ||
| 200 | }, | ||
| 201 | Event::Resize(_, _) => { | ||
| 202 | // We'll redraw for the new size next time step() is called. | ||
| 203 | }, | ||
| 204 | Event::Paste(_) => { | ||
| 205 | // Do nothing for now. | ||
| 206 | }, | ||
| 207 | } | ||
| 208 | } | ||
| 209 | } | ||
| 210 | |||
| 211 | fn action_prepend(&mut self, acts: Vec<(ProgramAction, ProgramContext)>) { | ||
| 212 | let mut acts = VecDeque::from(acts); | ||
| 213 | acts.append(&mut self.actstack); | ||
| 214 | self.actstack = acts; | ||
| 215 | } | ||
| 216 | |||
| 217 | fn action_pop(&mut self, keyskip: bool) -> Option<(ProgramAction, ProgramContext)> { | ||
| 218 | if let res @ Some(_) = self.actstack.pop_front() { | ||
| 219 | return res; | ||
| 220 | } | ||
| 221 | |||
| 222 | if keyskip { | ||
| 223 | return None; | ||
| 224 | } else { | ||
| 225 | return self.bindings.pop(); | ||
| 226 | } | ||
| 227 | } | ||
| 228 | |||
| 229 | fn action_run( | ||
| 230 | &mut self, | ||
| 231 | action: ProgramAction, | ||
| 232 | ctx: ProgramContext, | ||
| 233 | store: &mut ProgramStore, | ||
| 234 | ) -> IambResult<EditInfo> { | ||
| 235 | let info = match action { | ||
| 236 | // Do nothing. | ||
| 237 | Action::NoOp => None, | ||
| 238 | |||
| 239 | Action::Editor(act) => { | ||
| 240 | match self.screen.editor_command(&act, &ctx, store) { | ||
| 241 | Ok(info) => info, | ||
| 242 | Err(EditError::WrongBuffer(content)) if act.is_switchable(&ctx) => { | ||
| 243 | // Switch to the right window. | ||
| 244 | if let Some(winid) = content.to_window() { | ||
| 245 | let open = OpenTarget::Application(winid); | ||
| 246 | let open = WindowAction::Switch(open); | ||
| 247 | let _ = self.screen.window_command(&open, &ctx, store)?; | ||
| 248 | |||
| 249 | // Run command again. | ||
| 250 | self.screen.editor_command(&act, &ctx, store)? | ||
| 251 | } else { | ||
| 252 | return Err(EditError::WrongBuffer(content).into()); | ||
| 253 | } | ||
| 254 | }, | ||
| 255 | Err(err) => return Err(err.into()), | ||
| 256 | } | ||
| 257 | }, | ||
| 258 | |||
| 259 | // Simple delegations. | ||
| 260 | Action::Application(act) => self.iamb_run(act, ctx, store)?, | ||
| 261 | Action::CommandBar(act) => self.screen.command_bar(&act, &ctx)?, | ||
| 262 | Action::Macro(act) => self.bindings.macro_command(&act, &ctx, store)?, | ||
| 263 | Action::Scroll(style) => self.screen.scroll(&style, &ctx, store)?, | ||
| 264 | Action::Suspend => self.terminal.program_suspend()?, | ||
| 265 | Action::Tab(cmd) => self.screen.tab_command(&cmd, &ctx, store)?, | ||
| 266 | Action::Window(cmd) => self.screen.window_command(&cmd, &ctx, store)?, | ||
| 267 | |||
| 268 | Action::Jump(l, dir, count) => { | ||
| 269 | let count = ctx.resolve(&count); | ||
| 270 | let _ = self.screen.jump(l, dir, count, &ctx)?; | ||
| 271 | |||
| 272 | None | ||
| 273 | }, | ||
| 274 | |||
| 275 | // UI actions. | ||
| 276 | Action::RedrawScreen => { | ||
| 277 | self.screen.clear_message(); | ||
| 278 | self.redraw(true, store)?; | ||
| 279 | |||
| 280 | None | ||
| 281 | }, | ||
| 282 | |||
| 283 | // Actions that create more Actions. | ||
| 284 | Action::Prompt(act) => { | ||
| 285 | let acts = self.screen.prompt(&act, &ctx, store)?; | ||
| 286 | self.action_prepend(acts); | ||
| 287 | |||
| 288 | None | ||
| 289 | }, | ||
| 290 | Action::Command(act) => { | ||
| 291 | let acts = self.cmds.command(&act, &ctx)?; | ||
| 292 | self.action_prepend(acts); | ||
| 293 | |||
| 294 | None | ||
| 295 | }, | ||
| 296 | Action::Repeat(rt) => { | ||
| 297 | self.bindings.repeat(rt, Some(ctx)); | ||
| 298 | |||
| 299 | None | ||
| 300 | }, | ||
| 301 | |||
| 302 | // Unimplemented. | ||
| 303 | Action::KeywordLookup => { | ||
| 304 | // XXX: implement | ||
| 305 | None | ||
| 306 | }, | ||
| 307 | |||
| 308 | _ => { | ||
| 309 | // XXX: log unhandled actions? print message? | ||
| 310 | None | ||
| 311 | }, | ||
| 312 | }; | ||
| 313 | |||
| 314 | return Ok(info); | ||
| 315 | } | ||
| 316 | |||
| 317 | fn iamb_run( | ||
| 318 | &mut self, | ||
| 319 | action: IambAction, | ||
| 320 | _: ProgramContext, | ||
| 321 | store: &mut ProgramStore, | ||
| 322 | ) -> IambResult<EditInfo> { | ||
| 323 | let info = match action { | ||
| 324 | IambAction::ToggleScrollbackFocus => { | ||
| 325 | self.screen.current_window_mut()?.focus_toggle(); | ||
| 326 | |||
| 327 | None | ||
| 328 | }, | ||
| 329 | |||
| 330 | IambAction::SendMessage(room_id, msg) => { | ||
| 331 | let (event_id, msg) = self.worker.send_message(room_id.clone(), msg)?; | ||
| 332 | let user = store.application.settings.profile.user_id.clone(); | ||
| 333 | let info = store.application.get_room_info(room_id); | ||
| 334 | let key = (MessageTimeStamp::LocalEcho, event_id); | ||
| 335 | let msg = MessageContent::Original(msg.into()); | ||
| 336 | let msg = Message::new(msg, user, MessageTimeStamp::LocalEcho); | ||
| 337 | info.messages.insert(key, msg); | ||
| 338 | |||
| 339 | None | ||
| 340 | }, | ||
| 341 | IambAction::Verify(act, user_dev) => { | ||
| 342 | if let Some(sas) = store.application.verifications.get(&user_dev) { | ||
| 343 | self.worker.verify(act, sas.clone())? | ||
| 344 | } else { | ||
| 345 | return Err(IambError::InvalidVerificationId(user_dev).into()); | ||
| 346 | } | ||
| 347 | }, | ||
| 348 | IambAction::VerifyRequest(user_id) => { | ||
| 349 | if let Ok(user_id) = OwnedUserId::try_from(user_id.as_str()) { | ||
| 350 | self.worker.verify_request(user_id)? | ||
| 351 | } else { | ||
| 352 | return Err(IambError::InvalidUserId(user_id).into()); | ||
| 353 | } | ||
| 354 | }, | ||
| 355 | }; | ||
| 356 | |||
| 357 | Ok(info) | ||
| 358 | } | ||
| 359 | |||
| 360 | pub async fn run(&mut self) -> Result<(), std::io::Error> { | ||
| 361 | self.terminal.clear()?; | ||
| 362 | |||
| 363 | let store = self.store.clone(); | ||
| 364 | |||
| 365 | while self.screen.tabs() != 0 { | ||
| 366 | let key = self.step().await?; | ||
| 367 | |||
| 368 | self.bindings.input_key(key); | ||
| 369 | |||
| 370 | let mut locked = store.lock().await; | ||
| 371 | let mut keyskip = false; | ||
| 372 | |||
| 373 | while let Some((action, ctx)) = self.action_pop(keyskip) { | ||
| 374 | match self.action_run(action, ctx, locked.deref_mut()) { | ||
| 375 | Ok(None) => { | ||
| 376 | // Continue processing. | ||
| 377 | continue; | ||
| 378 | }, | ||
| 379 | Ok(Some(info)) => { | ||
| 380 | self.screen.push_info(info); | ||
| 381 | |||
| 382 | // Continue processing; we'll redraw later. | ||
| 383 | continue; | ||
| 384 | }, | ||
| 385 | Err(e) => { | ||
| 386 | self.screen.push_error(e); | ||
| 387 | |||
| 388 | // Skip processing any more keypress Actions until the next key. | ||
| 389 | keyskip = true; | ||
| 390 | continue; | ||
| 391 | }, | ||
| 392 | } | ||
| 393 | } | ||
| 394 | } | ||
| 395 | |||
| 396 | crossterm::terminal::disable_raw_mode()?; | ||
| 397 | execute!(self.terminal.backend_mut(), LeaveAlternateScreen)?; | ||
| 398 | self.terminal.show_cursor()?; | ||
| 399 | |||
| 400 | return Ok(()); | ||
| 401 | } | ||
| 402 | } | ||
| 403 | |||
| 404 | fn login(worker: Requester, settings: &ApplicationSettings) -> IambResult<()> { | ||
| 405 | println!("Logging in for {}...", settings.profile.user_id); | ||
| 406 | |||
| 407 | if settings.session_json.is_file() { | ||
| 408 | let file = File::open(settings.session_json.as_path())?; | ||
| 409 | let reader = BufReader::new(file); | ||
| 410 | let session = serde_json::from_reader(reader).map_err(IambError::from)?; | ||
| 411 | |||
| 412 | worker.login(LoginStyle::SessionRestore(session))?; | ||
| 413 | |||
| 414 | return Ok(()); | ||
| 415 | } | ||
| 416 | |||
| 417 | loop { | ||
| 418 | let password = rpassword::prompt_password("Password: ")?; | ||
| 419 | |||
| 420 | match worker.login(LoginStyle::Password(password)) { | ||
| 421 | Ok(info) => { | ||
| 422 | if let Some(msg) = info { | ||
| 423 | println!("{}", msg); | ||
| 424 | } | ||
| 425 | |||
| 426 | break; | ||
| 427 | }, | ||
| 428 | Err(err) => { | ||
| 429 | println!("Failed to login: {}", err); | ||
| 430 | continue; | ||
| 431 | }, | ||
| 432 | } | ||
| 433 | } | ||
| 434 | |||
| 435 | Ok(()) | ||
| 436 | } | ||
| 437 | |||
| 438 | fn print_exit<T: Display, N>(v: T) -> N { | ||
| 439 | println!("{}", v); | ||
| 440 | process::exit(2); | ||
| 441 | } | ||
| 442 | |||
| 443 | #[tokio::main] | ||
| 444 | async fn main() -> IambResult<()> { | ||
| 445 | // Parse command-line flags. | ||
| 446 | let iamb = Iamb::parse(); | ||
| 447 | |||
| 448 | // Load configuration and set up the Matrix SDK. | ||
| 449 | let settings = ApplicationSettings::load(iamb).unwrap_or_else(print_exit); | ||
| 450 | |||
| 451 | // Set up the tracing subscriber so we can log client messages. | ||
| 452 | let log_prefix = format!("iamb-log-{}", settings.profile_name); | ||
| 453 | let mut log_dir = settings.cache_dir.clone(); | ||
| 454 | log_dir.push("logs"); | ||
| 455 | |||
| 456 | create_dir_all(settings.matrix_dir.as_path())?; | ||
| 457 | create_dir_all(log_dir.as_path())?; | ||
| 458 | |||
| 459 | let appender = tracing_appender::rolling::daily(log_dir, log_prefix); | ||
| 460 | let (appender, _) = tracing_appender::non_blocking(appender); | ||
| 461 | |||
| 462 | let subscriber = FmtSubscriber::builder() | ||
| 463 | .with_writer(appender) | ||
| 464 | .with_max_level(Level::WARN) | ||
| 465 | .finish(); | ||
| 466 | tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed"); | ||
| 467 | |||
| 468 | // Set up the async worker thread and global store. | ||
| 469 | let worker = ClientWorker::spawn(settings.clone()); | ||
| 470 | let store = ChatStore::new(worker.clone(), settings.clone()); | ||
| 471 | let store = Store::new(store); | ||
| 472 | let store = Arc::new(AsyncMutex::new(store)); | ||
| 473 | worker.init(store.clone()); | ||
| 474 | |||
| 475 | login(worker, &settings).unwrap_or_else(print_exit); | ||
| 476 | |||
| 477 | // Make sure panics clean up the terminal properly. | ||
| 478 | let orig_hook = std::panic::take_hook(); | ||
| 479 | std::panic::set_hook(Box::new(move |panic_info| { | ||
| 480 | let _ = crossterm::terminal::disable_raw_mode(); | ||
| 481 | let _ = crossterm::execute!(stdout(), LeaveAlternateScreen); | ||
| 482 | let _ = crossterm::execute!(stdout(), CursorShow); | ||
| 483 | orig_hook(panic_info); | ||
| 484 | process::exit(1); | ||
| 485 | })); | ||
| 486 | |||
| 487 | let mut application = Application::new(settings, store).await?; | ||
| 488 | |||
| 489 | // We can now run the application. | ||
| 490 | application.run().await?; | ||
| 491 | |||
| 492 | process::exit(0); | ||
| 3 | } | 493 | } |
src/message.rs added +644
| @@ -0,0 +1,644 @@ | |||
| 1 | use std::borrow::Cow; | ||
| 2 | use std::cmp::{Ord, Ordering, PartialOrd}; | ||
| 3 | use std::collections::hash_map::DefaultHasher; | ||
| 4 | use std::collections::BTreeMap; | ||
| 5 | use std::convert::TryFrom; | ||
| 6 | use std::hash::{Hash, Hasher}; | ||
| 7 | use std::str::Lines; | ||
| 8 | |||
| 9 | use chrono::{DateTime, NaiveDateTime, Utc}; | ||
| 10 | use unicode_segmentation::UnicodeSegmentation; | ||
| 11 | use unicode_width::UnicodeWidthStr; | ||
| 12 | |||
| 13 | use matrix_sdk::ruma::{ | ||
| 14 | events::{ | ||
| 15 | room::message::{MessageType, RoomMessageEventContent}, | ||
| 16 | MessageLikeEvent, | ||
| 17 | }, | ||
| 18 | MilliSecondsSinceUnixEpoch, | ||
| 19 | OwnedEventId, | ||
| 20 | OwnedUserId, | ||
| 21 | UInt, | ||
| 22 | }; | ||
| 23 | |||
| 24 | use modalkit::tui::{ | ||
| 25 | style::{Color, Modifier as StyleModifier, Style}, | ||
| 26 | text::{Span, Spans, Text}, | ||
| 27 | }; | ||
| 28 | |||
| 29 | use modalkit::editing::{base::ViewportContext, cursor::Cursor}; | ||
| 30 | |||
| 31 | use crate::base::{IambResult, RoomInfo}; | ||
| 32 | |||
| 33 | pub type MessageEvent = MessageLikeEvent<RoomMessageEventContent>; | ||
| 34 | pub type MessageFetchResult = IambResult<(Option<String>, Vec<MessageEvent>)>; | ||
| 35 | pub type MessageKey = (MessageTimeStamp, OwnedEventId); | ||
| 36 | pub type Messages = BTreeMap<MessageKey, Message>; | ||
| 37 | |||
| 38 | const COLORS: [Color; 13] = [ | ||
| 39 | Color::Blue, | ||
| 40 | Color::Cyan, | ||
| 41 | Color::Green, | ||
| 42 | Color::LightBlue, | ||
| 43 | Color::LightGreen, | ||
| 44 | Color::LightCyan, | ||
| 45 | Color::LightMagenta, | ||
| 46 | Color::LightRed, | ||
| 47 | Color::LightYellow, | ||
| 48 | Color::Magenta, | ||
| 49 | Color::Red, | ||
| 50 | Color::Reset, | ||
| 51 | Color::Yellow, | ||
| 52 | ]; | ||
| 53 | |||
| 54 | const USER_GUTTER: usize = 30; | ||
| 55 | const TIME_GUTTER: usize = 12; | ||
| 56 | const MIN_MSG_LEN: usize = 30; | ||
| 57 | |||
| 58 | const USER_GUTTER_EMPTY: &str = " "; | ||
| 59 | const USER_GUTTER_EMPTY_SPAN: Span<'static> = Span { | ||
| 60 | content: Cow::Borrowed(USER_GUTTER_EMPTY), | ||
| 61 | style: Style { | ||
| 62 | fg: None, | ||
| 63 | bg: None, | ||
| 64 | add_modifier: StyleModifier::empty(), | ||
| 65 | sub_modifier: StyleModifier::empty(), | ||
| 66 | }, | ||
| 67 | }; | ||
| 68 | |||
| 69 | struct WrappedLinesIterator<'a> { | ||
| 70 | iter: Lines<'a>, | ||
| 71 | curr: Option<&'a str>, | ||
| 72 | width: usize, | ||
| 73 | } | ||
| 74 | |||
| 75 | impl<'a> WrappedLinesIterator<'a> { | ||
| 76 | fn new(input: &'a str, width: usize) -> Self { | ||
| 77 | WrappedLinesIterator { iter: input.lines(), curr: None, width } | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | impl<'a> Iterator for WrappedLinesIterator<'a> { | ||
| 82 | type Item = (&'a str, usize); | ||
| 83 | |||
| 84 | fn next(&mut self) -> Option<Self::Item> { | ||
| 85 | if self.curr.is_none() { | ||
| 86 | self.curr = self.iter.next(); | ||
| 87 | } | ||
| 88 | |||
| 89 | if let Some(s) = self.curr.take() { | ||
| 90 | let width = UnicodeWidthStr::width(s); | ||
| 91 | |||
| 92 | if width <= self.width { | ||
| 93 | return Some((s, width)); | ||
| 94 | } else { | ||
| 95 | // Find where to split the line. | ||
| 96 | let mut width = 0; | ||
| 97 | let mut idx = 0; | ||
| 98 | |||
| 99 | for (i, g) in UnicodeSegmentation::grapheme_indices(s, true) { | ||
| 100 | let gw = UnicodeWidthStr::width(g); | ||
| 101 | idx = i; | ||
| 102 | |||
| 103 | if width + gw > self.width { | ||
| 104 | break; | ||
| 105 | } | ||
| 106 | |||
| 107 | width += gw; | ||
| 108 | } | ||
| 109 | |||
| 110 | self.curr = Some(&s[idx..]); | ||
| 111 | |||
| 112 | return Some((&s[..idx], width)); | ||
| 113 | } | ||
| 114 | } else { | ||
| 115 | return None; | ||
| 116 | } | ||
| 117 | } | ||
| 118 | } | ||
| 119 | |||
| 120 | fn wrap(input: &str, width: usize) -> WrappedLinesIterator<'_> { | ||
| 121 | WrappedLinesIterator::new(input, width) | ||
| 122 | } | ||
| 123 | |||
| 124 | fn space(width: usize) -> String { | ||
| 125 | " ".repeat(width) | ||
| 126 | } | ||
| 127 | |||
| 128 | #[derive(thiserror::Error, Debug)] | ||
| 129 | pub enum TimeStampIntError { | ||
| 130 | #[error("Integer conversion error: {0}")] | ||
| 131 | IntError(#[from] std::num::TryFromIntError), | ||
| 132 | |||
| 133 | #[error("UInt conversion error: {0}")] | ||
| 134 | UIntError(<UInt as TryFrom<u64>>::Error), | ||
| 135 | } | ||
| 136 | |||
| 137 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
| 138 | pub enum MessageTimeStamp { | ||
| 139 | OriginServer(UInt), | ||
| 140 | LocalEcho, | ||
| 141 | } | ||
| 142 | |||
| 143 | impl MessageTimeStamp { | ||
| 144 | fn show(&self) -> Option<Span> { | ||
| 145 | match self { | ||
| 146 | MessageTimeStamp::OriginServer(ts) => { | ||
| 147 | let time = i64::from(*ts) / 1000; | ||
| 148 | let time = NaiveDateTime::from_timestamp_opt(time, 0)?; | ||
| 149 | let time = DateTime::<Utc>::from_utc(time, Utc); | ||
| 150 | let time = time.format("%T"); | ||
| 151 | let time = format!(" [{}]", time); | ||
| 152 | |||
| 153 | Span::raw(time).into() | ||
| 154 | }, | ||
| 155 | MessageTimeStamp::LocalEcho => None, | ||
| 156 | } | ||
| 157 | } | ||
| 158 | |||
| 159 | fn is_local_echo(&self) -> bool { | ||
| 160 | matches!(self, MessageTimeStamp::LocalEcho) | ||
| 161 | } | ||
| 162 | } | ||
| 163 | |||
| 164 | impl Ord for MessageTimeStamp { | ||
| 165 | fn cmp(&self, other: &Self) -> Ordering { | ||
| 166 | match (self, other) { | ||
| 167 | (MessageTimeStamp::OriginServer(_), MessageTimeStamp::LocalEcho) => Ordering::Less, | ||
| 168 | (MessageTimeStamp::OriginServer(a), MessageTimeStamp::OriginServer(b)) => a.cmp(b), | ||
| 169 | (MessageTimeStamp::LocalEcho, MessageTimeStamp::OriginServer(_)) => Ordering::Greater, | ||
| 170 | (MessageTimeStamp::LocalEcho, MessageTimeStamp::LocalEcho) => Ordering::Equal, | ||
| 171 | } | ||
| 172 | } | ||
| 173 | } | ||
| 174 | |||
| 175 | impl PartialOrd for MessageTimeStamp { | ||
| 176 | fn partial_cmp(&self, other: &Self) -> Option<Ordering> { | ||
| 177 | self.cmp(other).into() | ||
| 178 | } | ||
| 179 | } | ||
| 180 | |||
| 181 | impl From<MilliSecondsSinceUnixEpoch> for MessageTimeStamp { | ||
| 182 | fn from(millis: MilliSecondsSinceUnixEpoch) -> Self { | ||
| 183 | MessageTimeStamp::OriginServer(millis.0) | ||
| 184 | } | ||
| 185 | } | ||
| 186 | |||
| 187 | impl TryFrom<&MessageTimeStamp> for usize { | ||
| 188 | type Error = TimeStampIntError; | ||
| 189 | |||
| 190 | fn try_from(ts: &MessageTimeStamp) -> Result<Self, Self::Error> { | ||
| 191 | let n = match ts { | ||
| 192 | MessageTimeStamp::LocalEcho => 0, | ||
| 193 | MessageTimeStamp::OriginServer(u) => usize::try_from(u64::from(*u))?, | ||
| 194 | }; | ||
| 195 | |||
| 196 | Ok(n) | ||
| 197 | } | ||
| 198 | } | ||
| 199 | |||
| 200 | impl TryFrom<usize> for MessageTimeStamp { | ||
| 201 | type Error = TimeStampIntError; | ||
| 202 | |||
| 203 | fn try_from(u: usize) -> Result<Self, Self::Error> { | ||
| 204 | if u == 0 { | ||
| 205 | Ok(MessageTimeStamp::LocalEcho) | ||
| 206 | } else { | ||
| 207 | let n = u64::try_from(u)?; | ||
| 208 | let n = UInt::try_from(n).map_err(TimeStampIntError::UIntError)?; | ||
| 209 | |||
| 210 | Ok(MessageTimeStamp::OriginServer(n)) | ||
| 211 | } | ||
| 212 | } | ||
| 213 | } | ||
| 214 | |||
| 215 | #[derive(Clone, Debug, Default, Eq, PartialEq)] | ||
| 216 | pub struct MessageCursor { | ||
| 217 | /// When timestamp is None, the corner is determined by moving backwards from | ||
| 218 | /// the most recently received message. | ||
| 219 | pub timestamp: Option<MessageKey>, | ||
| 220 | |||
| 221 | /// A row within the [Text] representation of a [Message]. | ||
| 222 | pub text_row: usize, | ||
| 223 | } | ||
| 224 | |||
| 225 | impl MessageCursor { | ||
| 226 | pub fn new(timestamp: MessageKey, text_row: usize) -> Self { | ||
| 227 | MessageCursor { timestamp: Some(timestamp), text_row } | ||
| 228 | } | ||
| 229 | |||
| 230 | /// Get a cursor that refers to the most recent message. | ||
| 231 | pub fn latest() -> Self { | ||
| 232 | MessageCursor::default() | ||
| 233 | } | ||
| 234 | |||
| 235 | pub fn to_key<'a>(&'a self, info: &'a RoomInfo) -> Option<&'a MessageKey> { | ||
| 236 | if let Some(ref key) = self.timestamp { | ||
| 237 | Some(key) | ||
| 238 | } else { | ||
| 239 | Some(info.messages.last_key_value()?.0) | ||
| 240 | } | ||
| 241 | } | ||
| 242 | |||
| 243 | pub fn from_cursor(cursor: &Cursor, info: &RoomInfo) -> Option<Self> { | ||
| 244 | let ev_hash = u64::try_from(cursor.get_x()).ok()?; | ||
| 245 | let ev_term = OwnedEventId::try_from("$").ok()?; | ||
| 246 | |||
| 247 | let ts_start = MessageTimeStamp::try_from(cursor.get_y()).ok()?; | ||
| 248 | let start = (ts_start, ev_term); | ||
| 249 | let mut mc = None; | ||
| 250 | |||
| 251 | for ((ts, event_id), _) in info.messages.range(start..) { | ||
| 252 | let mut hasher = DefaultHasher::new(); | ||
| 253 | event_id.hash(&mut hasher); | ||
| 254 | |||
| 255 | if hasher.finish() == ev_hash { | ||
| 256 | mc = Self::from((*ts, event_id.clone())).into(); | ||
| 257 | break; | ||
| 258 | } | ||
| 259 | |||
| 260 | if mc.is_none() { | ||
| 261 | mc = Self::from((*ts, event_id.clone())).into(); | ||
| 262 | } | ||
| 263 | |||
| 264 | if ts > &ts_start { | ||
| 265 | break; | ||
| 266 | } | ||
| 267 | } | ||
| 268 | |||
| 269 | return mc; | ||
| 270 | } | ||
| 271 | |||
| 272 | pub fn to_cursor(&self, info: &RoomInfo) -> Option<Cursor> { | ||
| 273 | let (ts, event_id) = self.to_key(info)?; | ||
| 274 | |||
| 275 | let y: usize = usize::try_from(ts).ok()?; | ||
| 276 | |||
| 277 | let mut hasher = DefaultHasher::new(); | ||
| 278 | event_id.hash(&mut hasher); | ||
| 279 | let x = usize::try_from(hasher.finish()).ok()?; | ||
| 280 | |||
| 281 | Cursor::new(y, x).into() | ||
| 282 | } | ||
| 283 | } | ||
| 284 | |||
| 285 | impl From<Option<MessageKey>> for MessageCursor { | ||
| 286 | fn from(key: Option<MessageKey>) -> Self { | ||
| 287 | MessageCursor { timestamp: key, text_row: 0 } | ||
| 288 | } | ||
| 289 | } | ||
| 290 | |||
| 291 | impl From<MessageKey> for MessageCursor { | ||
| 292 | fn from(key: MessageKey) -> Self { | ||
| 293 | MessageCursor { timestamp: Some(key), text_row: 0 } | ||
| 294 | } | ||
| 295 | } | ||
| 296 | |||
| 297 | impl Ord for MessageCursor { | ||
| 298 | fn cmp(&self, other: &Self) -> Ordering { | ||
| 299 | match (&self.timestamp, &other.timestamp) { | ||
| 300 | (None, None) => self.text_row.cmp(&other.text_row), | ||
| 301 | (None, Some(_)) => Ordering::Greater, | ||
| 302 | (Some(_), None) => Ordering::Less, | ||
| 303 | (Some(st), Some(ot)) => { | ||
| 304 | let pcmp = st.cmp(ot); | ||
| 305 | let tcmp = self.text_row.cmp(&other.text_row); | ||
| 306 | |||
| 307 | pcmp.then(tcmp) | ||
| 308 | }, | ||
| 309 | } | ||
| 310 | } | ||
| 311 | } | ||
| 312 | |||
| 313 | impl PartialOrd for MessageCursor { | ||
| 314 | fn partial_cmp(&self, other: &Self) -> Option<Ordering> { | ||
| 315 | self.cmp(other).into() | ||
| 316 | } | ||
| 317 | } | ||
| 318 | |||
| 319 | #[derive(Clone)] | ||
| 320 | pub enum MessageContent { | ||
| 321 | Original(Box<RoomMessageEventContent>), | ||
| 322 | Redacted, | ||
| 323 | } | ||
| 324 | |||
| 325 | impl AsRef<str> for MessageContent { | ||
| 326 | fn as_ref(&self) -> &str { | ||
| 327 | match self { | ||
| 328 | MessageContent::Original(ev) => { | ||
| 329 | match &ev.msgtype { | ||
| 330 | MessageType::Text(content) => { | ||
| 331 | return content.body.as_ref(); | ||
| 332 | }, | ||
| 333 | MessageType::Emote(content) => { | ||
| 334 | return content.body.as_ref(); | ||
| 335 | }, | ||
| 336 | MessageType::Notice(content) => { | ||
| 337 | return content.body.as_str(); | ||
| 338 | }, | ||
| 339 | MessageType::ServerNotice(_) => { | ||
| 340 | // XXX: implement | ||
| 341 | |||
| 342 | return "[server notice]"; | ||
| 343 | }, | ||
| 344 | MessageType::VerificationRequest(_) => { | ||
| 345 | // XXX: implement | ||
| 346 | |||
| 347 | return "[verification request]"; | ||
| 348 | }, | ||
| 349 | MessageType::Audio(..) => { | ||
| 350 | return "[audio]"; | ||
| 351 | }, | ||
| 352 | MessageType::File(..) => { | ||
| 353 | return "[file]"; | ||
| 354 | }, | ||
| 355 | MessageType::Image(..) => { | ||
| 356 | return "[image]"; | ||
| 357 | }, | ||
| 358 | MessageType::Video(..) => { | ||
| 359 | return "[video]"; | ||
| 360 | }, | ||
| 361 | _ => return "[unknown message type]", | ||
| 362 | } | ||
| 363 | }, | ||
| 364 | MessageContent::Redacted => "[redacted]", | ||
| 365 | } | ||
| 366 | } | ||
| 367 | } | ||
| 368 | |||
| 369 | #[derive(Clone)] | ||
| 370 | pub struct Message { | ||
| 371 | pub content: MessageContent, | ||
| 372 | pub sender: OwnedUserId, | ||
| 373 | pub timestamp: MessageTimeStamp, | ||
| 374 | } | ||
| 375 | |||
| 376 | impl Message { | ||
| 377 | pub fn new(content: MessageContent, sender: OwnedUserId, timestamp: MessageTimeStamp) -> Self { | ||
| 378 | Message { content, sender, timestamp } | ||
| 379 | } | ||
| 380 | |||
| 381 | pub fn show(&self, selected: bool, vwctx: &ViewportContext<MessageCursor>) -> Text { | ||
| 382 | let width = vwctx.get_width(); | ||
| 383 | let msg = self.as_ref(); | ||
| 384 | |||
| 385 | let mut lines = vec![]; | ||
| 386 | |||
| 387 | let mut style = Style::default(); | ||
| 388 | |||
| 389 | if selected { | ||
| 390 | style = style.add_modifier(StyleModifier::REVERSED) | ||
| 391 | } | ||
| 392 | |||
| 393 | if self.timestamp.is_local_echo() { | ||
| 394 | style = style.add_modifier(StyleModifier::ITALIC); | ||
| 395 | } | ||
| 396 | |||
| 397 | if USER_GUTTER + TIME_GUTTER + MIN_MSG_LEN <= width { | ||
| 398 | let lw = width - USER_GUTTER - TIME_GUTTER; | ||
| 399 | |||
| 400 | for (i, (line, w)) in wrap(msg, lw).enumerate() { | ||
| 401 | let line = Span::styled(line, style); | ||
| 402 | let trailing = Span::styled(space(lw.saturating_sub(w)), style); | ||
| 403 | |||
| 404 | if i == 0 { | ||
| 405 | let user = self.show_sender(true); | ||
| 406 | |||
| 407 | if let Some(time) = self.timestamp.show() { | ||
| 408 | lines.push(Spans(vec![user, line, trailing, time])) | ||
| 409 | } else { | ||
| 410 | lines.push(Spans(vec![user, line, trailing])) | ||
| 411 | } | ||
| 412 | } else { | ||
| 413 | let space = USER_GUTTER_EMPTY_SPAN; | ||
| 414 | |||
| 415 | lines.push(Spans(vec![space, line, trailing])) | ||
| 416 | } | ||
| 417 | } | ||
| 418 | } else if USER_GUTTER + MIN_MSG_LEN <= width { | ||
| 419 | let lw = width - USER_GUTTER; | ||
| 420 | |||
| 421 | for (i, (line, w)) in wrap(msg, lw).enumerate() { | ||
| 422 | let line = Span::styled(line, style); | ||
| 423 | let trailing = Span::styled(space(lw.saturating_sub(w)), style); | ||
| 424 | |||
| 425 | let prefix = if i == 0 { | ||
| 426 | self.show_sender(true) | ||
| 427 | } else { | ||
| 428 | USER_GUTTER_EMPTY_SPAN | ||
| 429 | }; | ||
| 430 | |||
| 431 | lines.push(Spans(vec![prefix, line, trailing])) | ||
| 432 | } | ||
| 433 | } else { | ||
| 434 | lines.push(Spans::from(self.show_sender(false))); | ||
| 435 | |||
| 436 | for (line, _) in wrap(msg, width.saturating_sub(2)) { | ||
| 437 | let line = format!(" {}", line); | ||
| 438 | let line = Span::styled(line, style); | ||
| 439 | |||
| 440 | lines.push(Spans(vec![line])) | ||
| 441 | } | ||
| 442 | } | ||
| 443 | |||
| 444 | return Text { lines }; | ||
| 445 | } | ||
| 446 | |||
| 447 | fn show_sender(&self, align_right: bool) -> Span { | ||
| 448 | let sender = self.sender.to_string(); | ||
| 449 | |||
| 450 | let mut hasher = DefaultHasher::new(); | ||
| 451 | sender.hash(&mut hasher); | ||
| 452 | let color = hasher.finish() as usize % COLORS.len(); | ||
| 453 | let color = COLORS[color]; | ||
| 454 | |||
| 455 | let bold = Style::default().fg(color).add_modifier(StyleModifier::BOLD); | ||
| 456 | |||
| 457 | let sender = if align_right { | ||
| 458 | format!("{: >width$} ", sender, width = 28) | ||
| 459 | } else { | ||
| 460 | format!("{: <width$} ", sender, width = 28) | ||
| 461 | }; | ||
| 462 | |||
| 463 | Span::styled(sender, bold) | ||
| 464 | } | ||
| 465 | } | ||
| 466 | |||
| 467 | impl From<MessageEvent> for Message { | ||
| 468 | fn from(event: MessageEvent) -> Self { | ||
| 469 | match event { | ||
| 470 | MessageLikeEvent::Original(ev) => { | ||
| 471 | let content = MessageContent::Original(ev.content.into()); | ||
| 472 | |||
| 473 | Message::new(content, ev.sender, ev.origin_server_ts.into()) | ||
| 474 | }, | ||
| 475 | MessageLikeEvent::Redacted(ev) => { | ||
| 476 | Message::new(MessageContent::Redacted, ev.sender, ev.origin_server_ts.into()) | ||
| 477 | }, | ||
| 478 | } | ||
| 479 | } | ||
| 480 | } | ||
| 481 | |||
| 482 | impl AsRef<str> for Message { | ||
| 483 | fn as_ref(&self) -> &str { | ||
| 484 | self.content.as_ref() | ||
| 485 | } | ||
| 486 | } | ||
| 487 | |||
| 488 | impl ToString for Message { | ||
| 489 | fn to_string(&self) -> String { | ||
| 490 | self.as_ref().to_string() | ||
| 491 | } | ||
| 492 | } | ||
| 493 | |||
| 494 | #[cfg(test)] | ||
| 495 | pub mod tests { | ||
| 496 | use super::*; | ||
| 497 | use crate::tests::*; | ||
| 498 | |||
| 499 | #[test] | ||
| 500 | fn test_wrapped_lines_ascii() { | ||
| 501 | let s = "hello world!\nabcdefghijklmnopqrstuvwxyz\ngoodbye"; | ||
| 502 | |||
| 503 | let mut iter = wrap(s, 100); | ||
| 504 | assert_eq!(iter.next(), Some(("hello world!", 12))); | ||
| 505 | assert_eq!(iter.next(), Some(("abcdefghijklmnopqrstuvwxyz", 26))); | ||
| 506 | assert_eq!(iter.next(), Some(("goodbye", 7))); | ||
| 507 | assert_eq!(iter.next(), None); | ||
| 508 | |||
| 509 | let mut iter = wrap(s, 5); | ||
| 510 | assert_eq!(iter.next(), Some(("hello", 5))); | ||
| 511 | assert_eq!(iter.next(), Some((" worl", 5))); | ||
| 512 | assert_eq!(iter.next(), Some(("d!", 2))); | ||
| 513 | assert_eq!(iter.next(), Some(("abcde", 5))); | ||
| 514 | assert_eq!(iter.next(), Some(("fghij", 5))); | ||
| 515 | assert_eq!(iter.next(), Some(("klmno", 5))); | ||
| 516 | assert_eq!(iter.next(), Some(("pqrst", 5))); | ||
| 517 | assert_eq!(iter.next(), Some(("uvwxy", 5))); | ||
| 518 | assert_eq!(iter.next(), Some(("z", 1))); | ||
| 519 | assert_eq!(iter.next(), Some(("goodb", 5))); | ||
| 520 | assert_eq!(iter.next(), Some(("ye", 2))); | ||
| 521 | assert_eq!(iter.next(), None); | ||
| 522 | } | ||
| 523 | |||
| 524 | #[test] | ||
| 525 | fn test_wrapped_lines_unicode() { | ||
| 526 | let s = "CHICKEN"; | ||
| 527 | |||
| 528 | let mut iter = wrap(s, 14); | ||
| 529 | assert_eq!(iter.next(), Some((s, 14))); | ||
| 530 | assert_eq!(iter.next(), None); | ||
| 531 | |||
| 532 | let mut iter = wrap(s, 5); | ||
| 533 | assert_eq!(iter.next(), Some(("CH", 4))); | ||
| 534 | assert_eq!(iter.next(), Some(("IC", 4))); | ||
| 535 | assert_eq!(iter.next(), Some(("KE", 4))); | ||
| 536 | assert_eq!(iter.next(), Some(("N", 2))); | ||
| 537 | assert_eq!(iter.next(), None); | ||
| 538 | } | ||
| 539 | |||
| 540 | #[test] | ||
| 541 | fn test_mc_cmp() { | ||
| 542 | let mc1 = MessageCursor::from(MSG1_KEY.clone()); | ||
| 543 | let mc2 = MessageCursor::from(MSG2_KEY.clone()); | ||
| 544 | let mc3 = MessageCursor::from(MSG3_KEY.clone()); | ||
| 545 | let mc4 = MessageCursor::from(MSG4_KEY.clone()); | ||
| 546 | let mc5 = MessageCursor::from(MSG5_KEY.clone()); | ||
| 547 | |||
| 548 | // Everything is equal to itself. | ||
| 549 | assert_eq!(mc1.cmp(&mc1), Ordering::Equal); | ||
| 550 | assert_eq!(mc2.cmp(&mc2), Ordering::Equal); | ||
| 551 | assert_eq!(mc3.cmp(&mc3), Ordering::Equal); | ||
| 552 | assert_eq!(mc4.cmp(&mc4), Ordering::Equal); | ||
| 553 | assert_eq!(mc5.cmp(&mc5), Ordering::Equal); | ||
| 554 | |||
| 555 | // Local echo is always greater than an origin server timestamp. | ||
| 556 | assert_eq!(mc1.cmp(&mc2), Ordering::Greater); | ||
| 557 | assert_eq!(mc1.cmp(&mc3), Ordering::Greater); | ||
| 558 | assert_eq!(mc1.cmp(&mc4), Ordering::Greater); | ||
| 559 | assert_eq!(mc1.cmp(&mc5), Ordering::Greater); | ||
| 560 | |||
| 561 | // mc2 is the smallest timestamp. | ||
| 562 | assert_eq!(mc2.cmp(&mc1), Ordering::Less); | ||
| 563 | assert_eq!(mc2.cmp(&mc3), Ordering::Less); | ||
| 564 | assert_eq!(mc2.cmp(&mc4), Ordering::Less); | ||
| 565 | assert_eq!(mc2.cmp(&mc5), Ordering::Less); | ||
| 566 | |||
| 567 | // mc3 should be less than mc4 because of its event ID. | ||
| 568 | assert_eq!(mc3.cmp(&mc1), Ordering::Less); | ||
| 569 | assert_eq!(mc3.cmp(&mc2), Ordering::Greater); | ||
| 570 | assert_eq!(mc3.cmp(&mc4), Ordering::Less); | ||
| 571 | assert_eq!(mc3.cmp(&mc5), Ordering::Less); | ||
| 572 | |||
| 573 | // mc4 should be greater than mc3 because of its event ID. | ||
| 574 | assert_eq!(mc4.cmp(&mc1), Ordering::Less); | ||
| 575 | assert_eq!(mc4.cmp(&mc2), Ordering::Greater); | ||
| 576 | assert_eq!(mc4.cmp(&mc3), Ordering::Greater); | ||
| 577 | assert_eq!(mc4.cmp(&mc5), Ordering::Less); | ||
| 578 | |||
| 579 | // mc5 is the greatest OriginServer timestamp. | ||
| 580 | assert_eq!(mc5.cmp(&mc1), Ordering::Less); | ||
| 581 | assert_eq!(mc5.cmp(&mc2), Ordering::Greater); | ||
| 582 | assert_eq!(mc5.cmp(&mc3), Ordering::Greater); | ||
| 583 | assert_eq!(mc5.cmp(&mc4), Ordering::Greater); | ||
| 584 | } | ||
| 585 | |||
| 586 | #[test] | ||
| 587 | fn test_mc_to_key() { | ||
| 588 | let info = mock_room(); | ||
| 589 | let mc1 = MessageCursor::from(MSG1_KEY.clone()); | ||
| 590 | let mc2 = MessageCursor::from(MSG2_KEY.clone()); | ||
| 591 | let mc3 = MessageCursor::from(MSG3_KEY.clone()); | ||
| 592 | let mc4 = MessageCursor::from(MSG4_KEY.clone()); | ||
| 593 | let mc5 = MessageCursor::from(MSG5_KEY.clone()); | ||
| 594 | let mc6 = MessageCursor::latest(); | ||
| 595 | |||
| 596 | let k1 = mc1.to_key(&info).unwrap(); | ||
| 597 | let k2 = mc2.to_key(&info).unwrap(); | ||
| 598 | let k3 = mc3.to_key(&info).unwrap(); | ||
| 599 | let k4 = mc4.to_key(&info).unwrap(); | ||
| 600 | let k5 = mc5.to_key(&info).unwrap(); | ||
| 601 | let k6 = mc6.to_key(&info).unwrap(); | ||
| 602 | |||
| 603 | // These should all be equal to their MSGN_KEYs. | ||
| 604 | assert_eq!(k1, &MSG1_KEY.clone()); | ||
| 605 | assert_eq!(k2, &MSG2_KEY.clone()); | ||
| 606 | assert_eq!(k3, &MSG3_KEY.clone()); | ||
| 607 | assert_eq!(k4, &MSG4_KEY.clone()); | ||
| 608 | assert_eq!(k5, &MSG5_KEY.clone()); | ||
| 609 | |||
| 610 | // MessageCursor::latest() turns into the largest key (our local echo message). | ||
| 611 | assert_eq!(k6, &MSG1_KEY.clone()); | ||
| 612 | |||
| 613 | // MessageCursor::latest() fails to convert for a room w/o messages. | ||
| 614 | let info_empty = RoomInfo::default(); | ||
| 615 | assert_eq!(mc6.to_key(&info_empty), None); | ||
| 616 | } | ||
| 617 | |||
| 618 | #[test] | ||
| 619 | fn test_mc_to_from_cursor() { | ||
| 620 | let info = mock_room(); | ||
| 621 | let mc1 = MessageCursor::from(MSG1_KEY.clone()); | ||
| 622 | let mc2 = MessageCursor::from(MSG2_KEY.clone()); | ||
| 623 | let mc3 = MessageCursor::from(MSG3_KEY.clone()); | ||
| 624 | let mc4 = MessageCursor::from(MSG4_KEY.clone()); | ||
| 625 | let mc5 = MessageCursor::from(MSG5_KEY.clone()); | ||
| 626 | let mc6 = MessageCursor::latest(); | ||
| 627 | |||
| 628 | let identity = |mc: &MessageCursor| { | ||
| 629 | let c = mc.to_cursor(&info).unwrap(); | ||
| 630 | |||
| 631 | MessageCursor::from_cursor(&c, &info).unwrap() | ||
| 632 | }; | ||
| 633 | |||
| 634 | // These should all convert to a Cursor and back to the original value. | ||
| 635 | assert_eq!(identity(&mc1), mc1); | ||
| 636 | assert_eq!(identity(&mc2), mc2); | ||
| 637 | assert_eq!(identity(&mc3), mc3); | ||
| 638 | assert_eq!(identity(&mc4), mc4); | ||
| 639 | assert_eq!(identity(&mc5), mc5); | ||
| 640 | |||
| 641 | // MessageCursor::latest() should point at the most recent message after conversion. | ||
| 642 | assert_eq!(identity(&mc6), mc1); | ||
| 643 | } | ||
| 644 | } | ||
src/tests.rs added +133
| @@ -0,0 +1,133 @@ | |||
| 1 | use std::collections::BTreeMap; | ||
| 2 | |||
| 3 | use matrix_sdk::ruma::{ | ||
| 4 | event_id, | ||
| 5 | events::room::message::RoomMessageEventContent, | ||
| 6 | server_name, | ||
| 7 | user_id, | ||
| 8 | EventId, | ||
| 9 | OwnedRoomId, | ||
| 10 | OwnedUserId, | ||
| 11 | RoomId, | ||
| 12 | UInt, | ||
| 13 | }; | ||
| 14 | |||
| 15 | use std::path::PathBuf; | ||
| 16 | use std::sync::mpsc::sync_channel; | ||
| 17 | use url::Url; | ||
| 18 | |||
| 19 | use lazy_static::lazy_static; | ||
| 20 | |||
| 21 | use crate::{ | ||
| 22 | base::{ChatStore, ProgramStore, RoomFetchStatus, RoomInfo}, | ||
| 23 | config::{ApplicationSettings, ProfileConfig}, | ||
| 24 | message::{ | ||
| 25 | Message, | ||
| 26 | MessageContent, | ||
| 27 | MessageKey, | ||
| 28 | MessageTimeStamp::{LocalEcho, OriginServer}, | ||
| 29 | Messages, | ||
| 30 | }, | ||
| 31 | worker::Requester, | ||
| 32 | }; | ||
| 33 | |||
| 34 | lazy_static! { | ||
| 35 | pub static ref TEST_ROOM1_ID: OwnedRoomId = RoomId::new(server_name!("example.com")).to_owned(); | ||
| 36 | pub static ref TEST_USER1: OwnedUserId = user_id!("@user1:example.com").to_owned(); | ||
| 37 | pub static ref TEST_USER2: OwnedUserId = user_id!("@user2:example.com").to_owned(); | ||
| 38 | pub static ref MSG1_KEY: MessageKey = (LocalEcho, EventId::new(server_name!("example.com"))); | ||
| 39 | pub static ref MSG2_KEY: MessageKey = | ||
| 40 | (OriginServer(UInt::new(1).unwrap()), EventId::new(server_name!("example.com"))); | ||
| 41 | pub static ref MSG3_KEY: MessageKey = ( | ||
| 42 | OriginServer(UInt::new(2).unwrap()), | ||
| 43 | event_id!("$5jRz3KfVhaUzXtVj7k:example.com").to_owned() | ||
| 44 | ); | ||
| 45 | pub static ref MSG4_KEY: MessageKey = ( | ||
| 46 | OriginServer(UInt::new(2).unwrap()), | ||
| 47 | event_id!("$JP6qFV7WyXk5ZnexM3:example.com").to_owned() | ||
| 48 | ); | ||
| 49 | pub static ref MSG5_KEY: MessageKey = | ||
| 50 | (OriginServer(UInt::new(8).unwrap()), EventId::new(server_name!("example.com"))); | ||
| 51 | } | ||
| 52 | |||
| 53 | pub fn mock_message1() -> Message { | ||
| 54 | let content = RoomMessageEventContent::text_plain("writhe"); | ||
| 55 | let content = MessageContent::Original(content.into()); | ||
| 56 | |||
| 57 | Message::new(content, TEST_USER1.clone(), MSG1_KEY.0) | ||
| 58 | } | ||
| 59 | |||
| 60 | pub fn mock_message2() -> Message { | ||
| 61 | let content = RoomMessageEventContent::text_plain("helium"); | ||
| 62 | let content = MessageContent::Original(content.into()); | ||
| 63 | |||
| 64 | Message::new(content, TEST_USER2.clone(), MSG2_KEY.0) | ||
| 65 | } | ||
| 66 | |||
| 67 | pub fn mock_message3() -> Message { | ||
| 68 | let content = RoomMessageEventContent::text_plain("this\nis\na\nmultiline\nmessage"); | ||
| 69 | let content = MessageContent::Original(content.into()); | ||
| 70 | |||
| 71 | Message::new(content, TEST_USER2.clone(), MSG3_KEY.0) | ||
| 72 | } | ||
| 73 | |||
| 74 | pub fn mock_message4() -> Message { | ||
| 75 | let content = RoomMessageEventContent::text_plain("help"); | ||
| 76 | let content = MessageContent::Original(content.into()); | ||
| 77 | |||
| 78 | Message::new(content, TEST_USER1.clone(), MSG4_KEY.0) | ||
| 79 | } | ||
| 80 | |||
| 81 | pub fn mock_message5() -> Message { | ||
| 82 | let content = RoomMessageEventContent::text_plain("character"); | ||
| 83 | let content = MessageContent::Original(content.into()); | ||
| 84 | |||
| 85 | Message::new(content, TEST_USER2.clone(), MSG5_KEY.0) | ||
| 86 | } | ||
| 87 | |||
| 88 | pub fn mock_messages() -> Messages { | ||
| 89 | let mut messages = BTreeMap::new(); | ||
| 90 | |||
| 91 | messages.insert(MSG1_KEY.clone(), mock_message1()); | ||
| 92 | messages.insert(MSG2_KEY.clone(), mock_message2()); | ||
| 93 | messages.insert(MSG3_KEY.clone(), mock_message3()); | ||
| 94 | messages.insert(MSG4_KEY.clone(), mock_message4()); | ||
| 95 | messages.insert(MSG5_KEY.clone(), mock_message5()); | ||
| 96 | |||
| 97 | messages | ||
| 98 | } | ||
| 99 | |||
| 100 | pub fn mock_room() -> RoomInfo { | ||
| 101 | RoomInfo { | ||
| 102 | name: Some("Watercooler Discussion".into()), | ||
| 103 | messages: mock_messages(), | ||
| 104 | fetch_id: RoomFetchStatus::NotStarted, | ||
| 105 | fetch_last: None, | ||
| 106 | } | ||
| 107 | } | ||
| 108 | |||
| 109 | pub fn mock_settings() -> ApplicationSettings { | ||
| 110 | ApplicationSettings { | ||
| 111 | matrix_dir: PathBuf::new(), | ||
| 112 | cache_dir: PathBuf::new(), | ||
| 113 | session_json: PathBuf::new(), | ||
| 114 | profile_name: "test".into(), | ||
| 115 | profile: ProfileConfig { | ||
| 116 | user_id: user_id!("@user:example.com").to_owned(), | ||
| 117 | url: Url::parse("https://example.com").unwrap(), | ||
| 118 | }, | ||
| 119 | } | ||
| 120 | } | ||
| 121 | |||
| 122 | pub fn mock_store() -> ProgramStore { | ||
| 123 | let (tx, _) = sync_channel(5); | ||
| 124 | let worker = Requester { tx }; | ||
| 125 | |||
| 126 | let mut store = ChatStore::new(worker, mock_settings()); | ||
| 127 | let room_id = TEST_ROOM1_ID.clone(); | ||
| 128 | let info = mock_room(); | ||
| 129 | |||
| 130 | store.rooms.insert(room_id, info); | ||
| 131 | |||
| 132 | ProgramStore::new(store) | ||
| 133 | } | ||
src/windows/mod.rs added +696
| @@ -0,0 +1,696 @@ | |||
| 1 | use std::cmp::{Ord, Ordering, PartialOrd}; | ||
| 2 | use std::collections::hash_map::Entry; | ||
| 3 | |||
| 4 | use matrix_sdk::{ | ||
| 5 | encryption::verification::{format_emojis, SasVerification}, | ||
| 6 | room::Room as MatrixRoom, | ||
| 7 | ruma::RoomId, | ||
| 8 | DisplayName, | ||
| 9 | }; | ||
| 10 | |||
| 11 | use modalkit::tui::{ | ||
| 12 | buffer::Buffer, | ||
| 13 | layout::Rect, | ||
| 14 | style::{Modifier as StyleModifier, Style}, | ||
| 15 | text::{Span, Spans, Text}, | ||
| 16 | widgets::{Block, Borders, Widget}, | ||
| 17 | }; | ||
| 18 | |||
| 19 | use modalkit::{ | ||
| 20 | editing::{ | ||
| 21 | action::{ | ||
| 22 | EditError, | ||
| 23 | EditInfo, | ||
| 24 | EditResult, | ||
| 25 | Editable, | ||
| 26 | EditorAction, | ||
| 27 | Jumpable, | ||
| 28 | PromptAction, | ||
| 29 | Promptable, | ||
| 30 | Scrollable, | ||
| 31 | UIError, | ||
| 32 | WindowAction, | ||
| 33 | }, | ||
| 34 | base::{ | ||
| 35 | CloseFlags, | ||
| 36 | MoveDir1D, | ||
| 37 | OpenTarget, | ||
| 38 | PositionList, | ||
| 39 | ScrollStyle, | ||
| 40 | ViewportContext, | ||
| 41 | WordStyle, | ||
| 42 | }, | ||
| 43 | }, | ||
| 44 | widgets::{ | ||
| 45 | list::{ListCursor, ListItem, ListState}, | ||
| 46 | TermOffset, | ||
| 47 | TerminalCursor, | ||
| 48 | Window, | ||
| 49 | WindowOps, | ||
| 50 | }, | ||
| 51 | }; | ||
| 52 | |||
| 53 | use super::base::{ | ||
| 54 | ChatStore, | ||
| 55 | IambBufferId, | ||
| 56 | IambId, | ||
| 57 | IambInfo, | ||
| 58 | IambResult, | ||
| 59 | ProgramAction, | ||
| 60 | ProgramContext, | ||
| 61 | ProgramStore, | ||
| 62 | }; | ||
| 63 | |||
| 64 | use self::{room::RoomState, welcome::WelcomeState}; | ||
| 65 | |||
| 66 | pub mod room; | ||
| 67 | pub mod welcome; | ||
| 68 | |||
| 69 | #[inline] | ||
| 70 | fn selected_style(selected: bool) -> Style { | ||
| 71 | if selected { | ||
| 72 | Style::default().add_modifier(StyleModifier::REVERSED) | ||
| 73 | } else { | ||
| 74 | Style::default() | ||
| 75 | } | ||
| 76 | } | ||
| 77 | |||
| 78 | #[inline] | ||
| 79 | fn selected_span(s: &str, selected: bool) -> Span { | ||
| 80 | Span::styled(s, selected_style(selected)) | ||
| 81 | } | ||
| 82 | |||
| 83 | #[inline] | ||
| 84 | fn selected_text(s: &str, selected: bool) -> Text { | ||
| 85 | Text::from(selected_span(s, selected)) | ||
| 86 | } | ||
| 87 | |||
| 88 | #[inline] | ||
| 89 | fn room_prompt( | ||
| 90 | room_id: &RoomId, | ||
| 91 | act: &PromptAction, | ||
| 92 | ctx: &ProgramContext, | ||
| 93 | ) -> EditResult<Vec<(ProgramAction, ProgramContext)>, IambInfo> { | ||
| 94 | match act { | ||
| 95 | PromptAction::Submit => { | ||
| 96 | let room = IambId::Room(room_id.to_owned()); | ||
| 97 | let open = WindowAction::Switch(OpenTarget::Application(room)); | ||
| 98 | let acts = vec![(open.into(), ctx.clone())]; | ||
| 99 | |||
| 100 | Ok(acts) | ||
| 101 | }, | ||
| 102 | PromptAction::Abort(_) => { | ||
| 103 | let msg = "Cannot abort entry inside a list"; | ||
| 104 | let err = EditError::Failure(msg.into()); | ||
| 105 | |||
| 106 | Err(err) | ||
| 107 | }, | ||
| 108 | PromptAction::Recall(_, _) => { | ||
| 109 | let msg = "Cannot recall history inside a list"; | ||
| 110 | let err = EditError::Failure(msg.into()); | ||
| 111 | |||
| 112 | Err(err) | ||
| 113 | }, | ||
| 114 | _ => Err(EditError::Unimplemented("unknown prompt action".to_string())), | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | macro_rules! delegate { | ||
| 119 | ($s: expr, $id: ident => $e: expr) => { | ||
| 120 | match $s { | ||
| 121 | IambWindow::Room($id) => $e, | ||
| 122 | IambWindow::DirectList($id) => $e, | ||
| 123 | IambWindow::RoomList($id) => $e, | ||
| 124 | IambWindow::SpaceList($id) => $e, | ||
| 125 | IambWindow::VerifyList($id) => $e, | ||
| 126 | IambWindow::Welcome($id) => $e, | ||
| 127 | } | ||
| 128 | }; | ||
| 129 | } | ||
| 130 | |||
| 131 | pub enum IambWindow { | ||
| 132 | DirectList(DirectListState), | ||
| 133 | Room(RoomState), | ||
| 134 | VerifyList(VerifyListState), | ||
| 135 | RoomList(RoomListState), | ||
| 136 | SpaceList(SpaceListState), | ||
| 137 | Welcome(WelcomeState), | ||
| 138 | } | ||
| 139 | |||
| 140 | impl IambWindow { | ||
| 141 | pub fn focus_toggle(&mut self) { | ||
| 142 | if let IambWindow::Room(w) = self { | ||
| 143 | w.focus_toggle() | ||
| 144 | } else { | ||
| 145 | return; | ||
| 146 | } | ||
| 147 | } | ||
| 148 | |||
| 149 | pub fn get_title(&self, store: &mut ProgramStore) -> String { | ||
| 150 | match self { | ||
| 151 | IambWindow::Room(w) => w.get_title(store), | ||
| 152 | IambWindow::DirectList(_) => "Direct Messages".to_string(), | ||
| 153 | IambWindow::RoomList(_) => "Rooms".to_string(), | ||
| 154 | IambWindow::SpaceList(_) => "Spaces".to_string(), | ||
| 155 | IambWindow::VerifyList(_) => "Verifications".to_string(), | ||
| 156 | IambWindow::Welcome(_) => "Welcome to iamb".to_string(), | ||
| 157 | } | ||
| 158 | } | ||
| 159 | } | ||
| 160 | |||
| 161 | pub type DirectListState = ListState<DirectItem, IambInfo>; | ||
| 162 | pub type RoomListState = ListState<RoomItem, IambInfo>; | ||
| 163 | pub type SpaceListState = ListState<SpaceItem, IambInfo>; | ||
| 164 | pub type VerifyListState = ListState<VerifyItem, IambInfo>; | ||
| 165 | |||
| 166 | impl From<RoomState> for IambWindow { | ||
| 167 | fn from(room: RoomState) -> Self { | ||
| 168 | IambWindow::Room(room) | ||
| 169 | } | ||
| 170 | } | ||
| 171 | |||
| 172 | impl From<VerifyListState> for IambWindow { | ||
| 173 | fn from(list: VerifyListState) -> Self { | ||
| 174 | IambWindow::VerifyList(list) | ||
| 175 | } | ||
| 176 | } | ||
| 177 | |||
| 178 | impl From<DirectListState> for IambWindow { | ||
| 179 | fn from(list: DirectListState) -> Self { | ||
| 180 | IambWindow::DirectList(list) | ||
| 181 | } | ||
| 182 | } | ||
| 183 | |||
| 184 | impl From<RoomListState> for IambWindow { | ||
| 185 | fn from(list: RoomListState) -> Self { | ||
| 186 | IambWindow::RoomList(list) | ||
| 187 | } | ||
| 188 | } | ||
| 189 | |||
| 190 | impl From<SpaceListState> for IambWindow { | ||
| 191 | fn from(list: SpaceListState) -> Self { | ||
| 192 | IambWindow::SpaceList(list) | ||
| 193 | } | ||
| 194 | } | ||
| 195 | |||
| 196 | impl From<WelcomeState> for IambWindow { | ||
| 197 | fn from(win: WelcomeState) -> Self { | ||
| 198 | IambWindow::Welcome(win) | ||
| 199 | } | ||
| 200 | } | ||
| 201 | |||
| 202 | impl Editable<ProgramContext, ProgramStore, IambInfo> for IambWindow { | ||
| 203 | fn editor_command( | ||
| 204 | &mut self, | ||
| 205 | act: &EditorAction, | ||
| 206 | ctx: &ProgramContext, | ||
| 207 | store: &mut ProgramStore, | ||
| 208 | ) -> EditResult<EditInfo, IambInfo> { | ||
| 209 | delegate!(self, w => w.editor_command(act, ctx, store)) | ||
| 210 | } | ||
| 211 | } | ||
| 212 | |||
| 213 | impl Jumpable<ProgramContext, IambInfo> for IambWindow { | ||
| 214 | fn jump( | ||
| 215 | &mut self, | ||
| 216 | list: PositionList, | ||
| 217 | dir: MoveDir1D, | ||
| 218 | count: usize, | ||
| 219 | ctx: &ProgramContext, | ||
| 220 | ) -> IambResult<usize> { | ||
| 221 | delegate!(self, w => w.jump(list, dir, count, ctx)) | ||
| 222 | } | ||
| 223 | } | ||
| 224 | |||
| 225 | impl Scrollable<ProgramContext, ProgramStore, IambInfo> for IambWindow { | ||
| 226 | fn scroll( | ||
| 227 | &mut self, | ||
| 228 | style: &ScrollStyle, | ||
| 229 | ctx: &ProgramContext, | ||
| 230 | store: &mut ProgramStore, | ||
| 231 | ) -> EditResult<EditInfo, IambInfo> { | ||
| 232 | delegate!(self, w => w.scroll(style, ctx, store)) | ||
| 233 | } | ||
| 234 | } | ||
| 235 | |||
| 236 | impl Promptable<ProgramContext, ProgramStore, IambInfo> for IambWindow { | ||
| 237 | fn prompt( | ||
| 238 | &mut self, | ||
| 239 | act: &PromptAction, | ||
| 240 | ctx: &ProgramContext, | ||
| 241 | store: &mut ProgramStore, | ||
| 242 | ) -> EditResult<Vec<(ProgramAction, ProgramContext)>, IambInfo> { | ||
| 243 | delegate!(self, w => w.prompt(act, ctx, store)) | ||
| 244 | } | ||
| 245 | } | ||
| 246 | |||
| 247 | impl TerminalCursor for IambWindow { | ||
| 248 | fn get_term_cursor(&self) -> Option<TermOffset> { | ||
| 249 | delegate!(self, w => w.get_term_cursor()) | ||
| 250 | } | ||
| 251 | } | ||
| 252 | |||
| 253 | impl WindowOps<IambInfo> for IambWindow { | ||
| 254 | fn draw(&mut self, area: Rect, buf: &mut Buffer, focused: bool, store: &mut ProgramStore) { | ||
| 255 | let title = self.get_title(store); | ||
| 256 | let block = Block::default().title(title.as_str()).borders(Borders::ALL); | ||
| 257 | let inner = block.inner(area); | ||
| 258 | block.render(area, buf); | ||
| 259 | |||
| 260 | match self { | ||
| 261 | IambWindow::Room(state) => state.draw(inner, buf, focused, store), | ||
| 262 | IambWindow::DirectList(state) => { | ||
| 263 | let dms = store.application.worker.direct_messages(); | ||
| 264 | let items = dms.into_iter().map(|(id, name)| DirectItem::new(id, name, store)); | ||
| 265 | state.set(items.collect()); | ||
| 266 | state.draw(inner, buf, focused, store); | ||
| 267 | }, | ||
| 268 | IambWindow::RoomList(state) => { | ||
| 269 | let joined = store.application.worker.joined_rooms(); | ||
| 270 | let items = joined.into_iter().map(|(id, name)| RoomItem::new(id, name, store)); | ||
| 271 | state.set(items.collect()); | ||
| 272 | state.draw(inner, buf, focused, store); | ||
| 273 | }, | ||
| 274 | IambWindow::SpaceList(state) => { | ||
| 275 | let spaces = store.application.worker.spaces(); | ||
| 276 | let items = | ||
| 277 | spaces.into_iter().map(|(room, name)| SpaceItem::new(room, name, store)); | ||
| 278 | state.set(items.collect()); | ||
| 279 | state.draw(inner, buf, focused, store); | ||
| 280 | }, | ||
| 281 | IambWindow::VerifyList(state) => { | ||
| 282 | let verifications = &store.application.verifications; | ||
| 283 | let mut items = verifications.iter().map(VerifyItem::from).collect::<Vec<_>>(); | ||
| 284 | |||
| 285 | // Sort the active verifications towards the top. | ||
| 286 | items.sort(); | ||
| 287 | |||
| 288 | state.set(items); | ||
| 289 | state.draw(inner, buf, focused, store); | ||
| 290 | }, | ||
| 291 | IambWindow::Welcome(state) => state.draw(inner, buf, focused, store), | ||
| 292 | } | ||
| 293 | } | ||
| 294 | |||
| 295 | fn dup(&self, store: &mut ProgramStore) -> Self { | ||
| 296 | delegate!(self, w => w.dup(store).into()) | ||
| 297 | } | ||
| 298 | |||
| 299 | fn close(&mut self, flags: CloseFlags, store: &mut ProgramStore) -> bool { | ||
| 300 | delegate!(self, w => w.close(flags, store)) | ||
| 301 | } | ||
| 302 | |||
| 303 | fn get_cursor_word(&self, style: &WordStyle) -> Option<String> { | ||
| 304 | delegate!(self, w => w.get_cursor_word(style)) | ||
| 305 | } | ||
| 306 | |||
| 307 | fn get_selected_word(&self) -> Option<String> { | ||
| 308 | delegate!(self, w => w.get_selected_word()) | ||
| 309 | } | ||
| 310 | } | ||
| 311 | |||
| 312 | impl Window<IambInfo> for IambWindow { | ||
| 313 | fn id(&self) -> IambId { | ||
| 314 | match self { | ||
| 315 | IambWindow::Room(room) => IambId::Room(room.id().to_owned()), | ||
| 316 | IambWindow::DirectList(_) => IambId::DirectList, | ||
| 317 | IambWindow::RoomList(_) => IambId::RoomList, | ||
| 318 | IambWindow::SpaceList(_) => IambId::SpaceList, | ||
| 319 | IambWindow::VerifyList(_) => IambId::VerifyList, | ||
| 320 | IambWindow::Welcome(_) => IambId::Welcome, | ||
| 321 | } | ||
| 322 | } | ||
| 323 | |||
| 324 | fn open(id: IambId, store: &mut ProgramStore) -> IambResult<Self> { | ||
| 325 | match id { | ||
| 326 | IambId::Room(room_id) => { | ||
| 327 | let (room, name) = store.application.worker.get_room(room_id)?; | ||
| 328 | let room = RoomState::new(room, name, store); | ||
| 329 | |||
| 330 | return Ok(room.into()); | ||
| 331 | }, | ||
| 332 | IambId::DirectList => { | ||
| 333 | let list = DirectListState::new(IambBufferId::DirectList, vec![]); | ||
| 334 | |||
| 335 | return Ok(list.into()); | ||
| 336 | }, | ||
| 337 | IambId::RoomList => { | ||
| 338 | let list = RoomListState::new(IambBufferId::RoomList, vec![]); | ||
| 339 | |||
| 340 | return Ok(list.into()); | ||
| 341 | }, | ||
| 342 | IambId::SpaceList => { | ||
| 343 | let list = SpaceListState::new(IambBufferId::SpaceList, vec![]); | ||
| 344 | |||
| 345 | return Ok(list.into()); | ||
| 346 | }, | ||
| 347 | IambId::VerifyList => { | ||
| 348 | let list = VerifyListState::new(IambBufferId::VerifyList, vec![]); | ||
| 349 | |||
| 350 | return Ok(list.into()); | ||
| 351 | }, | ||
| 352 | IambId::Welcome => { | ||
| 353 | let win = WelcomeState::new(store); | ||
| 354 | |||
| 355 | return Ok(win.into()); | ||
| 356 | }, | ||
| 357 | } | ||
| 358 | } | ||
| 359 | |||
| 360 | fn find(name: String, store: &mut ProgramStore) -> IambResult<Self> { | ||
| 361 | let ChatStore { names, worker, .. } = &mut store.application; | ||
| 362 | |||
| 363 | match names.entry(name) { | ||
| 364 | Entry::Vacant(v) => { | ||
| 365 | let room_id = worker.join_room(v.key().to_string())?; | ||
| 366 | v.insert(room_id.clone()); | ||
| 367 | |||
| 368 | let (room, name) = store.application.worker.get_room(room_id)?; | ||
| 369 | let room = RoomState::new(room, name, store); | ||
| 370 | |||
| 371 | Ok(room.into()) | ||
| 372 | }, | ||
| 373 | Entry::Occupied(o) => { | ||
| 374 | let id = IambId::Room(o.get().clone()); | ||
| 375 | |||
| 376 | IambWindow::open(id, store) | ||
| 377 | }, | ||
| 378 | } | ||
| 379 | } | ||
| 380 | |||
| 381 | fn posn(index: usize, _: &mut ProgramStore) -> IambResult<Self> { | ||
| 382 | let msg = format!("Cannot find indexed buffer (index = {})", index); | ||
| 383 | let err = UIError::Unimplemented(msg); | ||
| 384 | |||
| 385 | Err(err) | ||
| 386 | } | ||
| 387 | } | ||
| 388 | |||
| 389 | #[derive(Clone)] | ||
| 390 | pub struct RoomItem { | ||
| 391 | room: MatrixRoom, | ||
| 392 | name: String, | ||
| 393 | } | ||
| 394 | |||
| 395 | impl RoomItem { | ||
| 396 | fn new(room: MatrixRoom, name: DisplayName, store: &mut ProgramStore) -> Self { | ||
| 397 | let name = name.to_string(); | ||
| 398 | |||
| 399 | store.application.set_room_name(room.room_id(), name.as_str()); | ||
| 400 | |||
| 401 | RoomItem { room, name } | ||
| 402 | } | ||
| 403 | } | ||
| 404 | |||
| 405 | impl ToString for RoomItem { | ||
| 406 | fn to_string(&self) -> String { | ||
| 407 | return self.name.clone(); | ||
| 408 | } | ||
| 409 | } | ||
| 410 | |||
| 411 | impl ListItem<IambInfo> for RoomItem { | ||
| 412 | fn show(&self, selected: bool, _: &ViewportContext<ListCursor>, _: &mut ProgramStore) -> Text { | ||
| 413 | selected_text(self.name.as_str(), selected) | ||
| 414 | } | ||
| 415 | } | ||
| 416 | |||
| 417 | impl Promptable<ProgramContext, ProgramStore, IambInfo> for RoomItem { | ||
| 418 | fn prompt( | ||
| 419 | &mut self, | ||
| 420 | act: &PromptAction, | ||
| 421 | ctx: &ProgramContext, | ||
| 422 | _: &mut ProgramStore, | ||
| 423 | ) -> EditResult<Vec<(ProgramAction, ProgramContext)>, IambInfo> { | ||
| 424 | room_prompt(self.room.room_id(), act, ctx) | ||
| 425 | } | ||
| 426 | } | ||
| 427 | |||
| 428 | #[derive(Clone)] | ||
| 429 | pub struct DirectItem { | ||
| 430 | room: MatrixRoom, | ||
| 431 | name: String, | ||
| 432 | } | ||
| 433 | |||
| 434 | impl DirectItem { | ||
| 435 | fn new(room: MatrixRoom, name: DisplayName, store: &mut ProgramStore) -> Self { | ||
| 436 | let name = name.to_string(); | ||
| 437 | |||
| 438 | store.application.set_room_name(room.room_id(), name.as_str()); | ||
| 439 | |||
| 440 | DirectItem { room, name } | ||
| 441 | } | ||
| 442 | } | ||
| 443 | |||
| 444 | impl ToString for DirectItem { | ||
| 445 | fn to_string(&self) -> String { | ||
| 446 | return self.name.clone(); | ||
| 447 | } | ||
| 448 | } | ||
| 449 | |||
| 450 | impl ListItem<IambInfo> for DirectItem { | ||
| 451 | fn show(&self, selected: bool, _: &ViewportContext<ListCursor>, _: &mut ProgramStore) -> Text { | ||
| 452 | selected_text(self.name.as_str(), selected) | ||
| 453 | } | ||
| 454 | } | ||
| 455 | |||
| 456 | impl Promptable<ProgramContext, ProgramStore, IambInfo> for DirectItem { | ||
| 457 | fn prompt( | ||
| 458 | &mut self, | ||
| 459 | act: &PromptAction, | ||
| 460 | ctx: &ProgramContext, | ||
| 461 | _: &mut ProgramStore, | ||
| 462 | ) -> EditResult<Vec<(ProgramAction, ProgramContext)>, IambInfo> { | ||
| 463 | room_prompt(self.room.room_id(), act, ctx) | ||
| 464 | } | ||
| 465 | } | ||
| 466 | |||
| 467 | #[derive(Clone)] | ||
| 468 | pub struct SpaceItem { | ||
| 469 | room: MatrixRoom, | ||
| 470 | name: String, | ||
| 471 | } | ||
| 472 | |||
| 473 | impl SpaceItem { | ||
| 474 | fn new(room: MatrixRoom, name: DisplayName, store: &mut ProgramStore) -> Self { | ||
| 475 | let name = name.to_string(); | ||
| 476 | |||
| 477 | store.application.set_room_name(room.room_id(), name.as_str()); | ||
| 478 | |||
| 479 | SpaceItem { room, name } | ||
| 480 | } | ||
| 481 | } | ||
| 482 | |||
| 483 | impl ToString for SpaceItem { | ||
| 484 | fn to_string(&self) -> String { | ||
| 485 | return self.room.room_id().to_string(); | ||
| 486 | } | ||
| 487 | } | ||
| 488 | |||
| 489 | impl ListItem<IambInfo> for SpaceItem { | ||
| 490 | fn show(&self, selected: bool, _: &ViewportContext<ListCursor>, _: &mut ProgramStore) -> Text { | ||
| 491 | selected_text(self.name.as_str(), selected) | ||
| 492 | } | ||
| 493 | } | ||
| 494 | |||
| 495 | impl Promptable<ProgramContext, ProgramStore, IambInfo> for SpaceItem { | ||
| 496 | fn prompt( | ||
| 497 | &mut self, | ||
| 498 | act: &PromptAction, | ||
| 499 | ctx: &ProgramContext, | ||
| 500 | _: &mut ProgramStore, | ||
| 501 | ) -> EditResult<Vec<(ProgramAction, ProgramContext)>, IambInfo> { | ||
| 502 | room_prompt(self.room.room_id(), act, ctx) | ||
| 503 | } | ||
| 504 | } | ||
| 505 | |||
| 506 | #[derive(Clone)] | ||
| 507 | pub struct VerifyItem { | ||
| 508 | user_dev: String, | ||
| 509 | sasv1: SasVerification, | ||
| 510 | } | ||
| 511 | |||
| 512 | impl VerifyItem { | ||
| 513 | fn new(user_dev: String, sasv1: SasVerification) -> Self { | ||
| 514 | VerifyItem { user_dev, sasv1 } | ||
| 515 | } | ||
| 516 | |||
| 517 | fn show_item(&self) -> String { | ||
| 518 | let state = if self.sasv1.is_done() { | ||
| 519 | "done" | ||
| 520 | } else if self.sasv1.is_cancelled() { | ||
| 521 | "cancelled" | ||
| 522 | } else if self.sasv1.emoji().is_some() { | ||
| 523 | "accepted" | ||
| 524 | } else { | ||
| 525 | "not accepted" | ||
| 526 | }; | ||
| 527 | |||
| 528 | if self.sasv1.is_self_verification() { | ||
| 529 | let device = self.sasv1.other_device(); | ||
| 530 | |||
| 531 | if let Some(display_name) = device.display_name() { | ||
| 532 | format!("Device verification with {} ({})", display_name, state) | ||
| 533 | } else { | ||
| 534 | format!("Device verification with device {} ({})", device.device_id(), state) | ||
| 535 | } | ||
| 536 | } else { | ||
| 537 | format!("User Verification with {} ({})", self.sasv1.other_user_id(), state) | ||
| 538 | } | ||
| 539 | } | ||
| 540 | } | ||
| 541 | |||
| 542 | impl PartialEq for VerifyItem { | ||
| 543 | fn eq(&self, other: &Self) -> bool { | ||
| 544 | self.user_dev == other.user_dev | ||
| 545 | } | ||
| 546 | } | ||
| 547 | |||
| 548 | impl Eq for VerifyItem {} | ||
| 549 | |||
| 550 | impl Ord for VerifyItem { | ||
| 551 | fn cmp(&self, other: &Self) -> Ordering { | ||
| 552 | fn state_val(sas: &SasVerification) -> usize { | ||
| 553 | if sas.is_done() { | ||
| 554 | return 3; | ||
| 555 | } else if sas.is_cancelled() { | ||
| 556 | return 2; | ||
| 557 | } else { | ||
| 558 | return 1; | ||
| 559 | } | ||
| 560 | } | ||
| 561 | |||
| 562 | fn device_val(sas: &SasVerification) -> usize { | ||
| 563 | if sas.is_self_verification() { | ||
| 564 | return 1; | ||
| 565 | } else { | ||
| 566 | return 2; | ||
| 567 | } | ||
| 568 | } | ||
| 569 | |||
| 570 | let state1 = state_val(&self.sasv1); | ||
| 571 | let state2 = state_val(&other.sasv1); | ||
| 572 | |||
| 573 | let dev1 = device_val(&self.sasv1); | ||
| 574 | let dev2 = device_val(&other.sasv1); | ||
| 575 | |||
| 576 | let scmp = state1.cmp(&state2); | ||
| 577 | let dcmp = dev1.cmp(&dev2); | ||
| 578 | |||
| 579 | scmp.then(dcmp).then_with(|| { | ||
| 580 | let did1 = self.sasv1.other_device().device_id(); | ||
| 581 | let did2 = other.sasv1.other_device().device_id(); | ||
| 582 | |||
| 583 | did1.cmp(did2) | ||
| 584 | }) | ||
| 585 | } | ||
| 586 | } | ||
| 587 | |||
| 588 | impl PartialOrd for VerifyItem { | ||
| 589 | fn partial_cmp(&self, other: &Self) -> Option<Ordering> { | ||
| 590 | self.cmp(other).into() | ||
| 591 | } | ||
| 592 | } | ||
| 593 | |||
| 594 | impl From<(&String, &SasVerification)> for VerifyItem { | ||
| 595 | fn from((user_dev, sasv1): (&String, &SasVerification)) -> Self { | ||
| 596 | VerifyItem::new(user_dev.clone(), sasv1.clone()) | ||
| 597 | } | ||
| 598 | } | ||
| 599 | |||
| 600 | impl ToString for VerifyItem { | ||
| 601 | fn to_string(&self) -> String { | ||
| 602 | if self.sasv1.is_done() { | ||
| 603 | String::new() | ||
| 604 | } else if self.sasv1.is_cancelled() { | ||
| 605 | format!(":verify request {}", self.sasv1.other_user_id()) | ||
| 606 | } else if self.sasv1.emoji().is_some() { | ||
| 607 | format!(":verify confirm {}", self.user_dev) | ||
| 608 | } else { | ||
| 609 | format!(":verify accept {}", self.user_dev) | ||
| 610 | } | ||
| 611 | } | ||
| 612 | } | ||
| 613 | |||
| 614 | impl ListItem<IambInfo> for VerifyItem { | ||
| 615 | fn show(&self, selected: bool, _: &ViewportContext<ListCursor>, _: &mut ProgramStore) -> Text { | ||
| 616 | let mut lines = vec![]; | ||
| 617 | |||
| 618 | let bold = Style::default().add_modifier(StyleModifier::BOLD); | ||
| 619 | let item = Span::styled(self.show_item(), selected_style(selected)); | ||
| 620 | lines.push(Spans::from(item)); | ||
| 621 | |||
| 622 | if self.sasv1.is_done() { | ||
| 623 | // Print nothing. | ||
| 624 | } else if self.sasv1.is_cancelled() { | ||
| 625 | if let Some(info) = self.sasv1.cancel_info() { | ||
| 626 | lines.push(Spans::from(format!(" Cancelled: {}", info.reason()))); | ||
| 627 | lines.push(Spans::from("")); | ||
| 628 | } | ||
| 629 | |||
| 630 | lines.push(Spans::from(" You can start a new verification request with:")); | ||
| 631 | } else if let Some(emoji) = self.sasv1.emoji() { | ||
| 632 | lines.push(Spans::from( | ||
| 633 | " Both devices should see the following Emoji sequence:".to_string(), | ||
| 634 | )); | ||
| 635 | lines.push(Spans::from("")); | ||
| 636 | |||
| 637 | for line in format_emojis(emoji).lines() { | ||
| 638 | lines.push(Spans::from(format!(" {}", line))); | ||
| 639 | } | ||
| 640 | |||
| 641 | lines.push(Spans::from("")); | ||
| 642 | lines.push(Spans::from(" If they don't match, run:")); | ||
| 643 | lines.push(Spans::from("")); | ||
| 644 | lines.push(Spans::from(Span::styled( | ||
| 645 | format!(":verify mismatch {}", self.user_dev), | ||
| 646 | bold, | ||
| 647 | ))); | ||
| 648 | lines.push(Spans::from("")); | ||
| 649 | lines.push(Spans::from(" If everything looks right, you can confirm with:")); | ||
| 650 | } else { | ||
| 651 | lines.push(Spans::from(" To accept this request, run:")); | ||
| 652 | } | ||
| 653 | |||
| 654 | let cmd = self.to_string(); | ||
| 655 | |||
| 656 | if !cmd.is_empty() { | ||
| 657 | lines.push(Spans::from("")); | ||
| 658 | lines.push(Spans(vec![Span::from(" "), Span::styled(cmd, bold)])); | ||
| 659 | lines.push(Spans::from("")); | ||
| 660 | lines.push(Spans(vec![ | ||
| 661 | Span::from("You can copy the above command with "), | ||
| 662 | Span::styled("yy", bold), | ||
| 663 | Span::from(" and then execute it with "), | ||
| 664 | Span::styled("@\"", bold), | ||
| 665 | ])); | ||
| 666 | } | ||
| 667 | |||
| 668 | Text { lines } | ||
| 669 | } | ||
| 670 | } | ||
| 671 | |||
| 672 | impl Promptable<ProgramContext, ProgramStore, IambInfo> for VerifyItem { | ||
| 673 | fn prompt( | ||
| 674 | &mut self, | ||
| 675 | act: &PromptAction, | ||
| 676 | _: &ProgramContext, | ||
| 677 | _: &mut ProgramStore, | ||
| 678 | ) -> EditResult<Vec<(ProgramAction, ProgramContext)>, IambInfo> { | ||
| 679 | match act { | ||
| 680 | PromptAction::Submit => Ok(vec![]), | ||
| 681 | PromptAction::Abort(_) => { | ||
| 682 | let msg = "Cannot abort entry inside a list"; | ||
| 683 | let err = EditError::Failure(msg.into()); | ||
| 684 | |||
| 685 | Err(err) | ||
| 686 | }, | ||
| 687 | PromptAction::Recall(_, _) => { | ||
| 688 | let msg = "Cannot recall history inside a list"; | ||
| 689 | let err = EditError::Failure(msg.into()); | ||
| 690 | |||
| 691 | Err(err) | ||
| 692 | }, | ||
| 693 | _ => Err(EditError::Unimplemented("unknown prompt action".to_string())), | ||
| 694 | } | ||
| 695 | } | ||
| 696 | } | ||
src/windows/room/chat.rs added +319
| @@ -0,0 +1,319 @@ | |||
| 1 | use matrix_sdk::{ | ||
| 2 | room::Room as MatrixRoom, | ||
| 3 | ruma::{OwnedRoomId, RoomId}, | ||
| 4 | }; | ||
| 5 | |||
| 6 | use modalkit::tui::{buffer::Buffer, layout::Rect, widgets::StatefulWidget}; | ||
| 7 | |||
| 8 | use modalkit::{ | ||
| 9 | widgets::textbox::{TextBox, TextBoxState}, | ||
| 10 | widgets::TerminalCursor, | ||
| 11 | widgets::{PromptActions, WindowOps}, | ||
| 12 | }; | ||
| 13 | |||
| 14 | use modalkit::editing::{ | ||
| 15 | action::{ | ||
| 16 | EditError, | ||
| 17 | EditInfo, | ||
| 18 | EditResult, | ||
| 19 | Editable, | ||
| 20 | EditorAction, | ||
| 21 | Jumpable, | ||
| 22 | PromptAction, | ||
| 23 | Promptable, | ||
| 24 | Scrollable, | ||
| 25 | }, | ||
| 26 | base::{CloseFlags, Count, MoveDir1D, PositionList, ScrollStyle, WordStyle}, | ||
| 27 | context::Resolve, | ||
| 28 | history::{self, HistoryList}, | ||
| 29 | rope::EditRope, | ||
| 30 | }; | ||
| 31 | |||
| 32 | use crate::base::{ | ||
| 33 | IambAction, | ||
| 34 | IambBufferId, | ||
| 35 | IambInfo, | ||
| 36 | IambResult, | ||
| 37 | ProgramAction, | ||
| 38 | ProgramContext, | ||
| 39 | ProgramStore, | ||
| 40 | RoomFocus, | ||
| 41 | }; | ||
| 42 | |||
| 43 | use super::scrollback::{Scrollback, ScrollbackState}; | ||
| 44 | |||
| 45 | pub struct ChatState { | ||
| 46 | room_id: OwnedRoomId, | ||
| 47 | |||
| 48 | tbox: TextBoxState<IambInfo>, | ||
| 49 | sent: HistoryList<EditRope>, | ||
| 50 | sent_scrollback: history::ScrollbackState, | ||
| 51 | |||
| 52 | scrollback: ScrollbackState, | ||
| 53 | focus: RoomFocus, | ||
| 54 | } | ||
| 55 | |||
| 56 | impl ChatState { | ||
| 57 | pub fn new(room: MatrixRoom, store: &mut ProgramStore) -> Self { | ||
| 58 | let room_id = room.room_id().to_owned(); | ||
| 59 | let scrollback = ScrollbackState::new(room_id.clone()); | ||
| 60 | let id = IambBufferId::Room(room_id.clone(), RoomFocus::MessageBar); | ||
| 61 | let ebuf = store.load_buffer(id); | ||
| 62 | let tbox = TextBoxState::new(ebuf); | ||
| 63 | |||
| 64 | ChatState { | ||
| 65 | room_id, | ||
| 66 | |||
| 67 | tbox, | ||
| 68 | sent: HistoryList::new(EditRope::from(""), 100), | ||
| 69 | sent_scrollback: history::ScrollbackState::Pending, | ||
| 70 | |||
| 71 | scrollback, | ||
| 72 | focus: RoomFocus::MessageBar, | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | pub fn focus_toggle(&mut self) { | ||
| 77 | self.focus = match self.focus { | ||
| 78 | RoomFocus::Scrollback => RoomFocus::MessageBar, | ||
| 79 | RoomFocus::MessageBar => RoomFocus::Scrollback, | ||
| 80 | }; | ||
| 81 | } | ||
| 82 | |||
| 83 | pub fn id(&self) -> &RoomId { | ||
| 84 | &self.room_id | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | macro_rules! delegate { | ||
| 89 | ($s: expr, $id: ident => $e: expr) => { | ||
| 90 | match $s.focus { | ||
| 91 | RoomFocus::Scrollback => { | ||
| 92 | match $s { | ||
| 93 | ChatState { scrollback: $id, .. } => $e, | ||
| 94 | } | ||
| 95 | }, | ||
| 96 | RoomFocus::MessageBar => { | ||
| 97 | match $s { | ||
| 98 | ChatState { tbox: $id, .. } => $e, | ||
| 99 | } | ||
| 100 | }, | ||
| 101 | } | ||
| 102 | }; | ||
| 103 | } | ||
| 104 | |||
| 105 | impl WindowOps<IambInfo> for ChatState { | ||
| 106 | fn draw(&mut self, area: Rect, buf: &mut Buffer, focused: bool, store: &mut ProgramStore) { | ||
| 107 | Chat::new(store).focus(focused).render(area, buf, self) | ||
| 108 | } | ||
| 109 | |||
| 110 | fn dup(&self, store: &mut ProgramStore) -> Self { | ||
| 111 | // XXX: I want each WindowSlot to have its own shared buffer, instead of each Room; need to | ||
| 112 | // find a good way to pass that info here so that it can be part of the content id. | ||
| 113 | let id = IambBufferId::Room(self.room_id.clone(), RoomFocus::MessageBar); | ||
| 114 | let ebuf = store.load_buffer(id); | ||
| 115 | let tbox = TextBoxState::new(ebuf); | ||
| 116 | |||
| 117 | ChatState { | ||
| 118 | room_id: self.room_id.clone(), | ||
| 119 | |||
| 120 | tbox, | ||
| 121 | sent: self.sent.clone(), | ||
| 122 | sent_scrollback: history::ScrollbackState::Pending, | ||
| 123 | |||
| 124 | scrollback: self.scrollback.dup(store), | ||
| 125 | focus: self.focus, | ||
| 126 | } | ||
| 127 | } | ||
| 128 | |||
| 129 | fn close(&mut self, _: CloseFlags, _: &mut ProgramStore) -> bool { | ||
| 130 | // XXX: what's the right closing behaviour for a room? | ||
| 131 | // Should write send a message? | ||
| 132 | true | ||
| 133 | } | ||
| 134 | |||
| 135 | fn get_cursor_word(&self, style: &WordStyle) -> Option<String> { | ||
| 136 | delegate!(self, w => w.get_cursor_word(style)) | ||
| 137 | } | ||
| 138 | |||
| 139 | fn get_selected_word(&self) -> Option<String> { | ||
| 140 | delegate!(self, w => w.get_selected_word()) | ||
| 141 | } | ||
| 142 | } | ||
| 143 | |||
| 144 | impl Editable<ProgramContext, ProgramStore, IambInfo> for ChatState { | ||
| 145 | fn editor_command( | ||
| 146 | &mut self, | ||
| 147 | act: &EditorAction, | ||
| 148 | ctx: &ProgramContext, | ||
| 149 | store: &mut ProgramStore, | ||
| 150 | ) -> EditResult<EditInfo, IambInfo> { | ||
| 151 | match delegate!(self, w => w.editor_command(act, ctx, store)) { | ||
| 152 | res @ Ok(_) => res, | ||
| 153 | Err(EditError::WrongBuffer(IambBufferId::Room(room_id, focus))) | ||
| 154 | if room_id == self.room_id && act.is_switchable(ctx) => | ||
| 155 | { | ||
| 156 | // Switch focus. | ||
| 157 | self.focus = focus; | ||
| 158 | |||
| 159 | // Run command again. | ||
| 160 | delegate!(self, w => w.editor_command(act, ctx, store)) | ||
| 161 | }, | ||
| 162 | res @ Err(_) => res, | ||
| 163 | } | ||
| 164 | } | ||
| 165 | } | ||
| 166 | |||
| 167 | impl TerminalCursor for ChatState { | ||
| 168 | fn get_term_cursor(&self) -> Option<(u16, u16)> { | ||
| 169 | delegate!(self, w => w.get_term_cursor()) | ||
| 170 | } | ||
| 171 | } | ||
| 172 | |||
| 173 | impl Jumpable<ProgramContext, IambInfo> for ChatState { | ||
| 174 | fn jump( | ||
| 175 | &mut self, | ||
| 176 | list: PositionList, | ||
| 177 | dir: MoveDir1D, | ||
| 178 | count: usize, | ||
| 179 | ctx: &ProgramContext, | ||
| 180 | ) -> IambResult<usize> { | ||
| 181 | delegate!(self, w => w.jump(list, dir, count, ctx)) | ||
| 182 | } | ||
| 183 | } | ||
| 184 | |||
| 185 | impl Scrollable<ProgramContext, ProgramStore, IambInfo> for ChatState { | ||
| 186 | fn scroll( | ||
| 187 | &mut self, | ||
| 188 | style: &ScrollStyle, | ||
| 189 | ctx: &ProgramContext, | ||
| 190 | store: &mut ProgramStore, | ||
| 191 | ) -> EditResult<EditInfo, IambInfo> { | ||
| 192 | // Send all scroll commands to the scrollback. | ||
| 193 | // | ||
| 194 | // If there's enough message text for scrolling to be necessary, | ||
| 195 | // navigating with movement keys should be enough to do the job. | ||
| 196 | self.scrollback.scroll(style, ctx, store) | ||
| 197 | } | ||
| 198 | } | ||
| 199 | |||
| 200 | impl PromptActions<ProgramContext, ProgramStore, IambInfo> for ChatState { | ||
| 201 | fn submit( | ||
| 202 | &mut self, | ||
| 203 | ctx: &ProgramContext, | ||
| 204 | _: &mut ProgramStore, | ||
| 205 | ) -> EditResult<Vec<(ProgramAction, ProgramContext)>, IambInfo> { | ||
| 206 | let txt = self.tbox.reset_text(); | ||
| 207 | |||
| 208 | let act = if txt.is_empty() { | ||
| 209 | vec![] | ||
| 210 | } else { | ||
| 211 | let act = IambAction::SendMessage(self.room_id.clone(), txt).into(); | ||
| 212 | |||
| 213 | vec![(act, ctx.clone())] | ||
| 214 | }; | ||
| 215 | |||
| 216 | Ok(act) | ||
| 217 | } | ||
| 218 | |||
| 219 | fn abort( | ||
| 220 | &mut self, | ||
| 221 | empty: bool, | ||
| 222 | _: &ProgramContext, | ||
| 223 | _: &mut ProgramStore, | ||
| 224 | ) -> EditResult<Vec<(ProgramAction, ProgramContext)>, IambInfo> { | ||
| 225 | let text = self.tbox.get(); | ||
| 226 | |||
| 227 | if empty && text.is_blank() { | ||
| 228 | return Ok(vec![]); | ||
| 229 | } | ||
| 230 | |||
| 231 | let text = self.tbox.reset().trim(); | ||
| 232 | |||
| 233 | if text.is_empty() { | ||
| 234 | let _ = self.sent.end(); | ||
| 235 | } else { | ||
| 236 | self.sent.select(text); | ||
| 237 | } | ||
| 238 | |||
| 239 | return Ok(vec![]); | ||
| 240 | } | ||
| 241 | |||
| 242 | fn recall( | ||
| 243 | &mut self, | ||
| 244 | dir: &MoveDir1D, | ||
| 245 | count: &Count, | ||
| 246 | ctx: &ProgramContext, | ||
| 247 | _: &mut ProgramStore, | ||
| 248 | ) -> EditResult<Vec<(ProgramAction, ProgramContext)>, IambInfo> { | ||
| 249 | let count = ctx.resolve(count); | ||
| 250 | let rope = self.tbox.get(); | ||
| 251 | |||
| 252 | let text = self.sent.recall(&rope, &mut self.sent_scrollback, *dir, count); | ||
| 253 | |||
| 254 | if let Some(text) = text { | ||
| 255 | self.tbox.set_text(text); | ||
| 256 | } | ||
| 257 | |||
| 258 | Ok(vec![]) | ||
| 259 | } | ||
| 260 | } | ||
| 261 | |||
| 262 | impl Promptable<ProgramContext, ProgramStore, IambInfo> for ChatState { | ||
| 263 | fn prompt( | ||
| 264 | &mut self, | ||
| 265 | act: &PromptAction, | ||
| 266 | ctx: &ProgramContext, | ||
| 267 | store: &mut ProgramStore, | ||
| 268 | ) -> EditResult<Vec<(ProgramAction, ProgramContext)>, IambInfo> { | ||
| 269 | if let RoomFocus::Scrollback = self.focus { | ||
| 270 | return Ok(vec![]); | ||
| 271 | } | ||
| 272 | |||
| 273 | match act { | ||
| 274 | PromptAction::Submit => self.submit(ctx, store), | ||
| 275 | PromptAction::Abort(empty) => self.abort(*empty, ctx, store), | ||
| 276 | PromptAction::Recall(dir, count) => self.recall(dir, count, ctx, store), | ||
| 277 | _ => Err(EditError::Unimplemented("unknown prompt action".to_string())), | ||
| 278 | } | ||
| 279 | } | ||
| 280 | } | ||
| 281 | |||
| 282 | pub struct Chat<'a> { | ||
| 283 | store: &'a mut ProgramStore, | ||
| 284 | focused: bool, | ||
| 285 | } | ||
| 286 | |||
| 287 | impl<'a> Chat<'a> { | ||
| 288 | pub fn new(store: &'a mut ProgramStore) -> Chat<'a> { | ||
| 289 | Chat { store, focused: false } | ||
| 290 | } | ||
| 291 | |||
| 292 | pub fn focus(mut self, focused: bool) -> Self { | ||
| 293 | self.focused = focused; | ||
| 294 | self | ||
| 295 | } | ||
| 296 | } | ||
| 297 | |||
| 298 | impl<'a> StatefulWidget for Chat<'a> { | ||
| 299 | type State = ChatState; | ||
| 300 | |||
| 301 | fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) { | ||
| 302 | let lines = state.tbox.has_lines(5).max(1) as u16; | ||
| 303 | let drawh = area.height; | ||
| 304 | let texth = lines.min(drawh).clamp(1, 5); | ||
| 305 | let scrollh = drawh.saturating_sub(texth); | ||
| 306 | |||
| 307 | let scrollarea = Rect::new(area.x, area.y, area.width, scrollh); | ||
| 308 | let textarea = Rect::new(scrollarea.x, scrollarea.y + scrollh, scrollarea.width, texth); | ||
| 309 | |||
| 310 | let scrollback_focused = state.focus.is_scrollback() && self.focused; | ||
| 311 | let scrollback = Scrollback::new(self.store).focus(scrollback_focused); | ||
| 312 | scrollback.render(scrollarea, buf, &mut state.scrollback); | ||
| 313 | |||
| 314 | let prompt = if self.focused { "> " } else { " " }; | ||
| 315 | |||
| 316 | let tbox = TextBox::new().prompt(prompt); | ||
| 317 | tbox.render(textarea, buf, &mut state.tbox); | ||
| 318 | } | ||
| 319 | } | ||
src/windows/room/mod.rs added +182
| @@ -0,0 +1,182 @@ | |||
| 1 | use matrix_sdk::room::Room as MatrixRoom; | ||
| 2 | use matrix_sdk::ruma::RoomId; | ||
| 3 | use matrix_sdk::DisplayName; | ||
| 4 | |||
| 5 | use modalkit::tui::{buffer::Buffer, layout::Rect, widgets::StatefulWidget}; | ||
| 6 | |||
| 7 | use modalkit::{ | ||
| 8 | editing::action::{ | ||
| 9 | EditInfo, | ||
| 10 | EditResult, | ||
| 11 | Editable, | ||
| 12 | EditorAction, | ||
| 13 | Jumpable, | ||
| 14 | PromptAction, | ||
| 15 | Promptable, | ||
| 16 | Scrollable, | ||
| 17 | }, | ||
| 18 | editing::base::{CloseFlags, MoveDir1D, PositionList, ScrollStyle, WordStyle}, | ||
| 19 | widgets::{TermOffset, TerminalCursor, WindowOps}, | ||
| 20 | }; | ||
| 21 | |||
| 22 | use crate::base::{IambInfo, IambResult, ProgramAction, ProgramContext, ProgramStore}; | ||
| 23 | |||
| 24 | use self::chat::ChatState; | ||
| 25 | use self::space::{Space, SpaceState}; | ||
| 26 | |||
| 27 | mod chat; | ||
| 28 | mod scrollback; | ||
| 29 | mod space; | ||
| 30 | |||
| 31 | macro_rules! delegate { | ||
| 32 | ($s: expr, $id: ident => $e: expr) => { | ||
| 33 | match $s { | ||
| 34 | RoomState::Chat($id) => $e, | ||
| 35 | RoomState::Space($id) => $e, | ||
| 36 | } | ||
| 37 | }; | ||
| 38 | } | ||
| 39 | |||
| 40 | pub enum RoomState { | ||
| 41 | Chat(ChatState), | ||
| 42 | Space(SpaceState), | ||
| 43 | } | ||
| 44 | |||
| 45 | impl From<ChatState> for RoomState { | ||
| 46 | fn from(chat: ChatState) -> Self { | ||
| 47 | RoomState::Chat(chat) | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | impl From<SpaceState> for RoomState { | ||
| 52 | fn from(space: SpaceState) -> Self { | ||
| 53 | RoomState::Space(space) | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | impl RoomState { | ||
| 58 | pub fn new(room: MatrixRoom, name: DisplayName, store: &mut ProgramStore) -> Self { | ||
| 59 | let room_id = room.room_id().to_owned(); | ||
| 60 | let info = store.application.get_room_info(room_id); | ||
| 61 | info.name = name.to_string().into(); | ||
| 62 | |||
| 63 | if room.is_space() { | ||
| 64 | SpaceState::new(room).into() | ||
| 65 | } else { | ||
| 66 | ChatState::new(room, store).into() | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | pub fn get_title(&self, store: &mut ProgramStore) -> String { | ||
| 71 | store | ||
| 72 | .application | ||
| 73 | .rooms | ||
| 74 | .get(self.id()) | ||
| 75 | .and_then(|i| i.name.as_ref()) | ||
| 76 | .map(String::from) | ||
| 77 | .unwrap_or_else(|| "Untitled Matrix Room".to_string()) | ||
| 78 | } | ||
| 79 | |||
| 80 | pub fn focus_toggle(&mut self) { | ||
| 81 | match self { | ||
| 82 | RoomState::Chat(chat) => chat.focus_toggle(), | ||
| 83 | RoomState::Space(_) => return, | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | pub fn id(&self) -> &RoomId { | ||
| 88 | match self { | ||
| 89 | RoomState::Chat(chat) => chat.id(), | ||
| 90 | RoomState::Space(space) => space.id(), | ||
| 91 | } | ||
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 95 | impl Editable<ProgramContext, ProgramStore, IambInfo> for RoomState { | ||
| 96 | fn editor_command( | ||
| 97 | &mut self, | ||
| 98 | act: &EditorAction, | ||
| 99 | ctx: &ProgramContext, | ||
| 100 | store: &mut ProgramStore, | ||
| 101 | ) -> EditResult<EditInfo, IambInfo> { | ||
| 102 | delegate!(self, w => w.editor_command(act, ctx, store)) | ||
| 103 | } | ||
| 104 | } | ||
| 105 | |||
| 106 | impl Jumpable<ProgramContext, IambInfo> for RoomState { | ||
| 107 | fn jump( | ||
| 108 | &mut self, | ||
| 109 | list: PositionList, | ||
| 110 | dir: MoveDir1D, | ||
| 111 | count: usize, | ||
| 112 | ctx: &ProgramContext, | ||
| 113 | ) -> IambResult<usize> { | ||
| 114 | delegate!(self, w => w.jump(list, dir, count, ctx)) | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | impl Scrollable<ProgramContext, ProgramStore, IambInfo> for RoomState { | ||
| 119 | fn scroll( | ||
| 120 | &mut self, | ||
| 121 | style: &ScrollStyle, | ||
| 122 | ctx: &ProgramContext, | ||
| 123 | store: &mut ProgramStore, | ||
| 124 | ) -> EditResult<EditInfo, IambInfo> { | ||
| 125 | delegate!(self, w => w.scroll(style, ctx, store)) | ||
| 126 | } | ||
| 127 | } | ||
| 128 | |||
| 129 | impl Promptable<ProgramContext, ProgramStore, IambInfo> for RoomState { | ||
| 130 | fn prompt( | ||
| 131 | &mut self, | ||
| 132 | act: &PromptAction, | ||
| 133 | ctx: &ProgramContext, | ||
| 134 | store: &mut ProgramStore, | ||
| 135 | ) -> EditResult<Vec<(ProgramAction, ProgramContext)>, IambInfo> { | ||
| 136 | delegate!(self, w => w.prompt(act, ctx, store)) | ||
| 137 | } | ||
| 138 | } | ||
| 139 | |||
| 140 | impl TerminalCursor for RoomState { | ||
| 141 | fn get_term_cursor(&self) -> Option<TermOffset> { | ||
| 142 | delegate!(self, w => w.get_term_cursor()) | ||
| 143 | } | ||
| 144 | } | ||
| 145 | |||
| 146 | impl WindowOps<IambInfo> for RoomState { | ||
| 147 | fn draw(&mut self, area: Rect, buf: &mut Buffer, focused: bool, store: &mut ProgramStore) { | ||
| 148 | match self { | ||
| 149 | RoomState::Chat(chat) => chat.draw(area, buf, focused, store), | ||
| 150 | RoomState::Space(space) => { | ||
| 151 | Space::new(store).focus(focused).render(area, buf, space); | ||
| 152 | }, | ||
| 153 | } | ||
| 154 | } | ||
| 155 | |||
| 156 | fn dup(&self, store: &mut ProgramStore) -> Self { | ||
| 157 | match self { | ||
| 158 | RoomState::Chat(chat) => RoomState::Chat(chat.dup(store)), | ||
| 159 | RoomState::Space(space) => RoomState::Space(space.dup(store)), | ||
| 160 | } | ||
| 161 | } | ||
| 162 | |||
| 163 | fn close(&mut self, _: CloseFlags, _: &mut ProgramStore) -> bool { | ||
| 164 | // XXX: what's the right closing behaviour for a room? | ||
| 165 | // Should write send a message? | ||
| 166 | true | ||
| 167 | } | ||
| 168 | |||
| 169 | fn get_cursor_word(&self, style: &WordStyle) -> Option<String> { | ||
| 170 | match self { | ||
| 171 | RoomState::Chat(chat) => chat.get_cursor_word(style), | ||
| 172 | RoomState::Space(space) => space.get_cursor_word(style), | ||
| 173 | } | ||
| 174 | } | ||
| 175 | |||
| 176 | fn get_selected_word(&self) -> Option<String> { | ||
| 177 | match self { | ||
| 178 | RoomState::Chat(chat) => chat.get_selected_word(), | ||
| 179 | RoomState::Space(space) => space.get_selected_word(), | ||
| 180 | } | ||
| 181 | } | ||
| 182 | } | ||
src/windows/room/scrollback.rs added +1471
| @@ -0,0 +1,1471 @@ | |||
| 1 | use std::collections::HashSet; | ||
| 2 | |||
| 3 | use regex::Regex; | ||
| 4 | |||
| 5 | use matrix_sdk::ruma::OwnedRoomId; | ||
| 6 | |||
| 7 | use modalkit::tui::{buffer::Buffer, layout::Rect, widgets::StatefulWidget}; | ||
| 8 | use modalkit::widgets::{ScrollActions, TerminalCursor, WindowOps}; | ||
| 9 | |||
| 10 | use modalkit::editing::{ | ||
| 11 | action::{ | ||
| 12 | Action, | ||
| 13 | CursorAction, | ||
| 14 | EditAction, | ||
| 15 | EditError, | ||
| 16 | EditInfo, | ||
| 17 | EditResult, | ||
| 18 | Editable, | ||
| 19 | EditorAction, | ||
| 20 | EditorActions, | ||
| 21 | HistoryAction, | ||
| 22 | InsertTextAction, | ||
| 23 | Jumpable, | ||
| 24 | PromptAction, | ||
| 25 | Promptable, | ||
| 26 | Scrollable, | ||
| 27 | Searchable, | ||
| 28 | SelectionAction, | ||
| 29 | UIError, | ||
| 30 | UIResult, | ||
| 31 | }, | ||
| 32 | base::{ | ||
| 33 | Axis, | ||
| 34 | CloseFlags, | ||
| 35 | Count, | ||
| 36 | EditRange, | ||
| 37 | EditTarget, | ||
| 38 | Mark, | ||
| 39 | MoveDir1D, | ||
| 40 | MoveDir2D, | ||
| 41 | MoveDirMod, | ||
| 42 | MovePosition, | ||
| 43 | MoveTerminus, | ||
| 44 | MoveType, | ||
| 45 | PositionList, | ||
| 46 | RangeType, | ||
| 47 | Register, | ||
| 48 | ScrollSize, | ||
| 49 | ScrollStyle, | ||
| 50 | SearchType, | ||
| 51 | TargetShape, | ||
| 52 | ViewportContext, | ||
| 53 | WordStyle, | ||
| 54 | }, | ||
| 55 | context::{EditContext, Resolve}, | ||
| 56 | cursor::{CursorGroup, CursorState}, | ||
| 57 | history::HistoryList, | ||
| 58 | rope::EditRope, | ||
| 59 | store::{RegisterCell, RegisterPutFlags}, | ||
| 60 | }; | ||
| 61 | |||
| 62 | use crate::{ | ||
| 63 | base::{IambBufferId, IambInfo, ProgramContext, ProgramStore, RoomFocus, RoomInfo}, | ||
| 64 | message::{Message, MessageCursor, MessageKey}, | ||
| 65 | }; | ||
| 66 | |||
| 67 | fn nth_key_before(pos: MessageKey, n: usize, info: &RoomInfo) -> MessageKey { | ||
| 68 | let mut end = &pos; | ||
| 69 | let iter = info.messages.range(..=&pos).rev().enumerate(); | ||
| 70 | |||
| 71 | for (i, (key, _)) in iter { | ||
| 72 | end = key; | ||
| 73 | |||
| 74 | if i >= n { | ||
| 75 | break; | ||
| 76 | } | ||
| 77 | } | ||
| 78 | |||
| 79 | end.clone() | ||
| 80 | } | ||
| 81 | |||
| 82 | fn nth_before(pos: MessageKey, n: usize, info: &RoomInfo) -> MessageCursor { | ||
| 83 | nth_key_before(pos, n, info).into() | ||
| 84 | } | ||
| 85 | |||
| 86 | fn nth_key_after(pos: MessageKey, n: usize, info: &RoomInfo) -> MessageKey { | ||
| 87 | let mut end = &pos; | ||
| 88 | let iter = info.messages.range(&pos..).enumerate(); | ||
| 89 | |||
| 90 | for (i, (key, _)) in iter { | ||
| 91 | end = key; | ||
| 92 | |||
| 93 | if i >= n { | ||
| 94 | break; | ||
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 98 | end.clone() | ||
| 99 | } | ||
| 100 | |||
| 101 | fn nth_after(pos: MessageKey, n: usize, info: &RoomInfo) -> MessageCursor { | ||
| 102 | nth_key_after(pos, n, info).into() | ||
| 103 | } | ||
| 104 | |||
| 105 | pub struct ScrollbackState { | ||
| 106 | room_id: OwnedRoomId, | ||
| 107 | id: IambBufferId, | ||
| 108 | cursor: MessageCursor, | ||
| 109 | viewctx: ViewportContext<MessageCursor>, | ||
| 110 | jumped: HistoryList<MessageCursor>, | ||
| 111 | } | ||
| 112 | |||
| 113 | impl ScrollbackState { | ||
| 114 | pub fn new(room_id: OwnedRoomId) -> ScrollbackState { | ||
| 115 | let id = IambBufferId::Room(room_id.to_owned(), RoomFocus::Scrollback); | ||
| 116 | let cursor = MessageCursor::default(); | ||
| 117 | let viewctx = ViewportContext::default(); | ||
| 118 | let jumped = HistoryList::default(); | ||
| 119 | |||
| 120 | ScrollbackState { room_id, id, cursor, viewctx, jumped } | ||
| 121 | } | ||
| 122 | |||
| 123 | /// Set the dimensions and placement within the terminal window for this list. | ||
| 124 | pub fn set_term_info(&mut self, area: Rect) { | ||
| 125 | self.viewctx.dimensions = (area.width as usize, area.height as usize); | ||
| 126 | } | ||
| 127 | |||
| 128 | pub fn messages<'a>( | ||
| 129 | &self, | ||
| 130 | range: EditRange<MessageCursor>, | ||
| 131 | info: &'a RoomInfo, | ||
| 132 | ) -> impl Iterator<Item = (&'a MessageKey, &'a Message)> { | ||
| 133 | let start = range.start.to_key(info); | ||
| 134 | let end = range.end.to_key(info); | ||
| 135 | |||
| 136 | let (start, end) = if let (Some(start), Some(end)) = (start, end) { | ||
| 137 | (start, end) | ||
| 138 | } else if let Some((last, _)) = info.messages.last_key_value() { | ||
| 139 | (last, last) | ||
| 140 | } else { | ||
| 141 | return info.messages.range(..); | ||
| 142 | }; | ||
| 143 | |||
| 144 | if range.inclusive { | ||
| 145 | info.messages.range(start..=end) | ||
| 146 | } else { | ||
| 147 | info.messages.range(start..end) | ||
| 148 | } | ||
| 149 | } | ||
| 150 | |||
| 151 | fn scrollview(&mut self, idx: MessageKey, pos: MovePosition, info: &RoomInfo) { | ||
| 152 | let selidx = if let Some(key) = self.cursor.to_key(info) { | ||
| 153 | key | ||
| 154 | } else { | ||
| 155 | return; | ||
| 156 | }; | ||
| 157 | |||
| 158 | match pos { | ||
| 159 | MovePosition::Beginning => { | ||
| 160 | self.viewctx.corner = idx.into(); | ||
| 161 | }, | ||
| 162 | MovePosition::Middle => { | ||
| 163 | let mut lines = 0; | ||
| 164 | let target = self.viewctx.get_height() / 2; | ||
| 165 | |||
| 166 | for (key, item) in info.messages.range(..=&idx).rev() { | ||
| 167 | let sel = selidx == key; | ||
| 168 | let len = item.show(sel, &self.viewctx).lines.len(); | ||
| 169 | |||
| 170 | if key == &idx { | ||
| 171 | lines += len / 2; | ||
| 172 | } else { | ||
| 173 | lines += len; | ||
| 174 | } | ||
| 175 | |||
| 176 | if lines >= target { | ||
| 177 | // We've moved back far enough. | ||
| 178 | self.viewctx.corner.timestamp = key.clone().into(); | ||
| 179 | self.viewctx.corner.text_row = lines - target; | ||
| 180 | break; | ||
| 181 | } | ||
| 182 | } | ||
| 183 | }, | ||
| 184 | MovePosition::End => { | ||
| 185 | let mut lines = 0; | ||
| 186 | let target = self.viewctx.get_height(); | ||
| 187 | |||
| 188 | for (key, item) in info.messages.range(..=&idx).rev() { | ||
| 189 | let sel = key == selidx; | ||
| 190 | let len = item.show(sel, &self.viewctx).lines.len(); | ||
| 191 | |||
| 192 | lines += len; | ||
| 193 | |||
| 194 | if lines >= target { | ||
| 195 | // We've moved back far enough. | ||
| 196 | self.viewctx.corner.timestamp = key.clone().into(); | ||
| 197 | self.viewctx.corner.text_row = lines - target; | ||
| 198 | break; | ||
| 199 | } | ||
| 200 | } | ||
| 201 | }, | ||
| 202 | } | ||
| 203 | } | ||
| 204 | |||
| 205 | fn shift_cursor(&mut self, info: &RoomInfo) { | ||
| 206 | let last_key = if let Some(k) = info.messages.last_key_value() { | ||
| 207 | k.0 | ||
| 208 | } else { | ||
| 209 | return; | ||
| 210 | }; | ||
| 211 | |||
| 212 | let corner_key = self.viewctx.corner.timestamp.as_ref().unwrap_or(last_key); | ||
| 213 | |||
| 214 | if self.cursor < self.viewctx.corner { | ||
| 215 | // Cursor is above the viewport; move it inside. | ||
| 216 | self.cursor = corner_key.clone().into(); | ||
| 217 | } | ||
| 218 | |||
| 219 | // Check whether the cursor is below the viewport. | ||
| 220 | let mut lines = 0; | ||
| 221 | |||
| 222 | let cursor_key = self.cursor.timestamp.as_ref().unwrap_or(last_key); | ||
| 223 | |||
| 224 | for (idx, item) in info.messages.range(corner_key.clone()..) { | ||
| 225 | if idx == cursor_key { | ||
| 226 | // Cursor is already within the viewport. | ||
| 227 | break; | ||
| 228 | } | ||
| 229 | |||
| 230 | lines += item.show(false, &self.viewctx).height().max(1); | ||
| 231 | |||
| 232 | if lines >= self.viewctx.get_height() { | ||
| 233 | // We've reached the end of the viewport; move cursor into it. | ||
| 234 | self.cursor = idx.clone().into(); | ||
| 235 | break; | ||
| 236 | } | ||
| 237 | } | ||
| 238 | } | ||
| 239 | |||
| 240 | fn _range_to(&self, cursor: MessageCursor) -> EditRange<MessageCursor> { | ||
| 241 | EditRange::inclusive(self.cursor.clone(), cursor, TargetShape::LineWise) | ||
| 242 | } | ||
| 243 | |||
| 244 | fn movement( | ||
| 245 | &self, | ||
| 246 | pos: MessageKey, | ||
| 247 | movement: &MoveType, | ||
| 248 | count: &Count, | ||
| 249 | ctx: &ProgramContext, | ||
| 250 | info: &RoomInfo, | ||
| 251 | ) -> Option<MessageCursor> { | ||
| 252 | let count = ctx.resolve(count); | ||
| 253 | |||
| 254 | match movement { | ||
| 255 | // These movements don't map meaningfully onto the scrollback history. | ||
| 256 | MoveType::BufferByteOffset => None, | ||
| 257 | MoveType::Column(_, _) => None, | ||
| 258 | MoveType::ItemMatch => None, | ||
| 259 | MoveType::LineColumnOffset => None, | ||
| 260 | MoveType::LinePercent => None, | ||
| 261 | MoveType::LinePos(_) => None, | ||
| 262 | MoveType::SentenceBegin(_) => None, | ||
| 263 | MoveType::ScreenFirstWord(_) => None, | ||
| 264 | MoveType::ScreenLinePos(_) => None, | ||
| 265 | MoveType::WordBegin(_, _) => None, | ||
| 266 | MoveType::WordEnd(_, _) => None, | ||
| 267 | |||
| 268 | MoveType::BufferLineOffset => None, | ||
| 269 | MoveType::BufferLinePercent => None, | ||
| 270 | MoveType::BufferPos(MovePosition::Beginning) => { | ||
| 271 | let start = info.messages.first_key_value()?.0.clone(); | ||
| 272 | |||
| 273 | Some(start.into()) | ||
| 274 | }, | ||
| 275 | MoveType::BufferPos(MovePosition::Middle) => None, | ||
| 276 | MoveType::BufferPos(MovePosition::End) => Some(MessageCursor::latest()), | ||
| 277 | MoveType::FinalNonBlank(dir) | | ||
| 278 | MoveType::FirstWord(dir) | | ||
| 279 | MoveType::Line(dir) | | ||
| 280 | MoveType::ScreenLine(dir) | | ||
| 281 | MoveType::ParagraphBegin(dir) | | ||
| 282 | MoveType::SectionBegin(dir) | | ||
| 283 | MoveType::SectionEnd(dir) => { | ||
| 284 | match dir { | ||
| 285 | MoveDir1D::Previous => nth_before(pos, count, info).into(), | ||
| 286 | MoveDir1D::Next => nth_after(pos, count, info).into(), | ||
| 287 | } | ||
| 288 | }, | ||
| 289 | MoveType::ViewportPos(MovePosition::Beginning) => { | ||
| 290 | return self.viewctx.corner.timestamp.as_ref().map(|k| k.clone().into()); | ||
| 291 | }, | ||
| 292 | MoveType::ViewportPos(MovePosition::Middle) => { | ||
| 293 | // XXX: Need to calculate an accurate middle position. | ||
| 294 | return None; | ||
| 295 | }, | ||
| 296 | MoveType::ViewportPos(MovePosition::End) => { | ||
| 297 | // XXX: Need store to calculate an accurate end position. | ||
| 298 | return None; | ||
| 299 | }, | ||
| 300 | |||
| 301 | _ => None, | ||
| 302 | } | ||
| 303 | } | ||
| 304 | |||
| 305 | fn range_of_movement( | ||
| 306 | &self, | ||
| 307 | pos: MessageKey, | ||
| 308 | movement: &MoveType, | ||
| 309 | count: &Count, | ||
| 310 | ctx: &ProgramContext, | ||
| 311 | info: &RoomInfo, | ||
| 312 | ) -> Option<EditRange<MessageCursor>> { | ||
| 313 | let other = self.movement(pos.clone(), movement, count, ctx, info)?; | ||
| 314 | |||
| 315 | Some(EditRange::inclusive(pos.into(), other, TargetShape::LineWise)) | ||
| 316 | } | ||
| 317 | |||
| 318 | fn range( | ||
| 319 | &self, | ||
| 320 | pos: MessageKey, | ||
| 321 | range: &RangeType, | ||
| 322 | _: bool, | ||
| 323 | count: &Count, | ||
| 324 | ctx: &ProgramContext, | ||
| 325 | info: &RoomInfo, | ||
| 326 | ) -> Option<EditRange<MessageCursor>> { | ||
| 327 | match range { | ||
| 328 | RangeType::Bracketed(_, _) => None, | ||
| 329 | RangeType::Item => None, | ||
| 330 | RangeType::Quote(_) => None, | ||
| 331 | RangeType::Word(_) => None, | ||
| 332 | RangeType::XmlTag => None, | ||
| 333 | |||
| 334 | RangeType::Buffer => { | ||
| 335 | let start = info.messages.first_key_value()?.0.clone(); | ||
| 336 | let end = info.messages.last_key_value()?.0.clone(); | ||
| 337 | |||
| 338 | Some(EditRange::inclusive(start.into(), end.into(), TargetShape::LineWise)) | ||
| 339 | }, | ||
| 340 | RangeType::Line | RangeType::Paragraph | RangeType::Sentence => { | ||
| 341 | let count = ctx.resolve(count); | ||
| 342 | |||
| 343 | if count == 0 { | ||
| 344 | return None; | ||
| 345 | } | ||
| 346 | |||
| 347 | let mut end = &pos; | ||
| 348 | |||
| 349 | for (i, (key, _)) in info.messages.range(&pos..).enumerate() { | ||
| 350 | if i >= count { | ||
| 351 | break; | ||
| 352 | } | ||
| 353 | |||
| 354 | end = key; | ||
| 355 | } | ||
| 356 | |||
| 357 | let end = end.clone().into(); | ||
| 358 | let start = pos.into(); | ||
| 359 | |||
| 360 | Some(EditRange::inclusive(start, end, TargetShape::LineWise)) | ||
| 361 | }, | ||
| 362 | |||
| 363 | _ => None, | ||
| 364 | } | ||
| 365 | } | ||
| 366 | |||
| 367 | fn find_message_next( | ||
| 368 | &self, | ||
| 369 | start: MessageKey, | ||
| 370 | needle: &Regex, | ||
| 371 | mut count: usize, | ||
| 372 | info: &RoomInfo, | ||
| 373 | ) -> Option<MessageCursor> { | ||
| 374 | let mut mc = None; | ||
| 375 | |||
| 376 | for (key, msg) in info.messages.range(&start..) { | ||
| 377 | if count == 0 { | ||
| 378 | break; | ||
| 379 | } | ||
| 380 | |||
| 381 | if key == &start { | ||
| 382 | continue; | ||
| 383 | } | ||
| 384 | |||
| 385 | if needle.is_match(msg.as_ref()) { | ||
| 386 | mc = MessageCursor::from(key.clone()).into(); | ||
| 387 | count -= 1; | ||
| 388 | } | ||
| 389 | } | ||
| 390 | |||
| 391 | return mc; | ||
| 392 | } | ||
| 393 | |||
| 394 | fn find_message_prev( | ||
| 395 | &self, | ||
| 396 | end: MessageKey, | ||
| 397 | needle: &Regex, | ||
| 398 | mut count: usize, | ||
| 399 | info: &RoomInfo, | ||
| 400 | need_load: &mut HashSet<OwnedRoomId>, | ||
| 401 | ) -> Option<MessageCursor> { | ||
| 402 | let mut mc = None; | ||
| 403 | |||
| 404 | for (key, msg) in info.messages.range(..&end).rev() { | ||
| 405 | if count == 0 { | ||
| 406 | break; | ||
| 407 | } | ||
| 408 | |||
| 409 | if needle.is_match(msg.as_ref()) { | ||
| 410 | mc = MessageCursor::from(key.clone()).into(); | ||
| 411 | count -= 1; | ||
| 412 | } | ||
| 413 | } | ||
| 414 | |||
| 415 | if count > 0 { | ||
| 416 | need_load.insert(self.room_id.clone()); | ||
| 417 | } | ||
| 418 | |||
| 419 | return mc; | ||
| 420 | } | ||
| 421 | |||
| 422 | fn find_message( | ||
| 423 | &self, | ||
| 424 | key: MessageKey, | ||
| 425 | dir: MoveDir1D, | ||
| 426 | needle: &Regex, | ||
| 427 | count: usize, | ||
| 428 | info: &RoomInfo, | ||
| 429 | need_load: &mut HashSet<OwnedRoomId>, | ||
| 430 | ) -> Option<MessageCursor> { | ||
| 431 | match dir { | ||
| 432 | MoveDir1D::Next => self.find_message_next(key, needle, count, info), | ||
| 433 | MoveDir1D::Previous => self.find_message_prev(key, needle, count, info, need_load), | ||
| 434 | } | ||
| 435 | } | ||
| 436 | } | ||
| 437 | |||
| 438 | impl WindowOps<IambInfo> for ScrollbackState { | ||
| 439 | fn draw(&mut self, area: Rect, buf: &mut Buffer, focused: bool, store: &mut ProgramStore) { | ||
| 440 | Scrollback::new(store).focus(focused).render(area, buf, self) | ||
| 441 | } | ||
| 442 | |||
| 443 | fn dup(&self, _: &mut ProgramStore) -> Self { | ||
| 444 | ScrollbackState { | ||
| 445 | room_id: self.room_id.clone(), | ||
| 446 | id: self.id.clone(), | ||
| 447 | cursor: self.cursor.clone(), | ||
| 448 | viewctx: self.viewctx.clone(), | ||
| 449 | jumped: self.jumped.clone(), | ||
| 450 | } | ||
| 451 | } | ||
| 452 | |||
| 453 | fn close(&mut self, _: CloseFlags, _: &mut ProgramStore) -> bool { | ||
| 454 | // XXX: what's the right closing behaviour for a room? | ||
| 455 | // Should write send a message? | ||
| 456 | true | ||
| 457 | } | ||
| 458 | |||
| 459 | fn get_cursor_word(&self, _: &WordStyle) -> Option<String> { | ||
| 460 | None | ||
| 461 | } | ||
| 462 | |||
| 463 | fn get_selected_word(&self) -> Option<String> { | ||
| 464 | None | ||
| 465 | } | ||
| 466 | } | ||
| 467 | |||
| 468 | impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState { | ||
| 469 | fn edit( | ||
| 470 | &mut self, | ||
| 471 | operation: &EditAction, | ||
| 472 | motion: &EditTarget, | ||
| 473 | ctx: &ProgramContext, | ||
| 474 | store: &mut ProgramStore, | ||
| 475 | ) -> EditResult<EditInfo, IambInfo> { | ||
| 476 | let info = store.application.rooms.entry(self.room_id.clone()).or_default(); | ||
| 477 | let key = if let Some(k) = self.cursor.to_key(info) { | ||
| 478 | k.clone() | ||
| 479 | } else { | ||
| 480 | let msg = "No messages to select."; | ||
| 481 | let err = EditError::Failure(msg.to_string()); | ||
| 482 | return Err(err); | ||
| 483 | }; | ||
| 484 | |||
| 485 | match operation { | ||
| 486 | EditAction::Motion => { | ||
| 487 | if motion.is_jumping() { | ||
| 488 | self.jumped.push(self.cursor.clone()); | ||
| 489 | } | ||
| 490 | |||
| 491 | let pos = match motion { | ||
| 492 | EditTarget::CurrentPosition | EditTarget::Selection => { | ||
| 493 | return Ok(None); | ||
| 494 | }, | ||
| 495 | EditTarget::Boundary(rt, inc, term, count) => { | ||
| 496 | self.range(key, rt, *inc, count, ctx, info).map(|r| { | ||
| 497 | match term { | ||
| 498 | MoveTerminus::Beginning => r.start, | ||
| 499 | MoveTerminus::End => r.end, | ||
| 500 | } | ||
| 501 | }) | ||
| 502 | }, | ||
| 503 | EditTarget::CharJump(mark) | EditTarget::LineJump(mark) => { | ||
| 504 | let mark = ctx.resolve(mark); | ||
| 505 | let cursor = store.cursors.get_mark(self.id.clone(), mark)?; | ||
| 506 | |||
| 507 | if let mc @ Some(_) = MessageCursor::from_cursor(&cursor, info) { | ||
| 508 | mc | ||
| 509 | } else { | ||
| 510 | let msg = "Failed to restore mark"; | ||
| 511 | let err = EditError::Failure(msg.into()); | ||
| 512 | |||
| 513 | return Err(err); | ||
| 514 | } | ||
| 515 | }, | ||
| 516 | EditTarget::Motion(mt, count) => self.movement(key, mt, count, ctx, info), | ||
| 517 | EditTarget::Range(_, _, _) => { | ||
| 518 | return Err(EditError::Failure("Cannot use ranges in a list".to_string())); | ||
| 519 | }, | ||
| 520 | EditTarget::Search(SearchType::Char(_), _, _) => { | ||
| 521 | let msg = "Cannot perform character search in a list"; | ||
| 522 | let err = EditError::Failure(msg.into()); | ||
| 523 | |||
| 524 | return Err(err); | ||
| 525 | }, | ||
| 526 | EditTarget::Search(SearchType::Regex, flip, count) => { | ||
| 527 | let count = ctx.resolve(count); | ||
| 528 | |||
| 529 | let dir = ctx.get_search_regex_dir(); | ||
| 530 | let dir = flip.resolve(&dir); | ||
| 531 | |||
| 532 | let needle = match ctx.get_search_regex() { | ||
| 533 | Some(re) => re, | ||
| 534 | None => { | ||
| 535 | let lsearch = store.registers.get(&Register::LastSearch); | ||
| 536 | let lsearch = lsearch.value.to_string(); | ||
| 537 | |||
| 538 | Regex::new(lsearch.as_ref())? | ||
| 539 | }, | ||
| 540 | }; | ||
| 541 | |||
| 542 | self.find_message( | ||
| 543 | key, | ||
| 544 | dir, | ||
| 545 | &needle, | ||
| 546 | count, | ||
| 547 | info, | ||
| 548 | &mut store.application.need_load, | ||
| 549 | ) | ||
| 550 | }, | ||
| 551 | EditTarget::Search(SearchType::Word(_, _), _, _) => { | ||
| 552 | let msg = "Cannot perform word search in a list"; | ||
| 553 | let err = EditError::Failure(msg.into()); | ||
| 554 | |||
| 555 | return Err(err); | ||
| 556 | }, | ||
| 557 | |||
| 558 | _ => { | ||
| 559 | let msg = format!("Unknown editing target: {:?}", motion); | ||
| 560 | let err = EditError::Unimplemented(msg); | ||
| 561 | |||
| 562 | return Err(err); | ||
| 563 | }, | ||
| 564 | }; | ||
| 565 | |||
| 566 | if let Some(pos) = pos { | ||
| 567 | self.cursor = pos; | ||
| 568 | } | ||
| 569 | |||
| 570 | return Ok(None); | ||
| 571 | }, | ||
| 572 | EditAction::Yank => { | ||
| 573 | let range = match motion { | ||
| 574 | EditTarget::CurrentPosition | EditTarget::Selection => { | ||
| 575 | Some(self._range_to(key.into())) | ||
| 576 | }, | ||
| 577 | EditTarget::Boundary(rt, inc, term, count) => { | ||
| 578 | self.range(key, rt, *inc, count, ctx, info).map(|r| { | ||
| 579 | self._range_to(match term { | ||
| 580 | MoveTerminus::Beginning => r.start, | ||
| 581 | MoveTerminus::End => r.end, | ||
| 582 | }) | ||
| 583 | }) | ||
| 584 | }, | ||
| 585 | EditTarget::CharJump(mark) | EditTarget::LineJump(mark) => { | ||
| 586 | let mark = ctx.resolve(mark); | ||
| 587 | let cursor = store.cursors.get_mark(self.id.clone(), mark)?; | ||
| 588 | |||
| 589 | if let Some(c) = MessageCursor::from_cursor(&cursor, info) { | ||
| 590 | self._range_to(c).into() | ||
| 591 | } else { | ||
| 592 | let msg = "Failed to restore mark"; | ||
| 593 | let err = EditError::Failure(msg.into()); | ||
| 594 | |||
| 595 | return Err(err); | ||
| 596 | } | ||
| 597 | }, | ||
| 598 | EditTarget::Motion(mt, count) => { | ||
| 599 | self.range_of_movement(key, mt, count, ctx, info) | ||
| 600 | }, | ||
| 601 | EditTarget::Range(rt, inc, count) => { | ||
| 602 | self.range(key, rt, *inc, count, ctx, info) | ||
| 603 | }, | ||
| 604 | EditTarget::Search(SearchType::Char(_), _, _) => { | ||
| 605 | let msg = "Cannot perform character search in a list"; | ||
| 606 | let err = EditError::Failure(msg.into()); | ||
| 607 | |||
| 608 | return Err(err); | ||
| 609 | }, | ||
| 610 | EditTarget::Search(SearchType::Regex, flip, count) => { | ||
| 611 | let count = ctx.resolve(count); | ||
| 612 | |||
| 613 | let dir = ctx.get_search_regex_dir(); | ||
| 614 | let dir = flip.resolve(&dir); | ||
| 615 | |||
| 616 | let needle = match ctx.get_search_regex() { | ||
| 617 | Some(re) => re, | ||
| 618 | None => { | ||
| 619 | let lsearch = store.registers.get(&Register::LastSearch); | ||
| 620 | let lsearch = lsearch.value.to_string(); | ||
| 621 | |||
| 622 | Regex::new(lsearch.as_ref())? | ||
| 623 | }, | ||
| 624 | }; | ||
| 625 | |||
| 626 | self.find_message( | ||
| 627 | key, | ||
| 628 | dir, | ||
| 629 | &needle, | ||
| 630 | count, | ||
| 631 | info, | ||
| 632 | &mut store.application.need_load, | ||
| 633 | ) | ||
| 634 | .map(|c| self._range_to(c)) | ||
| 635 | }, | ||
| 636 | EditTarget::Search(SearchType::Word(_, _), _, _) => { | ||
| 637 | let msg = "Cannot perform word search in a list"; | ||
| 638 | let err = EditError::Failure(msg.into()); | ||
| 639 | |||
| 640 | return Err(err); | ||
| 641 | }, | ||
| 642 | |||
| 643 | _ => { | ||
| 644 | let msg = format!("Unknown motion: {:?}", motion); | ||
| 645 | let err = EditError::Unimplemented(msg); | ||
| 646 | |||
| 647 | return Err(err); | ||
| 648 | }, | ||
| 649 | }; | ||
| 650 | |||
| 651 | if let Some(range) = range { | ||
| 652 | let mut yanked = EditRope::from(""); | ||
| 653 | |||
| 654 | for (_, msg) in self.messages(range, info) { | ||
| 655 | yanked += EditRope::from(msg.as_ref()); | ||
| 656 | yanked += EditRope::from('\n'); | ||
| 657 | } | ||
| 658 | |||
| 659 | let cell = RegisterCell::new(TargetShape::LineWise, yanked); | ||
| 660 | let register = ctx.get_register().unwrap_or(Register::Unnamed); | ||
| 661 | let mut flags = RegisterPutFlags::NONE; | ||
| 662 | |||
| 663 | if ctx.get_register_append() { | ||
| 664 | flags |= RegisterPutFlags::APPEND; | ||
| 665 | } | ||
| 666 | |||
| 667 | store.registers.put(®ister, cell, flags); | ||
| 668 | } | ||
| 669 | |||
| 670 | return Ok(None); | ||
| 671 | }, | ||
| 672 | |||
| 673 | // Everything else is a modifying action. | ||
| 674 | EditAction::ChangeCase(_) => Err(EditError::ReadOnly), | ||
| 675 | EditAction::ChangeNumber(_) => Err(EditError::ReadOnly), | ||
| 676 | EditAction::Delete => Err(EditError::ReadOnly), | ||
| 677 | EditAction::Format => Err(EditError::ReadOnly), | ||
| 678 | EditAction::Indent(_) => Err(EditError::ReadOnly), | ||
| 679 | EditAction::Join(_) => Err(EditError::ReadOnly), | ||
| 680 | EditAction::Replace(_) => Err(EditError::ReadOnly), | ||
| 681 | } | ||
| 682 | } | ||
| 683 | |||
| 684 | fn mark( | ||
| 685 | &mut self, | ||
| 686 | name: Mark, | ||
| 687 | _: &ProgramContext, | ||
| 688 | store: &mut ProgramStore, | ||
| 689 | ) -> EditResult<EditInfo, IambInfo> { | ||
| 690 | let info = store.application.get_room_info(self.room_id.clone()); | ||
| 691 | |||
| 692 | if let Some(cursor) = self.cursor.to_cursor(info) { | ||
| 693 | store.cursors.set_mark(self.id.clone(), name, cursor); | ||
| 694 | |||
| 695 | Ok(None) | ||
| 696 | } else { | ||
| 697 | let msg = "Failed to set mark for message"; | ||
| 698 | let err = EditError::Failure(msg.into()); | ||
| 699 | |||
| 700 | Err(err) | ||
| 701 | } | ||
| 702 | } | ||
| 703 | |||
| 704 | fn insert_text( | ||
| 705 | &mut self, | ||
| 706 | _: &InsertTextAction, | ||
| 707 | _: &ProgramContext, | ||
| 708 | _: &mut ProgramStore, | ||
| 709 | ) -> EditResult<EditInfo, IambInfo> { | ||
| 710 | Err(EditError::ReadOnly) | ||
| 711 | } | ||
| 712 | |||
| 713 | fn selection_command( | ||
| 714 | &mut self, | ||
| 715 | _: &SelectionAction, | ||
| 716 | _: &ProgramContext, | ||
| 717 | _: &mut ProgramStore, | ||
| 718 | ) -> EditResult<EditInfo, IambInfo> { | ||
| 719 | Err(EditError::Failure("Cannot perform selection actions in a list".into())) | ||
| 720 | } | ||
| 721 | |||
| 722 | fn history_command( | ||
| 723 | &mut self, | ||
| 724 | act: &HistoryAction, | ||
| 725 | _: &ProgramContext, | ||
| 726 | _: &mut ProgramStore, | ||
| 727 | ) -> EditResult<EditInfo, IambInfo> { | ||
| 728 | match act { | ||
| 729 | HistoryAction::Checkpoint => Ok(None), | ||
| 730 | HistoryAction::Undo(_) => Err(EditError::Failure("Nothing to undo".into())), | ||
| 731 | HistoryAction::Redo(_) => Err(EditError::Failure("Nothing to redo".into())), | ||
| 732 | _ => Err(EditError::Unimplemented(format!("Unknown action: {:?}", act))), | ||
| 733 | } | ||
| 734 | } | ||
| 735 | |||
| 736 | fn cursor_command( | ||
| 737 | &mut self, | ||
| 738 | act: &CursorAction, | ||
| 739 | ctx: &ProgramContext, | ||
| 740 | store: &mut ProgramStore, | ||
| 741 | ) -> EditResult<EditInfo, IambInfo> { | ||
| 742 | let info = store.application.get_room_info(self.room_id.clone()); | ||
| 743 | |||
| 744 | match act { | ||
| 745 | CursorAction::Close(_) => Ok(None), | ||
| 746 | CursorAction::Rotate(_, _) => Ok(None), | ||
| 747 | CursorAction::Split(_) => Ok(None), | ||
| 748 | |||
| 749 | CursorAction::Restore(_) => { | ||
| 750 | let reg = ctx.get_register().unwrap_or(Register::UnnamedCursorGroup); | ||
| 751 | |||
| 752 | // Get saved group. | ||
| 753 | let ngroup = store.cursors.get_group(self.id.clone(), ®)?; | ||
| 754 | |||
| 755 | // Lists don't have groups; override current position. | ||
| 756 | if self.jumped.current() != &self.cursor { | ||
| 757 | self.jumped.push(self.cursor.clone()); | ||
| 758 | } | ||
| 759 | |||
| 760 | if let Some(mc) = MessageCursor::from_cursor(ngroup.leader.cursor(), info) { | ||
| 761 | self.cursor = mc; | ||
| 762 | |||
| 763 | Ok(None) | ||
| 764 | } else { | ||
| 765 | let msg = "Cannot restore position in message history"; | ||
| 766 | let err = EditError::Failure(msg.into()); | ||
| 767 | |||
| 768 | Err(err) | ||
| 769 | } | ||
| 770 | }, | ||
| 771 | CursorAction::Save(_) => { | ||
| 772 | let reg = ctx.get_register().unwrap_or(Register::UnnamedCursorGroup); | ||
| 773 | |||
| 774 | // Lists don't have groups; override any previously saved group. | ||
| 775 | let cursor = self.cursor.to_cursor(info).ok_or_else(|| { | ||
| 776 | let msg = "Cannot save position in message history"; | ||
| 777 | EditError::Failure(msg.into()) | ||
| 778 | })?; | ||
| 779 | |||
| 780 | let group = CursorGroup { | ||
| 781 | leader: CursorState::Location(cursor), | ||
| 782 | members: vec![], | ||
| 783 | }; | ||
| 784 | |||
| 785 | store.cursors.set_group(self.id.clone(), reg, group)?; | ||
| 786 | |||
| 787 | Ok(None) | ||
| 788 | }, | ||
| 789 | _ => Err(EditError::Unimplemented(format!("Unknown action: {:?}", act))), | ||
| 790 | } | ||
| 791 | } | ||
| 792 | } | ||
| 793 | |||
| 794 | impl Editable<ProgramContext, ProgramStore, IambInfo> for ScrollbackState { | ||
| 795 | fn editor_command( | ||
| 796 | &mut self, | ||
| 797 | act: &EditorAction, | ||
| 798 | ctx: &ProgramContext, | ||
| 799 | store: &mut ProgramStore, | ||
| 800 | ) -> EditResult<EditInfo, IambInfo> { | ||
| 801 | match act { | ||
| 802 | EditorAction::Cursor(act) => self.cursor_command(act, ctx, store), | ||
| 803 | EditorAction::Edit(ea, et) => self.edit(&ctx.resolve(ea), et, ctx, store), | ||
| 804 | EditorAction::History(act) => self.history_command(act, ctx, store), | ||
| 805 | EditorAction::InsertText(act) => self.insert_text(act, ctx, store), | ||
| 806 | EditorAction::Mark(name) => self.mark(ctx.resolve(name), ctx, store), | ||
| 807 | EditorAction::Selection(act) => self.selection_command(act, ctx, store), | ||
| 808 | |||
| 809 | EditorAction::Complete(_, _) => { | ||
| 810 | let msg = ""; | ||
| 811 | let err = EditError::Unimplemented(msg.into()); | ||
| 812 | |||
| 813 | Err(err) | ||
| 814 | }, | ||
| 815 | |||
| 816 | _ => Err(EditError::Unimplemented(format!("Unknown action: {:?}", act))), | ||
| 817 | } | ||
| 818 | } | ||
| 819 | } | ||
| 820 | |||
| 821 | impl Jumpable<ProgramContext, IambInfo> for ScrollbackState { | ||
| 822 | fn jump( | ||
| 823 | &mut self, | ||
| 824 | list: PositionList, | ||
| 825 | dir: MoveDir1D, | ||
| 826 | count: usize, | ||
| 827 | _: &ProgramContext, | ||
| 828 | ) -> UIResult<usize, IambInfo> { | ||
| 829 | match list { | ||
| 830 | PositionList::ChangeList => { | ||
| 831 | let msg = "No changes to jump to within the list"; | ||
| 832 | let err = UIError::Failure(msg.into()); | ||
| 833 | |||
| 834 | return Err(err); | ||
| 835 | }, | ||
| 836 | PositionList::JumpList => { | ||
| 837 | let (len, pos) = match dir { | ||
| 838 | MoveDir1D::Previous => { | ||
| 839 | if self.jumped.future_len() == 0 && *self.jumped.current() != self.cursor { | ||
| 840 | // Push current position if this is the first jump backwards. | ||
| 841 | self.jumped.push(self.cursor.clone()); | ||
| 842 | } | ||
| 843 | |||
| 844 | let plen = self.jumped.past_len(); | ||
| 845 | let pos = self.jumped.prev(count); | ||
| 846 | |||
| 847 | (plen, pos) | ||
| 848 | }, | ||
| 849 | MoveDir1D::Next => { | ||
| 850 | let flen = self.jumped.future_len(); | ||
| 851 | let pos = self.jumped.next(count); | ||
| 852 | |||
| 853 | (flen, pos) | ||
| 854 | }, | ||
| 855 | }; | ||
| 856 | |||
| 857 | if len > 0 { | ||
| 858 | self.cursor = pos.clone(); | ||
| 859 | } | ||
| 860 | |||
| 861 | return Ok(count.saturating_sub(len)); | ||
| 862 | }, | ||
| 863 | } | ||
| 864 | } | ||
| 865 | } | ||
| 866 | |||
| 867 | impl Promptable<ProgramContext, ProgramStore, IambInfo> for ScrollbackState { | ||
| 868 | fn prompt( | ||
| 869 | &mut self, | ||
| 870 | act: &PromptAction, | ||
| 871 | _: &ProgramContext, | ||
| 872 | store: &mut ProgramStore, | ||
| 873 | ) -> EditResult<Vec<(Action<IambInfo>, ProgramContext)>, IambInfo> { | ||
| 874 | let info = store.application.get_room_info(self.room_id.clone()); | ||
| 875 | |||
| 876 | let _ = if let Some(key) = self.cursor.to_key(info) { | ||
| 877 | key | ||
| 878 | } else { | ||
| 879 | let msg = "No message currently selected"; | ||
| 880 | let err = EditError::Failure(msg.into()); | ||
| 881 | |||
| 882 | return Err(err); | ||
| 883 | }; | ||
| 884 | |||
| 885 | match act { | ||
| 886 | PromptAction::Submit => { | ||
| 887 | // XXX: I'm not sure exactly what to do here yet. I think I want this to display a | ||
| 888 | // pop-over ListState with actions that can then be submitted: | ||
| 889 | // | ||
| 890 | // - Create a reply | ||
| 891 | // - Edit a message | ||
| 892 | // - Redact a message | ||
| 893 | // - React to a message | ||
| 894 | // - Report a message | ||
| 895 | // - Download an attachment | ||
| 896 | // | ||
| 897 | // Each of these should correspond to a command that a user can run. For example, | ||
| 898 | // running `:reply` when hovering over a message should be equivalent to opening | ||
| 899 | // the pop-up and selecting "Reply To This Message". | ||
| 900 | return Ok(vec![]); | ||
| 901 | }, | ||
| 902 | PromptAction::Abort(..) => { | ||
| 903 | let msg = "Cannot abort a message."; | ||
| 904 | let err = EditError::Failure(msg.into()); | ||
| 905 | |||
| 906 | return Err(err); | ||
| 907 | }, | ||
| 908 | PromptAction::Recall(..) => { | ||
| 909 | let msg = "Cannot recall previous messages."; | ||
| 910 | let err = EditError::Failure(msg.into()); | ||
| 911 | |||
| 912 | return Err(err); | ||
| 913 | }, | ||
| 914 | _ => { | ||
| 915 | let msg = format!("Messages scrollback doesn't support {:?}", act); | ||
| 916 | let err = EditError::Unimplemented(msg); | ||
| 917 | |||
| 918 | return Err(err); | ||
| 919 | }, | ||
| 920 | } | ||
| 921 | } | ||
| 922 | } | ||
| 923 | |||
| 924 | impl ScrollActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState { | ||
| 925 | fn dirscroll( | ||
| 926 | &mut self, | ||
| 927 | dir: MoveDir2D, | ||
| 928 | size: ScrollSize, | ||
| 929 | count: &Count, | ||
| 930 | ctx: &ProgramContext, | ||
| 931 | store: &mut ProgramStore, | ||
| 932 | ) -> EditResult<EditInfo, IambInfo> { | ||
| 933 | let info = store.application.get_room_info(self.room_id.clone()); | ||
| 934 | let mut corner = self.viewctx.corner.clone(); | ||
| 935 | |||
| 936 | let last_key = if let Some(k) = info.messages.last_key_value() { | ||
| 937 | k.0 | ||
| 938 | } else { | ||
| 939 | return Ok(None); | ||
| 940 | }; | ||
| 941 | |||
| 942 | let corner_key = corner.timestamp.as_ref().unwrap_or(last_key).clone(); | ||
| 943 | let cursor_key = self.cursor.timestamp.as_ref().unwrap_or(last_key); | ||
| 944 | |||
| 945 | let count = ctx.resolve(count); | ||
| 946 | let height = self.viewctx.get_height(); | ||
| 947 | let mut rows = match size { | ||
| 948 | ScrollSize::Cell => count, | ||
| 949 | ScrollSize::HalfPage => count.saturating_mul(height) / 2, | ||
| 950 | ScrollSize::Page => count.saturating_mul(height), | ||
| 951 | }; | ||
| 952 | |||
| 953 | match dir { | ||
| 954 | MoveDir2D::Up => { | ||
| 955 | let first_key = info.messages.first_key_value().map(|f| f.0.clone()); | ||
| 956 | |||
| 957 | for (key, item) in info.messages.range(..=&corner_key).rev() { | ||
| 958 | let sel = key == cursor_key; | ||
| 959 | let txt = item.show(sel, &self.viewctx); | ||
| 960 | let len = txt.height().max(1); | ||
| 961 | let max = len.saturating_sub(1); | ||
| 962 | |||
| 963 | if key != &corner_key { | ||
| 964 | corner.text_row = max; | ||
| 965 | } | ||
| 966 | |||
| 967 | corner.timestamp = key.clone().into(); | ||
| 968 | |||
| 969 | if rows == 0 { | ||
| 970 | break; | ||
| 971 | } else if corner.text_row >= rows { | ||
| 972 | corner.text_row -= rows; | ||
| 973 | break; | ||
| 974 | } else if corner.timestamp == first_key { | ||
| 975 | corner.text_row = 0; | ||
| 976 | break; | ||
| 977 | } | ||
| 978 | |||
| 979 | rows -= corner.text_row + 1; | ||
| 980 | } | ||
| 981 | }, | ||
| 982 | MoveDir2D::Down => { | ||
| 983 | for (key, item) in info.messages.range(&corner_key..) { | ||
| 984 | let sel = key == cursor_key; | ||
| 985 | let txt = item.show(sel, &self.viewctx); | ||
| 986 | let len = txt.height().max(1); | ||
| 987 | let max = len.saturating_sub(1); | ||
| 988 | |||
| 989 | if key != &corner_key { | ||
| 990 | corner.text_row = 0; | ||
| 991 | } | ||
| 992 | |||
| 993 | corner.timestamp = key.clone().into(); | ||
| 994 | |||
| 995 | if rows == 0 { | ||
| 996 | break; | ||
| 997 | } else if key == last_key { | ||
| 998 | corner.text_row = corner.text_row.saturating_add(rows).min(max); | ||
| 999 | break; | ||
| 1000 | } else if corner.text_row >= max { | ||
| 1001 | rows -= 1; | ||
| 1002 | continue; | ||
| 1003 | } else if corner.text_row + rows <= max { | ||
| 1004 | corner.text_row += rows; | ||
| 1005 | break; | ||
| 1006 | } else { | ||
| 1007 | rows -= len - corner.text_row; | ||
| 1008 | continue; | ||
| 1009 | } | ||
| 1010 | } | ||
| 1011 | }, | ||
| 1012 | MoveDir2D::Left | MoveDir2D::Right => { | ||
| 1013 | let msg = "Cannot scroll vertically in message scrollback"; | ||
| 1014 | let err = EditError::Failure(msg.into()); | ||
| 1015 | |||
| 1016 | return Err(err); | ||
| 1017 | }, | ||
| 1018 | } | ||
| 1019 | |||
| 1020 | self.viewctx.corner = corner; | ||
| 1021 | self.shift_cursor(info); | ||
| 1022 | |||
| 1023 | Ok(None) | ||
| 1024 | } | ||
| 1025 | |||
| 1026 | fn cursorpos( | ||
| 1027 | &mut self, | ||
| 1028 | pos: MovePosition, | ||
| 1029 | axis: Axis, | ||
| 1030 | _: &ProgramContext, | ||
| 1031 | store: &mut ProgramStore, | ||
| 1032 | ) -> EditResult<EditInfo, IambInfo> { | ||
| 1033 | match axis { | ||
| 1034 | Axis::Horizontal => { | ||
| 1035 | let msg = "Cannot scroll vertically in message scrollback"; | ||
| 1036 | let err = EditError::Failure(msg.into()); | ||
| 1037 | |||
| 1038 | Err(err) | ||
| 1039 | }, | ||
| 1040 | Axis::Vertical => { | ||
| 1041 | let info = store.application.get_room_info(self.room_id.clone()); | ||
| 1042 | |||
| 1043 | if let Some(key) = self.cursor.to_key(info).cloned() { | ||
| 1044 | self.scrollview(key, pos, info); | ||
| 1045 | } | ||
| 1046 | |||
| 1047 | Ok(None) | ||
| 1048 | }, | ||
| 1049 | } | ||
| 1050 | } | ||
| 1051 | |||
| 1052 | fn linepos( | ||
| 1053 | &mut self, | ||
| 1054 | _: MovePosition, | ||
| 1055 | _: &Count, | ||
| 1056 | _: &ProgramContext, | ||
| 1057 | _: &mut ProgramStore, | ||
| 1058 | ) -> EditResult<EditInfo, IambInfo> { | ||
| 1059 | let msg = "Cannot scroll in message scrollback using line numbers"; | ||
| 1060 | let err = EditError::Failure(msg.into()); | ||
| 1061 | |||
| 1062 | Err(err) | ||
| 1063 | } | ||
| 1064 | } | ||
| 1065 | |||
| 1066 | impl Scrollable<ProgramContext, ProgramStore, IambInfo> for ScrollbackState { | ||
| 1067 | fn scroll( | ||
| 1068 | &mut self, | ||
| 1069 | style: &ScrollStyle, | ||
| 1070 | ctx: &ProgramContext, | ||
| 1071 | store: &mut ProgramStore, | ||
| 1072 | ) -> EditResult<EditInfo, IambInfo> { | ||
| 1073 | match style { | ||
| 1074 | ScrollStyle::Direction2D(dir, size, count) => { | ||
| 1075 | return self.dirscroll(*dir, *size, count, ctx, store); | ||
| 1076 | }, | ||
| 1077 | ScrollStyle::CursorPos(pos, axis) => { | ||
| 1078 | return self.cursorpos(*pos, *axis, ctx, store); | ||
| 1079 | }, | ||
| 1080 | ScrollStyle::LinePos(pos, count) => { | ||
| 1081 | return self.linepos(*pos, count, ctx, store); | ||
| 1082 | }, | ||
| 1083 | } | ||
| 1084 | } | ||
| 1085 | } | ||
| 1086 | |||
| 1087 | impl Searchable<ProgramContext, ProgramStore, IambInfo> for ScrollbackState { | ||
| 1088 | fn search( | ||
| 1089 | &mut self, | ||
| 1090 | dir: MoveDirMod, | ||
| 1091 | count: Count, | ||
| 1092 | ctx: &ProgramContext, | ||
| 1093 | store: &mut ProgramStore, | ||
| 1094 | ) -> UIResult<EditInfo, IambInfo> { | ||
| 1095 | let search = EditTarget::Search(SearchType::Regex, dir, count); | ||
| 1096 | |||
| 1097 | Ok(self.edit(&EditAction::Motion, &search, ctx, store)?) | ||
| 1098 | } | ||
| 1099 | } | ||
| 1100 | |||
| 1101 | impl TerminalCursor for ScrollbackState { | ||
| 1102 | fn get_term_cursor(&self) -> Option<(u16, u16)> { | ||
| 1103 | None | ||
| 1104 | } | ||
| 1105 | } | ||
| 1106 | |||
| 1107 | pub struct Scrollback<'a> { | ||
| 1108 | focused: bool, | ||
| 1109 | store: &'a mut ProgramStore, | ||
| 1110 | } | ||
| 1111 | |||
| 1112 | impl<'a> Scrollback<'a> { | ||
| 1113 | pub fn new(store: &'a mut ProgramStore) -> Self { | ||
| 1114 | Scrollback { focused: false, store } | ||
| 1115 | } | ||
| 1116 | |||
| 1117 | /// Indicate whether the scrollback is currently focused. | ||
| 1118 | pub fn focus(mut self, focused: bool) -> Self { | ||
| 1119 | self.focused = focused; | ||
| 1120 | self | ||
| 1121 | } | ||
| 1122 | } | ||
| 1123 | |||
| 1124 | impl<'a> StatefulWidget for Scrollback<'a> { | ||
| 1125 | type State = ScrollbackState; | ||
| 1126 | |||
| 1127 | fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) { | ||
| 1128 | state.set_term_info(area); | ||
| 1129 | |||
| 1130 | let height = state.viewctx.get_height(); | ||
| 1131 | |||
| 1132 | if height == 0 { | ||
| 1133 | return; | ||
| 1134 | } | ||
| 1135 | |||
| 1136 | if state.cursor.timestamp < state.viewctx.corner.timestamp { | ||
| 1137 | state.viewctx.corner = state.cursor.clone(); | ||
| 1138 | } | ||
| 1139 | |||
| 1140 | let info = self.store.application.get_room_info(state.room_id.clone()); | ||
| 1141 | |||
| 1142 | let cursor = &state.cursor; | ||
| 1143 | let cursor_key = if let Some(k) = cursor.to_key(info) { | ||
| 1144 | k | ||
| 1145 | } else { | ||
| 1146 | self.store.application.mark_for_load(state.room_id.clone()); | ||
| 1147 | return; | ||
| 1148 | }; | ||
| 1149 | |||
| 1150 | let corner = &state.viewctx.corner; | ||
| 1151 | let corner_key = match (&corner.timestamp, &cursor.timestamp) { | ||
| 1152 | (_, None) => nth_key_before(cursor_key.clone(), height, info), | ||
| 1153 | (None, _) => nth_key_before(cursor_key.clone(), height, info), | ||
| 1154 | (Some(k), _) => k.clone(), | ||
| 1155 | }; | ||
| 1156 | |||
| 1157 | let mut lines = vec![]; | ||
| 1158 | let mut sawit = false; | ||
| 1159 | |||
| 1160 | for (key, item) in info.messages.range(&corner_key..) { | ||
| 1161 | let sel = key == cursor_key; | ||
| 1162 | let txt = item.show(self.focused && sel, &state.viewctx); | ||
| 1163 | |||
| 1164 | for (row, line) in txt.lines.into_iter().enumerate() { | ||
| 1165 | if sawit && lines.len() >= height { | ||
| 1166 | // Check whether we've seen the first line of the | ||
| 1167 | // selected message and can fill the screen. | ||
| 1168 | break; | ||
| 1169 | } | ||
| 1170 | |||
| 1171 | if key == &corner_key && row < corner.text_row { | ||
| 1172 | // Skip rows above the viewport corner. | ||
| 1173 | continue; | ||
| 1174 | } | ||
| 1175 | |||
| 1176 | lines.push((key, row, line)); | ||
| 1177 | sawit |= sel; | ||
| 1178 | } | ||
| 1179 | } | ||
| 1180 | |||
| 1181 | if lines.len() > height { | ||
| 1182 | let n = lines.len() - height; | ||
| 1183 | let _ = lines.drain(..n); | ||
| 1184 | } | ||
| 1185 | |||
| 1186 | if let Some(((ts, event_id), row, _)) = lines.first() { | ||
| 1187 | state.viewctx.corner.timestamp = Some((*ts, event_id.clone())); | ||
| 1188 | state.viewctx.corner.text_row = *row; | ||
| 1189 | } | ||
| 1190 | |||
| 1191 | let mut y = area.top(); | ||
| 1192 | let x = area.left(); | ||
| 1193 | |||
| 1194 | for (_, _, txt) in lines.into_iter() { | ||
| 1195 | let _ = buf.set_spans(x, y, &txt, area.width); | ||
| 1196 | |||
| 1197 | y += 1; | ||
| 1198 | } | ||
| 1199 | |||
| 1200 | let first_key = info.messages.first_key_value().map(|f| f.0.clone()); | ||
| 1201 | if first_key == state.viewctx.corner.timestamp { | ||
| 1202 | // If the top of the screen is the older message, load more. | ||
| 1203 | self.store.application.mark_for_load(state.room_id.clone()); | ||
| 1204 | } | ||
| 1205 | } | ||
| 1206 | } | ||
| 1207 | |||
| 1208 | #[cfg(test)] | ||
| 1209 | mod tests { | ||
| 1210 | use super::*; | ||
| 1211 | use crate::tests::*; | ||
| 1212 | |||
| 1213 | #[test] | ||
| 1214 | fn test_search_messages() { | ||
| 1215 | let room_id = TEST_ROOM1_ID.clone(); | ||
| 1216 | let mut store = mock_store(); | ||
| 1217 | let mut scrollback = ScrollbackState::new(room_id.clone()); | ||
| 1218 | let ctx = ProgramContext::default(); | ||
| 1219 | |||
| 1220 | let next = MoveDirMod::Exact(MoveDir1D::Next); | ||
| 1221 | let prev = MoveDirMod::Exact(MoveDir1D::Previous); | ||
| 1222 | |||
| 1223 | // Search through the messages: | ||
| 1224 | // | ||
| 1225 | // MSG2: "helium" | ||
| 1226 | // MSG3: "this\nis\na\nmultiline\nmessage" | ||
| 1227 | // MSG4: "help" | ||
| 1228 | // MSG5: "character" | ||
| 1229 | // MSG1: "writhe" | ||
| 1230 | store.set_last_search("he"); | ||
| 1231 | |||
| 1232 | assert_eq!(scrollback.cursor, MessageCursor::latest()); | ||
| 1233 | |||
| 1234 | // Search backwards to MSG4. | ||
| 1235 | scrollback.search(prev.clone(), 1.into(), &ctx, &mut store).unwrap(); | ||
| 1236 | assert_eq!(scrollback.cursor, MSG4_KEY.clone().into()); | ||
| 1237 | |||
| 1238 | // Search backwards to MSG2. | ||
| 1239 | scrollback.search(prev.clone(), 1.into(), &ctx, &mut store).unwrap(); | ||
| 1240 | assert_eq!(scrollback.cursor, MSG2_KEY.clone().into()); | ||
| 1241 | assert_eq!(store.application.need_load.contains(&room_id), false); | ||
| 1242 | |||
| 1243 | // Can't go any further; need_load now contains the room ID. | ||
| 1244 | scrollback.search(prev.clone(), 1.into(), &ctx, &mut store).unwrap(); | ||
| 1245 | assert_eq!(scrollback.cursor, MSG2_KEY.clone().into()); | ||
| 1246 | assert_eq!(store.application.need_load.contains(&room_id), true); | ||
| 1247 | |||
| 1248 | // Search forward twice to MSG1. | ||
| 1249 | scrollback.search(next.clone(), 2.into(), &ctx, &mut store).unwrap(); | ||
| 1250 | assert_eq!(scrollback.cursor, MSG1_KEY.clone().into()); | ||
| 1251 | |||
| 1252 | // Can't go any further. | ||
| 1253 | scrollback.search(next.clone(), 2.into(), &ctx, &mut store).unwrap(); | ||
| 1254 | assert_eq!(scrollback.cursor, MSG1_KEY.clone().into()); | ||
| 1255 | } | ||
| 1256 | |||
| 1257 | #[test] | ||
| 1258 | fn test_movement() { | ||
| 1259 | let mut store = mock_store(); | ||
| 1260 | let mut scrollback = ScrollbackState::new(TEST_ROOM1_ID.clone()); | ||
| 1261 | let ctx = ProgramContext::default(); | ||
| 1262 | |||
| 1263 | let prev = |n: usize| EditTarget::Motion(MoveType::Line(MoveDir1D::Previous), n.into()); | ||
| 1264 | |||
| 1265 | let next = |n: usize| EditTarget::Motion(MoveType::Line(MoveDir1D::Next), n.into()); | ||
| 1266 | |||
| 1267 | assert_eq!(scrollback.cursor, MessageCursor::latest()); | ||
| 1268 | |||
| 1269 | scrollback.edit(&EditAction::Motion, &prev(1), &ctx, &mut store).unwrap(); | ||
| 1270 | assert_eq!(scrollback.cursor, MSG5_KEY.clone().into()); | ||
| 1271 | |||
| 1272 | scrollback.edit(&EditAction::Motion, &prev(2), &ctx, &mut store).unwrap(); | ||
| 1273 | assert_eq!(scrollback.cursor, MSG3_KEY.clone().into()); | ||
| 1274 | |||
| 1275 | scrollback.edit(&EditAction::Motion, &prev(5), &ctx, &mut store).unwrap(); | ||
| 1276 | assert_eq!(scrollback.cursor, MSG2_KEY.clone().into()); | ||
| 1277 | |||
| 1278 | scrollback.edit(&EditAction::Motion, &next(1), &ctx, &mut store).unwrap(); | ||
| 1279 | assert_eq!(scrollback.cursor, MSG3_KEY.clone().into()); | ||
| 1280 | |||
| 1281 | scrollback.edit(&EditAction::Motion, &next(1), &ctx, &mut store).unwrap(); | ||
| 1282 | assert_eq!(scrollback.cursor, MSG4_KEY.clone().into()); | ||
| 1283 | |||
| 1284 | scrollback.edit(&EditAction::Motion, &next(1), &ctx, &mut store).unwrap(); | ||
| 1285 | assert_eq!(scrollback.cursor, MSG5_KEY.clone().into()); | ||
| 1286 | |||
| 1287 | scrollback.edit(&EditAction::Motion, &next(1), &ctx, &mut store).unwrap(); | ||
| 1288 | assert_eq!(scrollback.cursor, MSG1_KEY.clone().into()); | ||
| 1289 | } | ||
| 1290 | |||
| 1291 | #[test] | ||
| 1292 | fn test_dirscroll() { | ||
| 1293 | let mut store = mock_store(); | ||
| 1294 | let mut scrollback = ScrollbackState::new(TEST_ROOM1_ID.clone()); | ||
| 1295 | let ctx = ProgramContext::default(); | ||
| 1296 | |||
| 1297 | let prev = MoveDir2D::Up; | ||
| 1298 | let next = MoveDir2D::Down; | ||
| 1299 | |||
| 1300 | assert_eq!(scrollback.cursor, MessageCursor::latest()); | ||
| 1301 | assert_eq!(scrollback.viewctx.dimensions, (0, 0)); | ||
| 1302 | assert_eq!(scrollback.viewctx.corner, MessageCursor::latest()); | ||
| 1303 | |||
| 1304 | // Set a terminal width of 60, and height of 3, rendering in scrollback as: | ||
| 1305 | // | ||
| 1306 | // |------------------------------------------------------------| | ||
| 1307 | // MSG2: | @user2:example.com helium | | ||
| 1308 | // MSG3: | @user2:example.com this | | ||
| 1309 | // | is | | ||
| 1310 | // | a | | ||
| 1311 | // | multiline | | ||
| 1312 | // | message | | ||
| 1313 | // MSG4: | @user1:example.com help | | ||
| 1314 | // MSG5: | @user2:example.com character | | ||
| 1315 | // MSG1: | @user1:example.com writhe | | ||
| 1316 | // |------------------------------------------------------------| | ||
| 1317 | let area = Rect::new(0, 0, 60, 3); | ||
| 1318 | let mut buffer = Buffer::empty(area); | ||
| 1319 | scrollback.draw(area, &mut buffer, true, &mut store); | ||
| 1320 | |||
| 1321 | assert_eq!(scrollback.cursor, MessageCursor::latest()); | ||
| 1322 | assert_eq!(scrollback.viewctx.dimensions, (60, 3)); | ||
| 1323 | assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG4_KEY.clone(), 0)); | ||
| 1324 | |||
| 1325 | // Scroll up a line at a time until we hit the first message. | ||
| 1326 | scrollback | ||
| 1327 | .dirscroll(prev, ScrollSize::Cell, &1.into(), &ctx, &mut store) | ||
| 1328 | .unwrap(); | ||
| 1329 | assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG3_KEY.clone(), 4)); | ||
| 1330 | |||
| 1331 | scrollback | ||
| 1332 | .dirscroll(prev, ScrollSize::Cell, &1.into(), &ctx, &mut store) | ||
| 1333 | .unwrap(); | ||
| 1334 | assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG3_KEY.clone(), 3)); | ||
| 1335 | |||
| 1336 | scrollback | ||
| 1337 | .dirscroll(prev, ScrollSize::Cell, &1.into(), &ctx, &mut store) | ||
| 1338 | .unwrap(); | ||
| 1339 | assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG3_KEY.clone(), 2)); | ||
| 1340 | |||
| 1341 | scrollback | ||
| 1342 | .dirscroll(prev, ScrollSize::Cell, &1.into(), &ctx, &mut store) | ||
| 1343 | .unwrap(); | ||
| 1344 | assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG3_KEY.clone(), 1)); | ||
| 1345 | |||
| 1346 | scrollback | ||
| 1347 | .dirscroll(prev, ScrollSize::Cell, &1.into(), &ctx, &mut store) | ||
| 1348 | .unwrap(); | ||
| 1349 | assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG3_KEY.clone(), 0)); | ||
| 1350 | |||
| 1351 | scrollback | ||
| 1352 | .dirscroll(prev, ScrollSize::Cell, &1.into(), &ctx, &mut store) | ||
| 1353 | .unwrap(); | ||
| 1354 | assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG2_KEY.clone(), 0)); | ||
| 1355 | |||
| 1356 | // Cannot scroll any further. | ||
| 1357 | scrollback | ||
| 1358 | .dirscroll(prev, ScrollSize::Cell, &1.into(), &ctx, &mut store) | ||
| 1359 | .unwrap(); | ||
| 1360 | assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG2_KEY.clone(), 0)); | ||
| 1361 | |||
| 1362 | // Now scroll back down one line at a time. | ||
| 1363 | scrollback | ||
| 1364 | .dirscroll(next, ScrollSize::Cell, &1.into(), &ctx, &mut store) | ||
| 1365 | .unwrap(); | ||
| 1366 | assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG3_KEY.clone(), 0)); | ||
| 1367 | |||
| 1368 | scrollback | ||
| 1369 | .dirscroll(next, ScrollSize::Cell, &1.into(), &ctx, &mut store) | ||
| 1370 | .unwrap(); | ||
| 1371 | assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG3_KEY.clone(), 1)); | ||
| 1372 | |||
| 1373 | scrollback | ||
| 1374 | .dirscroll(next, ScrollSize::Cell, &1.into(), &ctx, &mut store) | ||
| 1375 | .unwrap(); | ||
| 1376 | assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG3_KEY.clone(), 2)); | ||
| 1377 | |||
| 1378 | scrollback | ||
| 1379 | .dirscroll(next, ScrollSize::Cell, &1.into(), &ctx, &mut store) | ||
| 1380 | .unwrap(); | ||
| 1381 | assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG3_KEY.clone(), 3)); | ||
| 1382 | |||
| 1383 | scrollback | ||
| 1384 | .dirscroll(next, ScrollSize::Cell, &1.into(), &ctx, &mut store) | ||
| 1385 | .unwrap(); | ||
| 1386 | assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG3_KEY.clone(), 4)); | ||
| 1387 | |||
| 1388 | scrollback | ||
| 1389 | .dirscroll(next, ScrollSize::Cell, &1.into(), &ctx, &mut store) | ||
| 1390 | .unwrap(); | ||
| 1391 | assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG4_KEY.clone(), 0)); | ||
| 1392 | |||
| 1393 | scrollback | ||
| 1394 | .dirscroll(next, ScrollSize::Cell, &1.into(), &ctx, &mut store) | ||
| 1395 | .unwrap(); | ||
| 1396 | assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG5_KEY.clone(), 0)); | ||
| 1397 | |||
| 1398 | scrollback | ||
| 1399 | .dirscroll(next, ScrollSize::Cell, &1.into(), &ctx, &mut store) | ||
| 1400 | .unwrap(); | ||
| 1401 | assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG1_KEY.clone(), 0)); | ||
| 1402 | |||
| 1403 | // Cannot scroll down any further. | ||
| 1404 | scrollback | ||
| 1405 | .dirscroll(next, ScrollSize::Cell, &1.into(), &ctx, &mut store) | ||
| 1406 | .unwrap(); | ||
| 1407 | assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG1_KEY.clone(), 0)); | ||
| 1408 | |||
| 1409 | // Scroll up two Pages (six lines). | ||
| 1410 | scrollback | ||
| 1411 | .dirscroll(prev, ScrollSize::Page, &2.into(), &ctx, &mut store) | ||
| 1412 | .unwrap(); | ||
| 1413 | assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG3_KEY.clone(), 1)); | ||
| 1414 | |||
| 1415 | // Scroll down two HalfPages (three lines). | ||
| 1416 | scrollback | ||
| 1417 | .dirscroll(next, ScrollSize::HalfPage, &2.into(), &ctx, &mut store) | ||
| 1418 | .unwrap(); | ||
| 1419 | assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG3_KEY.clone(), 4)); | ||
| 1420 | } | ||
| 1421 | |||
| 1422 | #[test] | ||
| 1423 | fn test_cursorpos() { | ||
| 1424 | let mut store = mock_store(); | ||
| 1425 | let mut scrollback = ScrollbackState::new(TEST_ROOM1_ID.clone()); | ||
| 1426 | let ctx = ProgramContext::default(); | ||
| 1427 | |||
| 1428 | // Set a terminal width of 60, and height of 3, rendering in scrollback as: | ||
| 1429 | // | ||
| 1430 | // |------------------------------------------------------------| | ||
| 1431 | // MSG2: | @user2:example.com helium | | ||
| 1432 | // MSG3: | @user2:example.com this | | ||
| 1433 | // | is | | ||
| 1434 | // | a | | ||
| 1435 | // | multiline | | ||
| 1436 | // | message | | ||
| 1437 | // MSG4: | @user1:example.com help | | ||
| 1438 | // MSG5: | @user2:example.com character | | ||
| 1439 | // MSG1: | @user1:example.com writhe | | ||
| 1440 | // |------------------------------------------------------------| | ||
| 1441 | let area = Rect::new(0, 0, 60, 3); | ||
| 1442 | let mut buffer = Buffer::empty(area); | ||
| 1443 | scrollback.cursor = MSG4_KEY.clone().into(); | ||
| 1444 | scrollback.draw(area, &mut buffer, true, &mut store); | ||
| 1445 | |||
| 1446 | assert_eq!(scrollback.cursor, MSG4_KEY.clone().into()); | ||
| 1447 | assert_eq!(scrollback.viewctx.dimensions, (60, 3)); | ||
| 1448 | assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG3_KEY.clone(), 3)); | ||
| 1449 | |||
| 1450 | // Scroll so that the cursor is at the top of the screen. | ||
| 1451 | scrollback | ||
| 1452 | .cursorpos(MovePosition::Beginning, Axis::Vertical, &ctx, &mut store) | ||
| 1453 | .unwrap(); | ||
| 1454 | assert_eq!(scrollback.cursor, MSG4_KEY.clone().into()); | ||
| 1455 | assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG4_KEY.clone(), 0)); | ||
| 1456 | |||
| 1457 | // Scroll so that the cursor is at the bottom of the screen. | ||
| 1458 | scrollback | ||
| 1459 | .cursorpos(MovePosition::End, Axis::Vertical, &ctx, &mut store) | ||
| 1460 | .unwrap(); | ||
| 1461 | assert_eq!(scrollback.cursor, MSG4_KEY.clone().into()); | ||
| 1462 | assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG3_KEY.clone(), 3)); | ||
| 1463 | |||
| 1464 | // Scroll so that the cursor is in the middle of the screen. | ||
| 1465 | scrollback | ||
| 1466 | .cursorpos(MovePosition::Middle, Axis::Vertical, &ctx, &mut store) | ||
| 1467 | .unwrap(); | ||
| 1468 | assert_eq!(scrollback.cursor, MSG4_KEY.clone().into()); | ||
| 1469 | assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG3_KEY.clone(), 4)); | ||
| 1470 | } | ||
| 1471 | } | ||
src/windows/room/space.rs added +105
| @@ -0,0 +1,105 @@ | |||
| 1 | use std::ops::{Deref, DerefMut}; | ||
| 2 | |||
| 3 | use matrix_sdk::{ | ||
| 4 | room::Room as MatrixRoom, | ||
| 5 | ruma::{OwnedRoomId, RoomId}, | ||
| 6 | }; | ||
| 7 | |||
| 8 | use modalkit::tui::{buffer::Buffer, layout::Rect, widgets::StatefulWidget}; | ||
| 9 | |||
| 10 | use modalkit::{ | ||
| 11 | widgets::list::{List, ListState}, | ||
| 12 | widgets::{TermOffset, TerminalCursor, WindowOps}, | ||
| 13 | }; | ||
| 14 | |||
| 15 | use crate::base::{IambBufferId, IambInfo, ProgramStore, RoomFocus}; | ||
| 16 | |||
| 17 | use crate::windows::RoomItem; | ||
| 18 | |||
| 19 | pub struct SpaceState { | ||
| 20 | room_id: OwnedRoomId, | ||
| 21 | list: ListState<RoomItem, IambInfo>, | ||
| 22 | } | ||
| 23 | |||
| 24 | impl SpaceState { | ||
| 25 | pub fn new(room: MatrixRoom) -> Self { | ||
| 26 | let room_id = room.room_id().to_owned(); | ||
| 27 | let content = IambBufferId::Room(room_id.clone(), RoomFocus::Scrollback); | ||
| 28 | let list = ListState::new(content, vec![]); | ||
| 29 | |||
| 30 | SpaceState { room_id, list } | ||
| 31 | } | ||
| 32 | |||
| 33 | pub fn id(&self) -> &RoomId { | ||
| 34 | &self.room_id | ||
| 35 | } | ||
| 36 | |||
| 37 | pub fn dup(&self, store: &mut ProgramStore) -> Self { | ||
| 38 | SpaceState { | ||
| 39 | room_id: self.room_id.clone(), | ||
| 40 | list: self.list.dup(store), | ||
| 41 | } | ||
| 42 | } | ||
| 43 | } | ||
| 44 | |||
| 45 | impl TerminalCursor for SpaceState { | ||
| 46 | fn get_term_cursor(&self) -> Option<TermOffset> { | ||
| 47 | self.list.get_term_cursor() | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | impl Deref for SpaceState { | ||
| 52 | type Target = ListState<RoomItem, IambInfo>; | ||
| 53 | |||
| 54 | fn deref(&self) -> &Self::Target { | ||
| 55 | &self.list | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | impl DerefMut for SpaceState { | ||
| 60 | fn deref_mut(&mut self) -> &mut Self::Target { | ||
| 61 | &mut self.list | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | pub struct Space<'a> { | ||
| 66 | focused: bool, | ||
| 67 | store: &'a mut ProgramStore, | ||
| 68 | } | ||
| 69 | |||
| 70 | impl<'a> Space<'a> { | ||
| 71 | pub fn new(store: &'a mut ProgramStore) -> Self { | ||
| 72 | Space { focused: false, store } | ||
| 73 | } | ||
| 74 | |||
| 75 | pub fn focus(mut self, focused: bool) -> Self { | ||
| 76 | self.focused = focused; | ||
| 77 | self | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | impl<'a> StatefulWidget for Space<'a> { | ||
| 82 | type State = SpaceState; | ||
| 83 | |||
| 84 | fn render(self, area: Rect, buffer: &mut Buffer, state: &mut Self::State) { | ||
| 85 | let members = self.store.application.worker.space_members(state.room_id.clone()).unwrap(); | ||
| 86 | let items = members | ||
| 87 | .into_iter() | ||
| 88 | .filter_map(|id| { | ||
| 89 | let (room, name) = self.store.application.worker.get_room(id.clone()).ok()?; | ||
| 90 | |||
| 91 | if id != state.room_id { | ||
| 92 | Some(RoomItem::new(room, name, self.store)) | ||
| 93 | } else { | ||
| 94 | None | ||
| 95 | } | ||
| 96 | }) | ||
| 97 | .collect(); | ||
| 98 | |||
| 99 | state.list.set(items); | ||
| 100 | |||
| 101 | List::new(self.store) | ||
| 102 | .focus(self.focused) | ||
| 103 | .render(area, buffer, &mut state.list) | ||
| 104 | } | ||
| 105 | } | ||
src/windows/welcome.md added +44
| @@ -0,0 +1,44 @@ | |||
| 1 | # Welcome to iamb! | ||
| 2 | |||
| 3 | ## Useful Keybindings | ||
| 4 | |||
| 5 | - `<Enter>` will send a typed message | ||
| 6 | - `O`/`o` can be used to insert blank lines before and after the cursor line | ||
| 7 | - `^O` can be used in Insert mode to enter a single Normal mode keybinding sequence | ||
| 8 | - `^Wm` can be used to toggle whether the message bar or scrollback is selected | ||
| 9 | - `^Wz` can be used to toggle whether the current window takes up the full screen | ||
| 10 | |||
| 11 | ## Room Commands | ||
| 12 | |||
| 13 | - `:dms` will open a list of direct messages | ||
| 14 | - `:rooms` will open a list of joined rooms | ||
| 15 | - `:spaces` will open a list of joined spaces | ||
| 16 | - `:join` can be used to switch to join a new room or start a direct message | ||
| 17 | - `:split` and `:vsplit` can be used to open rooms in a new window | ||
| 18 | |||
| 19 | ## Verification Commands | ||
| 20 | |||
| 21 | The `:verify` command has several different subcommands for working with | ||
| 22 | verification requests. When used without any arguments, it will take you to a | ||
| 23 | list of current verifications, where you can see and compare the Emoji. | ||
| 24 | |||
| 25 | The different subcommands are: | ||
| 26 | |||
| 27 | - `:verify request USERNAME` will send a verification request to a user | ||
| 28 | - `:verify confirm USERNAME/DEVICE` will confirm a verification | ||
| 29 | - `:verify mismatch USERNAME/DEVICE` will cancel a verification where the Emoji don't match | ||
| 30 | - `:verify cancel USERNAME/DEVICE` will cancel a verification | ||
| 31 | |||
| 32 | ## Other Useful Commands | ||
| 33 | |||
| 34 | - `:welcome` will take you back to this screen | ||
| 35 | |||
| 36 | ## Additional Configuration | ||
| 37 | |||
| 38 | You can customize iamb in your `$CONFIG_DIR/iamb/config.json` file, where | ||
| 39 | `$CONFIG_DIR` is your system's per-user configuration directory. | ||
| 40 | |||
| 41 | You can edit the following values in the file: | ||
| 42 | |||
| 43 | - `"default_profile"`, a profile name to use when starting iamb if one wasn't specified | ||
| 44 | - `"cache"`, a directory for cached iamb | ||
src/windows/welcome.rs added +71
| @@ -0,0 +1,71 @@ | |||
| 1 | use std::ops::{Deref, DerefMut}; | ||
| 2 | |||
| 3 | use modalkit::tui::{buffer::Buffer, layout::Rect}; | ||
| 4 | |||
| 5 | use modalkit::{ | ||
| 6 | widgets::textbox::TextBoxState, | ||
| 7 | widgets::WindowOps, | ||
| 8 | widgets::{TermOffset, TerminalCursor}, | ||
| 9 | }; | ||
| 10 | |||
| 11 | use modalkit::editing::base::{CloseFlags, WordStyle}; | ||
| 12 | |||
| 13 | use crate::base::{IambBufferId, IambInfo, ProgramStore}; | ||
| 14 | |||
| 15 | const WELCOME_TEXT: &str = include_str!("welcome.md"); | ||
| 16 | |||
| 17 | pub struct WelcomeState { | ||
| 18 | tbox: TextBoxState<IambInfo>, | ||
| 19 | } | ||
| 20 | |||
| 21 | impl WelcomeState { | ||
| 22 | pub fn new(store: &mut ProgramStore) -> Self { | ||
| 23 | let buf = store.buffers.load_str(IambBufferId::Welcome, WELCOME_TEXT); | ||
| 24 | |||
| 25 | WelcomeState { tbox: TextBoxState::new(buf) } | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | impl Deref for WelcomeState { | ||
| 30 | type Target = TextBoxState<IambInfo>; | ||
| 31 | |||
| 32 | fn deref(&self) -> &Self::Target { | ||
| 33 | return &self.tbox; | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | impl DerefMut for WelcomeState { | ||
| 38 | fn deref_mut(&mut self) -> &mut Self::Target { | ||
| 39 | return &mut self.tbox; | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | impl TerminalCursor for WelcomeState { | ||
| 44 | fn get_term_cursor(&self) -> Option<TermOffset> { | ||
| 45 | self.tbox.get_term_cursor() | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | impl WindowOps<IambInfo> for WelcomeState { | ||
| 50 | fn draw(&mut self, area: Rect, buf: &mut Buffer, focused: bool, store: &mut ProgramStore) { | ||
| 51 | self.tbox.draw(area, buf, focused, store) | ||
| 52 | } | ||
| 53 | |||
| 54 | fn dup(&self, store: &mut ProgramStore) -> Self { | ||
| 55 | let tbox = self.tbox.dup(store); | ||
| 56 | |||
| 57 | WelcomeState { tbox } | ||
| 58 | } | ||
| 59 | |||
| 60 | fn close(&mut self, flags: CloseFlags, store: &mut ProgramStore) -> bool { | ||
| 61 | self.tbox.close(flags, store) | ||
| 62 | } | ||
| 63 | |||
| 64 | fn get_cursor_word(&self, style: &WordStyle) -> Option<String> { | ||
| 65 | self.tbox.get_cursor_word(style) | ||
| 66 | } | ||
| 67 | |||
| 68 | fn get_selected_word(&self) -> Option<String> { | ||
| 69 | self.tbox.get_selected_word() | ||
| 70 | } | ||
| 71 | } | ||
src/worker.rs added +813
| @@ -0,0 +1,813 @@ | |||
| 1 | use std::convert::TryFrom; | ||
| 2 | use std::fs::File; | ||
| 3 | use std::io::BufWriter; | ||
| 4 | use std::str::FromStr; | ||
| 5 | use std::sync::mpsc::{sync_channel, Receiver, RecvTimeoutError, SyncSender}; | ||
| 6 | use std::sync::Arc; | ||
| 7 | use std::time::Duration; | ||
| 8 | |||
| 9 | use gethostname::gethostname; | ||
| 10 | use tokio::task::JoinHandle; | ||
| 11 | use tracing::error; | ||
| 12 | |||
| 13 | use matrix_sdk::{ | ||
| 14 | config::{RequestConfig, StoreConfig, SyncSettings}, | ||
| 15 | encryption::verification::{SasVerification, Verification}, | ||
| 16 | event_handler::Ctx, | ||
| 17 | reqwest, | ||
| 18 | room::{Messages, MessagesOptions, Room as MatrixRoom}, | ||
| 19 | ruma::{ | ||
| 20 | api::client::{ | ||
| 21 | room::create_room::v3::{Request as CreateRoomRequest, RoomPreset}, | ||
| 22 | room::Visibility, | ||
| 23 | space::get_hierarchy::v1::Request as SpaceHierarchyRequest, | ||
| 24 | }, | ||
| 25 | events::{ | ||
| 26 | key::verification::{ | ||
| 27 | done::{OriginalSyncKeyVerificationDoneEvent, ToDeviceKeyVerificationDoneEvent}, | ||
| 28 | key::{OriginalSyncKeyVerificationKeyEvent, ToDeviceKeyVerificationKeyEvent}, | ||
| 29 | request::ToDeviceKeyVerificationRequestEvent, | ||
| 30 | start::{OriginalSyncKeyVerificationStartEvent, ToDeviceKeyVerificationStartEvent}, | ||
| 31 | VerificationMethod, | ||
| 32 | }, | ||
| 33 | room::message::{MessageType, RoomMessageEventContent, TextMessageEventContent}, | ||
| 34 | room::name::RoomNameEventContent, | ||
| 35 | AnyMessageLikeEvent, | ||
| 36 | AnyTimelineEvent, | ||
| 37 | SyncMessageLikeEvent, | ||
| 38 | SyncStateEvent, | ||
| 39 | }, | ||
| 40 | OwnedEventId, | ||
| 41 | OwnedRoomId, | ||
| 42 | OwnedRoomOrAliasId, | ||
| 43 | OwnedUserId, | ||
| 44 | }, | ||
| 45 | Client, | ||
| 46 | DisplayName, | ||
| 47 | Session, | ||
| 48 | }; | ||
| 49 | |||
| 50 | use modalkit::editing::action::{EditInfo, InfoMessage, UIError}; | ||
| 51 | |||
| 52 | use crate::{ | ||
| 53 | base::{AsyncProgramStore, IambError, IambResult, VerifyAction}, | ||
| 54 | message::{Message, MessageFetchResult, MessageTimeStamp}, | ||
| 55 | ApplicationSettings, | ||
| 56 | }; | ||
| 57 | |||
| 58 | const IAMB_DEVICE_NAME: &str = "iamb"; | ||
| 59 | const IAMB_USER_AGENT: &str = "iamb"; | ||
| 60 | const REQ_TIMEOUT: Duration = Duration::from_secs(60); | ||
| 61 | |||
| 62 | fn initial_devname() -> String { | ||
| 63 | format!("{} on {}", IAMB_DEVICE_NAME, gethostname().to_string_lossy()) | ||
| 64 | } | ||
| 65 | |||
| 66 | pub enum LoginStyle { | ||
| 67 | SessionRestore(Session), | ||
| 68 | Password(String), | ||
| 69 | } | ||
| 70 | |||
| 71 | pub struct ClientResponse<T>(Receiver<T>); | ||
| 72 | pub struct ClientReply<T>(SyncSender<T>); | ||
| 73 | |||
| 74 | impl<T> ClientResponse<T> { | ||
| 75 | fn recv(self) -> T { | ||
| 76 | self.0.recv().expect("failed to receive response from client thread") | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | impl<T> ClientReply<T> { | ||
| 81 | fn send(self, t: T) { | ||
| 82 | self.0.send(t).unwrap(); | ||
| 83 | } | ||
| 84 | } | ||
| 85 | |||
| 86 | fn oneshot<T>() -> (ClientReply<T>, ClientResponse<T>) { | ||
| 87 | let (tx, rx) = sync_channel(1); | ||
| 88 | let reply = ClientReply(tx); | ||
| 89 | let response = ClientResponse(rx); | ||
| 90 | |||
| 91 | return (reply, response); | ||
| 92 | } | ||
| 93 | |||
| 94 | type EchoPair = (OwnedEventId, RoomMessageEventContent); | ||
| 95 | |||
| 96 | pub enum WorkerTask { | ||
| 97 | DirectMessages(ClientReply<Vec<(MatrixRoom, DisplayName)>>), | ||
| 98 | Init(AsyncProgramStore, ClientReply<()>), | ||
| 99 | LoadOlder(OwnedRoomId, Option<String>, u32, ClientReply<MessageFetchResult>), | ||
| 100 | Login(LoginStyle, ClientReply<IambResult<EditInfo>>), | ||
| 101 | GetRoom(OwnedRoomId, ClientReply<IambResult<(MatrixRoom, DisplayName)>>), | ||
| 102 | JoinRoom(String, ClientReply<IambResult<OwnedRoomId>>), | ||
| 103 | JoinedRooms(ClientReply<Vec<(MatrixRoom, DisplayName)>>), | ||
| 104 | SpaceMembers(OwnedRoomId, ClientReply<IambResult<Vec<OwnedRoomId>>>), | ||
| 105 | Spaces(ClientReply<Vec<(MatrixRoom, DisplayName)>>), | ||
| 106 | SendMessage(OwnedRoomId, String, ClientReply<IambResult<EchoPair>>), | ||
| 107 | Verify(VerifyAction, SasVerification, ClientReply<IambResult<EditInfo>>), | ||
| 108 | VerifyRequest(OwnedUserId, ClientReply<IambResult<EditInfo>>), | ||
| 109 | } | ||
| 110 | |||
| 111 | #[derive(Clone)] | ||
| 112 | pub struct Requester { | ||
| 113 | pub tx: SyncSender<WorkerTask>, | ||
| 114 | } | ||
| 115 | |||
| 116 | impl Requester { | ||
| 117 | pub fn init(&self, store: AsyncProgramStore) { | ||
| 118 | let (reply, response) = oneshot(); | ||
| 119 | |||
| 120 | self.tx.send(WorkerTask::Init(store, reply)).unwrap(); | ||
| 121 | |||
| 122 | return response.recv(); | ||
| 123 | } | ||
| 124 | |||
| 125 | pub fn load_older( | ||
| 126 | &self, | ||
| 127 | room_id: OwnedRoomId, | ||
| 128 | fetch_id: Option<String>, | ||
| 129 | limit: u32, | ||
| 130 | ) -> MessageFetchResult { | ||
| 131 | let (reply, response) = oneshot(); | ||
| 132 | |||
| 133 | self.tx | ||
| 134 | .send(WorkerTask::LoadOlder(room_id, fetch_id, limit, reply)) | ||
| 135 | .unwrap(); | ||
| 136 | |||
| 137 | return response.recv(); | ||
| 138 | } | ||
| 139 | |||
| 140 | pub fn login(&self, style: LoginStyle) -> IambResult<EditInfo> { | ||
| 141 | let (reply, response) = oneshot(); | ||
| 142 | |||
| 143 | self.tx.send(WorkerTask::Login(style, reply)).unwrap(); | ||
| 144 | |||
| 145 | return response.recv(); | ||
| 146 | } | ||
| 147 | |||
| 148 | pub fn send_message(&self, room_id: OwnedRoomId, msg: String) -> IambResult<EchoPair> { | ||
| 149 | let (reply, response) = oneshot(); | ||
| 150 | |||
| 151 | self.tx.send(WorkerTask::SendMessage(room_id, msg, reply)).unwrap(); | ||
| 152 | |||
| 153 | return response.recv(); | ||
| 154 | } | ||
| 155 | |||
| 156 | pub fn direct_messages(&self) -> Vec<(MatrixRoom, DisplayName)> { | ||
| 157 | let (reply, response) = oneshot(); | ||
| 158 | |||
| 159 | self.tx.send(WorkerTask::DirectMessages(reply)).unwrap(); | ||
| 160 | |||
| 161 | return response.recv(); | ||
| 162 | } | ||
| 163 | |||
| 164 | pub fn get_room(&self, room_id: OwnedRoomId) -> IambResult<(MatrixRoom, DisplayName)> { | ||
| 165 | let (reply, response) = oneshot(); | ||
| 166 | |||
| 167 | self.tx.send(WorkerTask::GetRoom(room_id, reply)).unwrap(); | ||
| 168 | |||
| 169 | return response.recv(); | ||
| 170 | } | ||
| 171 | |||
| 172 | pub fn join_room(&self, name: String) -> IambResult<OwnedRoomId> { | ||
| 173 | let (reply, response) = oneshot(); | ||
| 174 | |||
| 175 | self.tx.send(WorkerTask::JoinRoom(name, reply)).unwrap(); | ||
| 176 | |||
| 177 | return response.recv(); | ||
| 178 | } | ||
| 179 | |||
| 180 | pub fn joined_rooms(&self) -> Vec<(MatrixRoom, DisplayName)> { | ||
| 181 | let (reply, response) = oneshot(); | ||
| 182 | |||
| 183 | self.tx.send(WorkerTask::JoinedRooms(reply)).unwrap(); | ||
| 184 | |||
| 185 | return response.recv(); | ||
| 186 | } | ||
| 187 | |||
| 188 | pub fn space_members(&self, space: OwnedRoomId) -> IambResult<Vec<OwnedRoomId>> { | ||
| 189 | let (reply, response) = oneshot(); | ||
| 190 | |||
| 191 | self.tx.send(WorkerTask::SpaceMembers(space, reply)).unwrap(); | ||
| 192 | |||
| 193 | return response.recv(); | ||
| 194 | } | ||
| 195 | |||
| 196 | pub fn spaces(&self) -> Vec<(MatrixRoom, DisplayName)> { | ||
| 197 | let (reply, response) = oneshot(); | ||
| 198 | |||
| 199 | self.tx.send(WorkerTask::Spaces(reply)).unwrap(); | ||
| 200 | |||
| 201 | return response.recv(); | ||
| 202 | } | ||
| 203 | |||
| 204 | pub fn verify(&self, act: VerifyAction, sas: SasVerification) -> IambResult<EditInfo> { | ||
| 205 | let (reply, response) = oneshot(); | ||
| 206 | |||
| 207 | self.tx.send(WorkerTask::Verify(act, sas, reply)).unwrap(); | ||
| 208 | |||
| 209 | return response.recv(); | ||
| 210 | } | ||
| 211 | |||
| 212 | pub fn verify_request(&self, user_id: OwnedUserId) -> IambResult<EditInfo> { | ||
| 213 | let (reply, response) = oneshot(); | ||
| 214 | |||
| 215 | self.tx.send(WorkerTask::VerifyRequest(user_id, reply)).unwrap(); | ||
| 216 | |||
| 217 | return response.recv(); | ||
| 218 | } | ||
| 219 | } | ||
| 220 | |||
| 221 | pub struct ClientWorker { | ||
| 222 | initialized: bool, | ||
| 223 | settings: ApplicationSettings, | ||
| 224 | client: Client, | ||
| 225 | sync_handle: Option<JoinHandle<()>>, | ||
| 226 | } | ||
| 227 | |||
| 228 | impl ClientWorker { | ||
| 229 | pub fn spawn(settings: ApplicationSettings) -> Requester { | ||
| 230 | let (tx, rx) = sync_channel(5); | ||
| 231 | |||
| 232 | let _ = tokio::spawn(async move { | ||
| 233 | let account = &settings.profile; | ||
| 234 | |||
| 235 | // Set up a custom client that only uses HTTP/1. | ||
| 236 | // | ||
| 237 | // During my testing, I kept stumbling across something weird with sync and HTTP/2 that | ||
| 238 | // will need to be revisited in the future. | ||
| 239 | let http = reqwest::Client::builder() | ||
| 240 | .user_agent(IAMB_USER_AGENT) | ||
| 241 | .timeout(Duration::from_secs(60)) | ||
| 242 | .pool_idle_timeout(Duration::from_secs(120)) | ||
| 243 | .pool_max_idle_per_host(5) | ||
| 244 | .http1_only() | ||
| 245 | .build() | ||
| 246 | .unwrap(); | ||
| 247 | |||
| 248 | // Set up the Matrix client for the selected profile. | ||
| 249 | let client = Client::builder() | ||
| 250 | .http_client(Arc::new(http)) | ||
| 251 | .homeserver_url(account.url.clone()) | ||
| 252 | .store_config(StoreConfig::default()) | ||
| 253 | .sled_store(settings.matrix_dir.as_path(), None) | ||
| 254 | .expect("Failed to setup up sled store for Matrix SDK") | ||
| 255 | .request_config( | ||
| 256 | RequestConfig::new().timeout(REQ_TIMEOUT).retry_timeout(REQ_TIMEOUT), | ||
| 257 | ) | ||
| 258 | .build() | ||
| 259 | .await | ||
| 260 | .expect("Failed to instantiate Matrix client"); | ||
| 261 | |||
| 262 | let mut worker = ClientWorker { | ||
| 263 | initialized: false, | ||
| 264 | settings, | ||
| 265 | client, | ||
| 266 | sync_handle: None, | ||
| 267 | }; | ||
| 268 | |||
| 269 | worker.work(rx).await; | ||
| 270 | }); | ||
| 271 | |||
| 272 | return Requester { tx }; | ||
| 273 | } | ||
| 274 | |||
| 275 | async fn work(&mut self, rx: Receiver<WorkerTask>) { | ||
| 276 | loop { | ||
| 277 | let t = rx.recv_timeout(Duration::from_secs(1)); | ||
| 278 | |||
| 279 | match t { | ||
| 280 | Ok(task) => self.run(task).await, | ||
| 281 | Err(RecvTimeoutError::Timeout) => {}, | ||
| 282 | Err(RecvTimeoutError::Disconnected) => { | ||
| 283 | break; | ||
| 284 | }, | ||
| 285 | } | ||
| 286 | } | ||
| 287 | |||
| 288 | if let Some(handle) = self.sync_handle.take() { | ||
| 289 | handle.abort(); | ||
| 290 | } | ||
| 291 | } | ||
| 292 | |||
| 293 | async fn run(&mut self, task: WorkerTask) { | ||
| 294 | match task { | ||
| 295 | WorkerTask::DirectMessages(reply) => { | ||
| 296 | assert!(self.initialized); | ||
| 297 | reply.send(self.direct_messages().await); | ||
| 298 | }, | ||
| 299 | WorkerTask::Init(store, reply) => { | ||
| 300 | assert_eq!(self.initialized, false); | ||
| 301 | self.init(store).await; | ||
| 302 | reply.send(()); | ||
| 303 | }, | ||
| 304 | WorkerTask::JoinRoom(room_id, reply) => { | ||
| 305 | assert!(self.initialized); | ||
| 306 | reply.send(self.join_room(room_id).await); | ||
| 307 | }, | ||
| 308 | WorkerTask::GetRoom(room_id, reply) => { | ||
| 309 | assert!(self.initialized); | ||
| 310 | reply.send(self.get_room(room_id).await); | ||
| 311 | }, | ||
| 312 | WorkerTask::JoinedRooms(reply) => { | ||
| 313 | assert!(self.initialized); | ||
| 314 | reply.send(self.joined_rooms().await); | ||
| 315 | }, | ||
| 316 | WorkerTask::LoadOlder(room_id, fetch_id, limit, reply) => { | ||
| 317 | assert!(self.initialized); | ||
| 318 | reply.send(self.load_older(room_id, fetch_id, limit).await); | ||
| 319 | }, | ||
| 320 | WorkerTask::Login(style, reply) => { | ||
| 321 | assert!(self.initialized); | ||
| 322 | reply.send(self.login_and_sync(style).await); | ||
| 323 | }, | ||
| 324 | WorkerTask::SpaceMembers(space, reply) => { | ||
| 325 | assert!(self.initialized); | ||
| 326 | reply.send(self.space_members(space).await); | ||
| 327 | }, | ||
| 328 | WorkerTask::Spaces(reply) => { | ||
| 329 | assert!(self.initialized); | ||
| 330 | reply.send(self.spaces().await); | ||
| 331 | }, | ||
| 332 | WorkerTask::SendMessage(room_id, msg, reply) => { | ||
| 333 | assert!(self.initialized); | ||
| 334 | reply.send(self.send_message(room_id, msg).await); | ||
| 335 | }, | ||
| 336 | WorkerTask::Verify(act, sas, reply) => { | ||
| 337 | assert!(self.initialized); | ||
| 338 | reply.send(self.verify(act, sas).await); | ||
| 339 | }, | ||
| 340 | WorkerTask::VerifyRequest(user_id, reply) => { | ||
| 341 | assert!(self.initialized); | ||
| 342 | reply.send(self.verify_request(user_id).await); | ||
| 343 | }, | ||
| 344 | } | ||
| 345 | } | ||
| 346 | |||
| 347 | async fn init(&mut self, store: AsyncProgramStore) { | ||
| 348 | self.client.add_event_handler_context(store); | ||
| 349 | |||
| 350 | let _ = self.client.add_event_handler( | ||
| 351 | |ev: SyncStateEvent<RoomNameEventContent>, | ||
| 352 | room: MatrixRoom, | ||
| 353 | store: Ctx<AsyncProgramStore>| { | ||
| 354 | async move { | ||
| 355 | if let SyncStateEvent::Original(ev) = ev { | ||
| 356 | if let Some(room_name) = ev.content.name { | ||
| 357 | let room_id = room.room_id().to_owned(); | ||
| 358 | let room_name = Some(room_name.to_string()); | ||
| 359 | let mut locked = store.lock().await; | ||
| 360 | let mut info = | ||
| 361 | locked.application.rooms.entry(room_id.to_owned()).or_default(); | ||
| 362 | info.name = room_name; | ||
| 363 | } | ||
| 364 | } | ||
| 365 | } | ||
| 366 | }, | ||
| 367 | ); | ||
| 368 | |||
| 369 | let _ = self.client.add_event_handler( | ||
| 370 | |ev: SyncMessageLikeEvent<RoomMessageEventContent>, | ||
| 371 | room: MatrixRoom, | ||
| 372 | client: Client, | ||
| 373 | store: Ctx<AsyncProgramStore>| { | ||
| 374 | async move { | ||
| 375 | let room_id = room.room_id(); | ||
| 376 | let room_name = room.display_name().await.ok(); | ||
| 377 | let room_name = room_name.as_ref().map(ToString::to_string); | ||
| 378 | |||
| 379 | if let Some(msg) = ev.as_original() { | ||
| 380 | if let MessageType::VerificationRequest(_) = msg.content.msgtype { | ||
| 381 | if let Some(request) = client | ||
| 382 | .encryption() | ||
| 383 | .get_verification_request(ev.sender(), ev.event_id()) | ||
| 384 | .await | ||
| 385 | { | ||
| 386 | request.accept().await.expect("Failed to accept request"); | ||
| 387 | } | ||
| 388 | } | ||
| 389 | } | ||
| 390 | |||
| 391 | let mut locked = store.lock().await; | ||
| 392 | let mut info = locked.application.get_room_info(room_id.to_owned()); | ||
| 393 | info.name = room_name; | ||
| 394 | |||
| 395 | let event_id = ev.event_id().to_owned(); | ||
| 396 | let key = (ev.origin_server_ts().into(), event_id.clone()); | ||
| 397 | let msg = Message::from(ev.into_full_event(room_id.to_owned())); | ||
| 398 | info.messages.insert(key, msg); | ||
| 399 | |||
| 400 | // Remove the echo. | ||
| 401 | let key = (MessageTimeStamp::LocalEcho, event_id); | ||
| 402 | let _ = info.messages.remove(&key); | ||
| 403 | } | ||
| 404 | }, | ||
| 405 | ); | ||
| 406 | |||
| 407 | let _ = self.client.add_event_handler( | ||
| 408 | |ev: OriginalSyncKeyVerificationStartEvent, | ||
| 409 | client: Client, | ||
| 410 | store: Ctx<AsyncProgramStore>| { | ||
| 411 | async move { | ||
| 412 | let tx_id = ev.content.relates_to.event_id.as_ref(); | ||
| 413 | |||
| 414 | if let Some(Verification::SasV1(sas)) = | ||
| 415 | client.encryption().get_verification(&ev.sender, tx_id).await | ||
| 416 | { | ||
| 417 | sas.accept().await.unwrap(); | ||
| 418 | |||
| 419 | store.lock().await.application.insert_sas(sas) | ||
| 420 | } | ||
| 421 | } | ||
| 422 | }, | ||
| 423 | ); | ||
| 424 | |||
| 425 | let _ = self.client.add_event_handler( | ||
| 426 | |ev: OriginalSyncKeyVerificationKeyEvent, | ||
| 427 | client: Client, | ||
| 428 | store: Ctx<AsyncProgramStore>| { | ||
| 429 | async move { | ||
| 430 | let tx_id = ev.content.relates_to.event_id.as_ref(); | ||
| 431 | |||
| 432 | if let Some(Verification::SasV1(sas)) = | ||
| 433 | client.encryption().get_verification(&ev.sender, tx_id).await | ||
| 434 | { | ||
| 435 | store.lock().await.application.insert_sas(sas); | ||
| 436 | } | ||
| 437 | } | ||
| 438 | }, | ||
| 439 | ); | ||
| 440 | |||
| 441 | let _ = self.client.add_event_handler( | ||
| 442 | |ev: OriginalSyncKeyVerificationDoneEvent, | ||
| 443 | client: Client, | ||
| 444 | store: Ctx<AsyncProgramStore>| { | ||
| 445 | async move { | ||
| 446 | let tx_id = ev.content.relates_to.event_id.as_ref(); | ||
| 447 | |||
| 448 | if let Some(Verification::SasV1(sas)) = | ||
| 449 | client.encryption().get_verification(&ev.sender, tx_id).await | ||
| 450 | { | ||
| 451 | store.lock().await.application.insert_sas(sas); | ||
| 452 | } | ||
| 453 | } | ||
| 454 | }, | ||
| 455 | ); | ||
| 456 | |||
| 457 | let _ = self.client.add_event_handler( | ||
| 458 | |ev: ToDeviceKeyVerificationRequestEvent, client: Client| { | ||
| 459 | async move { | ||
| 460 | let request = client | ||
| 461 | .encryption() | ||
| 462 | .get_verification_request(&ev.sender, &ev.content.transaction_id) | ||
| 463 | .await | ||
| 464 | .unwrap(); | ||
| 465 | |||
| 466 | request.accept().await.unwrap(); | ||
| 467 | } | ||
| 468 | }, | ||
| 469 | ); | ||
| 470 | |||
| 471 | let _ = self.client.add_event_handler( | ||
| 472 | |ev: ToDeviceKeyVerificationStartEvent, | ||
| 473 | client: Client, | ||
| 474 | store: Ctx<AsyncProgramStore>| { | ||
| 475 | async move { | ||
| 476 | let tx_id = ev.content.transaction_id; | ||
| 477 | |||
| 478 | if let Some(Verification::SasV1(sas)) = | ||
| 479 | client.encryption().get_verification(&ev.sender, tx_id.as_ref()).await | ||
| 480 | { | ||
| 481 | sas.accept().await.unwrap(); | ||
| 482 | |||
| 483 | store.lock().await.application.insert_sas(sas); | ||
| 484 | } | ||
| 485 | } | ||
| 486 | }, | ||
| 487 | ); | ||
| 488 | |||
| 489 | let _ = self.client.add_event_handler( | ||
| 490 | |ev: ToDeviceKeyVerificationKeyEvent, client: Client, store: Ctx<AsyncProgramStore>| { | ||
| 491 | async move { | ||
| 492 | let tx_id = ev.content.transaction_id; | ||
| 493 | |||
| 494 | if let Some(Verification::SasV1(sas)) = | ||
| 495 | client.encryption().get_verification(&ev.sender, tx_id.as_ref()).await | ||
| 496 | { | ||
| 497 | store.lock().await.application.insert_sas(sas); | ||
| 498 | } | ||
| 499 | } | ||
| 500 | }, | ||
| 501 | ); | ||
| 502 | |||
| 503 | let _ = self.client.add_event_handler( | ||
| 504 | |ev: ToDeviceKeyVerificationDoneEvent, | ||
| 505 | client: Client, | ||
| 506 | store: Ctx<AsyncProgramStore>| { | ||
| 507 | async move { | ||
| 508 | let tx_id = ev.content.transaction_id; | ||
| 509 | |||
| 510 | if let Some(Verification::SasV1(sas)) = | ||
| 511 | client.encryption().get_verification(&ev.sender, tx_id.as_ref()).await | ||
| 512 | { | ||
| 513 | store.lock().await.application.insert_sas(sas); | ||
| 514 | } | ||
| 515 | } | ||
| 516 | }, | ||
| 517 | ); | ||
| 518 | |||
| 519 | self.initialized = true; | ||
| 520 | } | ||
| 521 | |||
| 522 | async fn login_and_sync(&mut self, style: LoginStyle) -> IambResult<EditInfo> { | ||
| 523 | let client = self.client.clone(); | ||
| 524 | |||
| 525 | match style { | ||
| 526 | LoginStyle::SessionRestore(session) => { | ||
| 527 | client.restore_login(session).await.map_err(IambError::from)?; | ||
| 528 | }, | ||
| 529 | LoginStyle::Password(password) => { | ||
| 530 | let resp = client | ||
| 531 | .login_username(&self.settings.profile.user_id, &password) | ||
| 532 | .initial_device_display_name(initial_devname().as_str()) | ||
| 533 | .send() | ||
| 534 | .await | ||
| 535 | .map_err(IambError::from)?; | ||
| 536 | let file = File::create(self.settings.session_json.as_path())?; | ||
| 537 | let writer = BufWriter::new(file); | ||
| 538 | let session = Session::from(resp); | ||
| 539 | serde_json::to_writer(writer, &session).map_err(IambError::from)?; | ||
| 540 | }, | ||
| 541 | } | ||
| 542 | |||
| 543 | let handle = tokio::spawn(async move { | ||
| 544 | loop { | ||
| 545 | let settings = SyncSettings::default(); | ||
| 546 | |||
| 547 | let _ = client.sync(settings).await; | ||
| 548 | } | ||
| 549 | }); | ||
| 550 | |||
| 551 | self.sync_handle = Some(handle); | ||
| 552 | |||
| 553 | self.client | ||
| 554 | .sync_once(SyncSettings::default()) | ||
| 555 | .await | ||
| 556 | .map_err(IambError::from)?; | ||
| 557 | |||
| 558 | Ok(Some(InfoMessage::from("Successfully logged in!"))) | ||
| 559 | } | ||
| 560 | |||
| 561 | async fn send_message(&mut self, room_id: OwnedRoomId, msg: String) -> IambResult<EchoPair> { | ||
| 562 | let room = if let r @ Some(_) = self.client.get_joined_room(&room_id) { | ||
| 563 | r | ||
| 564 | } else if self.client.join_room_by_id(&room_id).await.is_ok() { | ||
| 565 | self.client.get_joined_room(&room_id) | ||
| 566 | } else { | ||
| 567 | None | ||
| 568 | }; | ||
| 569 | |||
| 570 | if let Some(room) = room { | ||
| 571 | let msg = TextMessageEventContent::plain(msg); | ||
| 572 | let msg = MessageType::Text(msg); | ||
| 573 | let msg = RoomMessageEventContent::new(msg); | ||
| 574 | |||
| 575 | // XXX: second parameter can be a locally unique transaction id. | ||
| 576 | // Useful for doing retries. | ||
| 577 | let resp = room.send(msg.clone(), None).await.map_err(IambError::from)?; | ||
| 578 | let event_id = resp.event_id; | ||
| 579 | |||
| 580 | // XXX: need to either give error messages and retry when needed! | ||
| 581 | |||
| 582 | return Ok((event_id, msg)); | ||
| 583 | } else { | ||
| 584 | Err(IambError::UnknownRoom(room_id).into()) | ||
| 585 | } | ||
| 586 | } | ||
| 587 | |||
| 588 | async fn direct_message(&mut self, user: OwnedUserId) -> IambResult<(MatrixRoom, DisplayName)> { | ||
| 589 | for (room, name) in self.direct_messages().await { | ||
| 590 | if room.get_member(user.as_ref()).await.map_err(IambError::from)?.is_some() { | ||
| 591 | return Ok((room, name)); | ||
| 592 | } | ||
| 593 | } | ||
| 594 | |||
| 595 | let mut request = CreateRoomRequest::new(); | ||
| 596 | let invite = [user.clone()]; | ||
| 597 | request.is_direct = true; | ||
| 598 | request.invite = &invite; | ||
| 599 | request.visibility = Visibility::Private; | ||
| 600 | request.preset = Some(RoomPreset::PrivateChat); | ||
| 601 | |||
| 602 | match self.client.create_room(request).await { | ||
| 603 | Ok(resp) => self.get_room(resp.room_id).await, | ||
| 604 | Err(e) => { | ||
| 605 | error!( | ||
| 606 | user_id = user.as_str(), | ||
| 607 | err = e.to_string(), | ||
| 608 | "Failed to create direct message room" | ||
| 609 | ); | ||
| 610 | |||
| 611 | let msg = format!("Could not open a room with {}", user); | ||
| 612 | let err = UIError::Failure(msg); | ||
| 613 | |||
| 614 | Err(err) | ||
| 615 | }, | ||
| 616 | } | ||
| 617 | } | ||
| 618 | |||
| 619 | async fn get_room(&mut self, room_id: OwnedRoomId) -> IambResult<(MatrixRoom, DisplayName)> { | ||
| 620 | if let Some(room) = self.client.get_room(&room_id) { | ||
| 621 | let name = room.display_name().await.map_err(IambError::from)?; | ||
| 622 | |||
| 623 | Ok((room, name)) | ||
| 624 | } else { | ||
| 625 | Err(IambError::UnknownRoom(room_id).into()) | ||
| 626 | } | ||
| 627 | } | ||
| 628 | |||
| 629 | async fn join_room(&mut self, name: String) -> IambResult<OwnedRoomId> { | ||
| 630 | if let Ok(alias_id) = OwnedRoomOrAliasId::from_str(name.as_str()) { | ||
| 631 | match self.client.join_room_by_id_or_alias(&alias_id, &[]).await { | ||
| 632 | Ok(resp) => Ok(resp.room_id), | ||
| 633 | Err(e) => { | ||
| 634 | let msg = e.to_string(); | ||
| 635 | let err = UIError::Failure(msg); | ||
| 636 | |||
| 637 | return Err(err); | ||
| 638 | }, | ||
| 639 | } | ||
| 640 | } else if let Ok(user) = OwnedUserId::try_from(name.as_str()) { | ||
| 641 | let room = self.direct_message(user).await?.0; | ||
| 642 | |||
| 643 | return Ok(room.room_id().to_owned()); | ||
| 644 | } else { | ||
| 645 | let msg = format!("{:?} is not a valid room or user name", name.as_str()); | ||
| 646 | let err = UIError::Failure(msg); | ||
| 647 | |||
| 648 | return Err(err); | ||
| 649 | } | ||
| 650 | } | ||
| 651 | |||
| 652 | async fn direct_messages(&mut self) -> Vec<(MatrixRoom, DisplayName)> { | ||
| 653 | let mut rooms = vec![]; | ||
| 654 | |||
| 655 | for room in self.client.joined_rooms().into_iter() { | ||
| 656 | if room.is_space() || !room.is_direct() { | ||
| 657 | continue; | ||
| 658 | } | ||
| 659 | |||
| 660 | if let Ok(name) = room.display_name().await { | ||
| 661 | rooms.push((MatrixRoom::from(room), name)) | ||
| 662 | } | ||
| 663 | } | ||
| 664 | |||
| 665 | return rooms; | ||
| 666 | } | ||
| 667 | |||
| 668 | async fn joined_rooms(&mut self) -> Vec<(MatrixRoom, DisplayName)> { | ||
| 669 | let mut rooms = vec![]; | ||
| 670 | |||
| 671 | for room in self.client.joined_rooms().into_iter() { | ||
| 672 | if room.is_space() || room.is_direct() { | ||
| 673 | continue; | ||
| 674 | } | ||
| 675 | |||
| 676 | if let Ok(name) = room.display_name().await { | ||
| 677 | rooms.push((MatrixRoom::from(room), name)) | ||
| 678 | } | ||
| 679 | } | ||
| 680 | |||
| 681 | return rooms; | ||
| 682 | } | ||
| 683 | |||
| 684 | async fn load_older( | ||
| 685 | &mut self, | ||
| 686 | room_id: OwnedRoomId, | ||
| 687 | fetch_id: Option<String>, | ||
| 688 | limit: u32, | ||
| 689 | ) -> MessageFetchResult { | ||
| 690 | if let Some(room) = self.client.get_room(room_id.as_ref()) { | ||
| 691 | let mut opts = match &fetch_id { | ||
| 692 | Some(id) => MessagesOptions::backward().from(id.as_str()), | ||
| 693 | None => MessagesOptions::backward(), | ||
| 694 | }; | ||
| 695 | opts.limit = limit.into(); | ||
| 696 | |||
| 697 | let Messages { end, chunk, .. } = room.messages(opts).await.map_err(IambError::from)?; | ||
| 698 | |||
| 699 | let msgs = chunk.into_iter().filter_map(|ev| { | ||
| 700 | match ev.event.deserialize() { | ||
| 701 | Ok(AnyTimelineEvent::MessageLike(msg)) => { | ||
| 702 | if let AnyMessageLikeEvent::RoomMessage(msg) = msg { | ||
| 703 | Some(msg) | ||
| 704 | } else { | ||
| 705 | None | ||
| 706 | } | ||
| 707 | }, | ||
| 708 | Ok(AnyTimelineEvent::State(_)) => None, | ||
| 709 | Err(_) => None, | ||
| 710 | } | ||
| 711 | }); | ||
| 712 | |||
| 713 | Ok((end, msgs.collect())) | ||
| 714 | } else { | ||
| 715 | Err(IambError::UnknownRoom(room_id).into()) | ||
| 716 | } | ||
| 717 | } | ||
| 718 | |||
| 719 | async fn space_members(&mut self, space: OwnedRoomId) -> IambResult<Vec<OwnedRoomId>> { | ||
| 720 | let mut req = SpaceHierarchyRequest::new(&space); | ||
| 721 | req.limit = Some(1000u32.into()); | ||
| 722 | req.max_depth = Some(1u32.into()); | ||
| 723 | |||
| 724 | let resp = self.client.send(req, None).await.map_err(IambError::from)?; | ||
| 725 | |||
| 726 | let rooms = resp.rooms.into_iter().map(|chunk| chunk.room_id).collect(); | ||
| 727 | |||
| 728 | Ok(rooms) | ||
| 729 | } | ||
| 730 | |||
| 731 | async fn spaces(&mut self) -> Vec<(MatrixRoom, DisplayName)> { | ||
| 732 | let mut spaces = vec![]; | ||
| 733 | |||
| 734 | for room in self.client.joined_rooms().into_iter() { | ||
| 735 | if !room.is_space() { | ||
| 736 | continue; | ||
| 737 | } | ||
| 738 | |||
| 739 | if let Ok(name) = room.display_name().await { | ||
| 740 | spaces.push((MatrixRoom::from(room), name)); | ||
| 741 | } | ||
| 742 | } | ||
| 743 | |||
| 744 | return spaces; | ||
| 745 | } | ||
| 746 | |||
| 747 | async fn verify(&self, action: VerifyAction, sas: SasVerification) -> IambResult<EditInfo> { | ||
| 748 | match action { | ||
| 749 | VerifyAction::Accept => { | ||
| 750 | sas.accept().await.map_err(IambError::from)?; | ||
| 751 | |||
| 752 | Ok(Some(InfoMessage::from("Accepted verification request"))) | ||
| 753 | }, | ||
| 754 | VerifyAction::Confirm => { | ||
| 755 | if sas.is_done() || sas.is_cancelled() { | ||
| 756 | let msg = "Can only confirm in-progress verifications!"; | ||
| 757 | let err = UIError::Failure(msg.into()); | ||
| 758 | |||
| 759 | return Err(err); | ||
| 760 | } | ||
| 761 | |||
| 762 | sas.confirm().await.map_err(IambError::from)?; | ||
| 763 | |||
| 764 | Ok(Some(InfoMessage::from("Confirmed verification"))) | ||
| 765 | }, | ||
| 766 | VerifyAction::Cancel => { | ||
| 767 | if sas.is_done() || sas.is_cancelled() { | ||
| 768 | let msg = "Can only cancel in-progress verifications!"; | ||
| 769 | let err = UIError::Failure(msg.into()); | ||
| 770 | |||
| 771 | return Err(err); | ||
| 772 | } | ||
| 773 | |||
| 774 | sas.cancel().await.map_err(IambError::from)?; | ||
| 775 | |||
| 776 | Ok(Some(InfoMessage::from("Cancelled verification"))) | ||
| 777 | }, | ||
| 778 | VerifyAction::Mismatch => { | ||
| 779 | if sas.is_done() || sas.is_cancelled() { | ||
| 780 | let msg = "Can only cancel in-progress verifications!"; | ||
| 781 | let err = UIError::Failure(msg.into()); | ||
| 782 | |||
| 783 | return Err(err); | ||
| 784 | } | ||
| 785 | |||
| 786 | sas.mismatch().await.map_err(IambError::from)?; | ||
| 787 | |||
| 788 | Ok(Some(InfoMessage::from("Cancelled verification"))) | ||
| 789 | }, | ||
| 790 | } | ||
| 791 | } | ||
| 792 | |||
| 793 | async fn verify_request(&self, user_id: OwnedUserId) -> IambResult<EditInfo> { | ||
| 794 | let enc = self.client.encryption(); | ||
| 795 | |||
| 796 | match enc.get_user_identity(user_id.as_ref()).await.map_err(IambError::from)? { | ||
| 797 | Some(identity) => { | ||
| 798 | let methods = vec![VerificationMethod::SasV1]; | ||
| 799 | let request = identity.request_verification_with_methods(methods); | ||
| 800 | let _req = request.await.map_err(IambError::from)?; | ||
| 801 | let info = format!("Sent verification request to {}", user_id); | ||
| 802 | |||
| 803 | Ok(InfoMessage::from(info).into()) | ||
| 804 | }, | ||
| 805 | None => { | ||
| 806 | let msg = format!("Could not find identity information for {}", user_id); | ||
| 807 | let err = UIError::Failure(msg); | ||
| 808 | |||
| 809 | Err(err) | ||
| 810 | }, | ||
| 811 | } | ||
| 812 | } | ||
| 813 | } | ||