Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69125e3fc4 | ||
|
|
56ec90523c | ||
|
|
d13d4b9f7f | ||
|
|
54ce042384 | ||
|
|
b6f4b03c12 | ||
|
|
504b520fe1 |
224
Cargo.lock
generated
224
Cargo.lock
generated
@@ -54,9 +54,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.67"
|
||||
version = "1.0.68"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7724808837b77f4b4de9d283820f9d98bcf496d5692934b857a2399d31ff22e6"
|
||||
checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61"
|
||||
|
||||
[[package]]
|
||||
name = "anymap2"
|
||||
@@ -124,9 +124,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "async-trait"
|
||||
version = "0.1.60"
|
||||
version = "0.1.61"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "677d1d8ab452a3936018a687b20e6f7cf5363d713b732b8884001317b0e48aa3"
|
||||
checksum = "705339e0e4a9690e2908d2b3d049d85682cf19fbd5782494498fbf7003a6a282"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -168,6 +168,12 @@ version = "0.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.21.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a"
|
||||
|
||||
[[package]]
|
||||
name = "base64ct"
|
||||
version = "1.5.3"
|
||||
@@ -327,9 +333,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.0.29"
|
||||
version = "4.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4d63b9e9c07271b9957ad22c173bae2a4d9a81127680962039296abcd2f8251d"
|
||||
checksum = "aa91278560fc226a5d9d736cc21e485ff9aad47d26b8ffe1f54cba868b684b9f"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"clap_derive",
|
||||
@@ -342,9 +348,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.0.21"
|
||||
version = "4.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014"
|
||||
checksum = "684a277d672e91966334af371f1a7b5833f9aa00b07c84e92fbce95e00208ce8"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro-error",
|
||||
@@ -355,9 +361,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8"
|
||||
checksum = "783fe232adfca04f90f56201b26d79682d4cd2625e0bc7290b95123afe558ade"
|
||||
dependencies = [
|
||||
"os_str_bytes",
|
||||
]
|
||||
@@ -506,9 +512,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cxx"
|
||||
version = "1.0.84"
|
||||
version = "1.0.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "27874566aca772cb515af4c6e997b5fe2119820bca447689145e39bb734d19a0"
|
||||
checksum = "51d1075c37807dcf850c379432f0df05ba52cc30f279c5cfc43cc221ce7f8579"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"cxxbridge-flags",
|
||||
@@ -518,9 +524,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cxx-build"
|
||||
version = "1.0.84"
|
||||
version = "1.0.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7bb951f2523a49533003656a72121306b225ec16a49a09dc6b0ba0d6f3ec3c0"
|
||||
checksum = "5044281f61b27bc598f2f6647d480aed48d2bf52d6eb0b627d84c0361b17aa70"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"codespan-reporting",
|
||||
@@ -533,15 +539,15 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cxxbridge-flags"
|
||||
version = "1.0.84"
|
||||
version = "1.0.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be778b6327031c1c7b61dd2e48124eee5361e6aa76b8de93692f011b08870ab4"
|
||||
checksum = "61b50bc93ba22c27b0d31128d2d130a0a6b3d267ae27ef7e4fae2167dfe8781c"
|
||||
|
||||
[[package]]
|
||||
name = "cxxbridge-macro"
|
||||
version = "1.0.84"
|
||||
version = "1.0.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b8a2b87662fe5a0a0b38507756ab66aff32638876a0866e5a5fc82ceb07ee49"
|
||||
checksum = "39e61fda7e62115119469c7b3591fd913ecca96fb766cfd3f2e2502ab7bc87a5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -593,7 +599,7 @@ dependencies = [
|
||||
"hashbrown",
|
||||
"lock_api",
|
||||
"once_cell",
|
||||
"parking_lot_core 0.9.5",
|
||||
"parking_lot_core 0.9.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1019,15 +1025,6 @@ version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.2.6"
|
||||
@@ -1128,7 +1125,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "iamb"
|
||||
version = "0.0.1"
|
||||
version = "0.0.3"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"clap",
|
||||
@@ -1137,6 +1134,8 @@ dependencies = [
|
||||
"gethostname",
|
||||
"lazy_static",
|
||||
"matrix-sdk",
|
||||
"mime",
|
||||
"mime_guess",
|
||||
"modalkit",
|
||||
"regex",
|
||||
"rpassword",
|
||||
@@ -1251,9 +1250,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "io-lifetimes"
|
||||
version = "1.0.3"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c"
|
||||
checksum = "e7d6c6f8c91b4b9ed43484ad1a938e393caf35960fce7f82a040497207bd8e9e"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys",
|
||||
@@ -1261,17 +1260,17 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ipnet"
|
||||
version = "2.7.0"
|
||||
version = "2.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "11b0d96e660696543b251e58030cf9787df56da39dab19ad60eae7353040917e"
|
||||
checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146"
|
||||
|
||||
[[package]]
|
||||
name = "is-terminal"
|
||||
version = "0.4.1"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "927609f78c2913a6f6ac3c27a4fe87f43e2a35367c0c4b0f8265e8f49a104330"
|
||||
checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189"
|
||||
dependencies = [
|
||||
"hermit-abi 0.2.6",
|
||||
"hermit-abi",
|
||||
"io-lifetimes",
|
||||
"rustix",
|
||||
"windows-sys",
|
||||
@@ -1327,9 +1326,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.138"
|
||||
version = "0.2.139"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8"
|
||||
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
|
||||
|
||||
[[package]]
|
||||
name = "link-cplusplus"
|
||||
@@ -1467,7 +1466,7 @@ dependencies = [
|
||||
"aes",
|
||||
"async-trait",
|
||||
"atomic",
|
||||
"base64",
|
||||
"base64 0.13.1",
|
||||
"byteorder",
|
||||
"ctr",
|
||||
"dashmap",
|
||||
@@ -1496,7 +1495,7 @@ checksum = "7847d36bba832bc787214323bc042b71dca7fdf2aee9f0e3eb573b64f2f7eb7f"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
"base64",
|
||||
"base64 0.13.1",
|
||||
"dashmap",
|
||||
"derive_builder",
|
||||
"getrandom 0.2.8",
|
||||
@@ -1580,6 +1579,16 @@ version = "0.3.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
|
||||
|
||||
[[package]]
|
||||
name = "mime_guess"
|
||||
version = "2.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef"
|
||||
dependencies = [
|
||||
"mime",
|
||||
"unicase",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "minimal-lexical"
|
||||
version = "0.2.1"
|
||||
@@ -1619,9 +1628,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "7.1.1"
|
||||
version = "7.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36"
|
||||
checksum = "e5507769c4919c998e69e49c839d9dc6e693ede4cc4290d6ad8b41d4f09c548c"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"minimal-lexical",
|
||||
@@ -1658,19 +1667,19 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.14.0"
|
||||
version = "1.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5"
|
||||
checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b"
|
||||
dependencies = [
|
||||
"hermit-abi 0.1.19",
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.16.0"
|
||||
version = "1.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860"
|
||||
checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66"
|
||||
|
||||
[[package]]
|
||||
name = "opaque-debug"
|
||||
@@ -1714,7 +1723,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
|
||||
dependencies = [
|
||||
"lock_api",
|
||||
"parking_lot_core 0.9.5",
|
||||
"parking_lot_core 0.9.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1733,9 +1742,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot_core"
|
||||
version = "0.9.5"
|
||||
version = "0.9.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7ff9f3fef3968a3ec5945535ed654cb38ff72d7495a25619e2247fb15a2ed9ba"
|
||||
checksum = "ba1ef8814b5c993410bb3adfad7a5ed269563e4a2f90c41f5d85be7fb47133bf"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
@@ -1869,18 +1878,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.48"
|
||||
version = "1.0.49"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e9d89e5dba24725ae5678020bf8f1357a9aa7ff10736b551adbcd3f8d17d766f"
|
||||
checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "prost"
|
||||
version = "0.11.3"
|
||||
version = "0.11.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c0b18e655c21ff5ac2084a5ad0611e827b3f92badf79f4910b5a5c58f4d87ff0"
|
||||
checksum = "21dc42e00223fc37204bd4aa177e69420c604ca4a183209a8f9de30c6d934698"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"prost-derive",
|
||||
@@ -1888,9 +1897,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "prost-derive"
|
||||
version = "0.11.2"
|
||||
version = "0.11.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "164ae68b6587001ca506d3bf7f1000bfa248d0e1217b618108fba4ec1d0cc306"
|
||||
checksum = "8bda8c0881ea9f722eb9629376db3d0b903b462477c1aafcb0566610ac28ac5d"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"itertools",
|
||||
@@ -1901,9 +1910,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.22"
|
||||
version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "556d0f47a940e895261e77dc200d5eadfc6ef644c179c6f5edfc105e3a2292c8"
|
||||
checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
@@ -2001,9 +2010,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.7.0"
|
||||
version = "1.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a"
|
||||
checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
@@ -2022,7 +2031,7 @@ version = "0.11.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68cc60575865c7831548863cc02356512e3f1dc2f3f82cb837d7fc4cc8f3c97c"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"base64 0.13.1",
|
||||
"bytes",
|
||||
"encoding_rs",
|
||||
"futures-core",
|
||||
@@ -2072,9 +2081,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ropey"
|
||||
version = "1.5.0"
|
||||
version = "1.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbd22239fafefc42138ca5da064f3c17726a80d2379d817a3521240e78dd0064"
|
||||
checksum = "a4f832915525613e83f275694cb8c184f5df13ca26a9ef0ea6ce736921964c8e"
|
||||
dependencies = [
|
||||
"smallvec",
|
||||
"str_indices",
|
||||
@@ -2138,7 +2147,7 @@ version = "0.10.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "716889595f4edc3cfeb94d9f122e413f73e37d7d80ea1c14196e1004241a3889"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"base64 0.13.1",
|
||||
"bytes",
|
||||
"form_urlencoded",
|
||||
"getrandom 0.2.8",
|
||||
@@ -2211,9 +2220,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.36.5"
|
||||
version = "0.36.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a3807b5d10909833d3e9acd1eb5fb988f79376ff10fce42937de71a449c4c588"
|
||||
checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"errno",
|
||||
@@ -2225,9 +2234,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustls"
|
||||
version = "0.20.7"
|
||||
version = "0.20.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "539a2bfe908f471bfa933876bd1eb6a19cf2176d375f82ef7f99530a40e48c2c"
|
||||
checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f"
|
||||
dependencies = [
|
||||
"log",
|
||||
"ring",
|
||||
@@ -2237,11 +2246,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustls-pemfile"
|
||||
version = "1.0.1"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0864aeff53f8c05aa08d86e5ef839d3dfcf07aeba2db32f12db0ef716e87bd55"
|
||||
checksum = "d194b56d58803a43635bdc398cd17e383d6f71f9182b9a192c127ca42494a59b"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"base64 0.21.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2274,15 +2283,15 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.15"
|
||||
version = "1.0.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3bfa246f936730408c0abee392cc1a50b118ece708c7f630516defd64480c7d8"
|
||||
checksum = "58bc9567378fc7690d6b2addae4e60ac2eeea07becb2c64b9f218b53865cba2a"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.151"
|
||||
version = "1.0.152"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "97fed41fc1a24994d044e6db6935e69511a1153b52c15eb42493b26fa87feba0"
|
||||
checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
@@ -2298,9 +2307,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.151"
|
||||
version = "1.0.152"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "255abe9a125a985c05190d687b320c12f9b1f0b99445e608c21ba0782c719ad8"
|
||||
checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -2309,9 +2318,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.90"
|
||||
version = "1.0.91"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8778cc0b528968fe72abec38b5db5a20a70d148116cd9325d2bc5f5180ca3faf"
|
||||
checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
@@ -2457,9 +2466,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "str_indices"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9d9199fa80c817e074620be84374a520062ebac833f358d74b37060ce4a0f2c0"
|
||||
checksum = "5f026164926842ec52deb1938fae44f83dfdb82d0a5b0270c5bd5935ab74d6dd"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
@@ -2475,9 +2484,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.106"
|
||||
version = "1.0.107"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09ee3a69cd2c7e06684677e5629b3878b253af05e4714964204279c6bc02cf0b"
|
||||
checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -2589,9 +2598,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.23.0"
|
||||
version = "1.24.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eab6d665857cc6ca78d6e80303a02cea7a7851e85dfbd77cbdc09bd129f1ef46"
|
||||
checksum = "1d9f76183f91ecfb55e1d7d5602bd1d979e38a3a522fe900241cf195624d67ae"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"bytes",
|
||||
@@ -2599,9 +2608,7 @@ dependencies = [
|
||||
"memchr",
|
||||
"mio",
|
||||
"num_cpus",
|
||||
"parking_lot 0.12.1",
|
||||
"pin-project-lite",
|
||||
"signal-hook-registry",
|
||||
"socket2",
|
||||
"tokio-macros",
|
||||
"windows-sys",
|
||||
@@ -2729,9 +2736,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "try-lock"
|
||||
version = "0.2.3"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642"
|
||||
checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"
|
||||
|
||||
[[package]]
|
||||
name = "tui"
|
||||
@@ -2752,6 +2759,15 @@ version = "1.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
|
||||
|
||||
[[package]]
|
||||
name = "unicase"
|
||||
version = "2.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
|
||||
dependencies = [
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-bidi"
|
||||
version = "0.3.8"
|
||||
@@ -2858,7 +2874,7 @@ checksum = "f6f20153a1c82ac5f1243b62e80f067ae608facc415c6ef82f88426a61c79886"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"arrayvec",
|
||||
"base64",
|
||||
"base64 0.13.1",
|
||||
"cbc",
|
||||
"ed25519-dalek",
|
||||
"hkdf",
|
||||
@@ -3090,45 +3106,45 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.42.0"
|
||||
version = "0.42.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e"
|
||||
checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.42.0"
|
||||
version = "0.42.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4"
|
||||
checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.42.0"
|
||||
version = "0.42.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7"
|
||||
checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.42.0"
|
||||
version = "0.42.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246"
|
||||
checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.42.0"
|
||||
version = "0.42.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed"
|
||||
checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.42.0"
|
||||
version = "0.42.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028"
|
||||
checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.42.0"
|
||||
version = "0.42.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5"
|
||||
checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"
|
||||
|
||||
[[package]]
|
||||
name = "winreg"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "iamb"
|
||||
version = "0.0.2"
|
||||
version = "0.0.3"
|
||||
edition = "2018"
|
||||
authors = ["Ulyssa <git@ulyssa.dev>"]
|
||||
repository = "https://github.com/ulyssa/iamb"
|
||||
@@ -19,6 +19,8 @@ dirs = "4.0.0"
|
||||
futures = "0.3.21"
|
||||
gethostname = "0.4.1"
|
||||
matrix-sdk = {version = "0.6", default-features = false, features = ["e2e-encryption", "sled", "rustls-tls"]}
|
||||
mime = "^0.3.16"
|
||||
mime_guess = "^2.0.4"
|
||||
modalkit = "0.0.9"
|
||||
regex = "^1.5"
|
||||
rpassword = "^7.2"
|
||||
@@ -26,7 +28,7 @@ serde = "^1.0"
|
||||
serde_json = "^1.0"
|
||||
sled = "0.34"
|
||||
thiserror = "^1.0.37"
|
||||
tokio = {version = "1.17.0", features = ["full"]}
|
||||
tokio = {version = "1.24.1", features = ["macros", "net", "rt-multi-thread", "sync", "time"]}
|
||||
tracing = "~0.1.36"
|
||||
tracing-appender = "~0.2.2"
|
||||
tracing-subscriber = "0.3.16"
|
||||
|
||||
70
README.md
70
README.md
@@ -1,5 +1,9 @@
|
||||
# iamb
|
||||
|
||||
[](https://github.com/ulyssa/iamb/actions?query=workflow%3ACI+)
|
||||
[](https://crates.io/crates/iamb)
|
||||
[](https://crates.io/crates/iamb)
|
||||
|
||||
## About
|
||||
|
||||
`iamb` is a Matrix client for the terminal that uses Vim keybindings.
|
||||
@@ -41,39 +45,39 @@ To get an idea of what is and isn't yet implemented, here is a subset of the
|
||||
Matrix website's [features comparison table][client-comparison-matrix], showing
|
||||
two other TUI clients and Element Web:
|
||||
|
||||
| | iamb | [gomuks] | [weechat-matrix] | Element Web/Desktop |
|
||||
| --------------------------------------- | :----------------- | :----------------: | :----------------: | :-----------------: |
|
||||
| Room directory | :x: ([#14]) | :x: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Room tag showing | :x: ([#15]) | :heavy_check_mark: | :x: | :heavy_check_mark: |
|
||||
| Room tag editing | :x: ([#15]) | :heavy_check_mark: | :x: | :heavy_check_mark: |
|
||||
| Search joined rooms | :x: ([#16]) | :heavy_check_mark: | :x: | :heavy_check_mark: |
|
||||
| Room user list | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Display Room Description | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Edit Room Description | :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Highlights | :x: ([#8]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Pushrules | :x: | :heavy_check_mark: | :x: | :heavy_check_mark: |
|
||||
| Send read markers | :x: ([#11]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Display read markers | :x: ([#11]) | :x: | :x: | :heavy_check_mark: |
|
||||
| Sending Invites | :x: ([#7]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Accepting Invites | :x: ([#7]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Typing Notification | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| E2E | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Replies | :x: ([#3]) | :heavy_check_mark: | :x: | :heavy_check_mark: |
|
||||
| Attachment uploading | :x: ([#13]) | :x: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Attachment downloading | :x: ([#13]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Send stickers | :x: | :x: | :x: | :heavy_check_mark: |
|
||||
| Send formatted messages (markdown) | :x: ([#10]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Rich Text Editor for formatted messages | :x: | :x: | :x: | :heavy_check_mark: |
|
||||
| Display formatted messages | :x: ([#10]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Redacting | :x: ([#5]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Multiple Matrix Accounts | :heavy_check_mark: | :x: | :heavy_check_mark: | :x: |
|
||||
| New user registration | :x: | :x: | :x: | :heavy_check_mark: |
|
||||
| VOIP | :x: | :x: | :x: | :heavy_check_mark: |
|
||||
| Reactions | :x: ([#2]) | :heavy_check_mark: | :x: | :heavy_check_mark: |
|
||||
| Message editing | :x: ([#4]) | :heavy_check_mark: | :x: | :heavy_check_mark: |
|
||||
| Room upgrades | :x: | :heavy_check_mark: | :x: | :heavy_check_mark: |
|
||||
| Localisations | :x: | 1 | :x: | 44 |
|
||||
| SSO Support | :x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| | iamb | [gomuks] | [weechat-matrix] | Element Web/Desktop |
|
||||
| --------------------------------------- | :---------- | :------: | :--------------: | :-----------------: |
|
||||
| Room directory | ❌ ([#14]) | ❌ | ✔️ | ✔️ |
|
||||
| Room tag showing | ❌ ([#15]) | ✔️ | ❌ | ✔️ |
|
||||
| Room tag editing | ❌ ([#15]) | ✔️ | ❌ | ✔️ |
|
||||
| Search joined rooms | ❌ ([#16]) | ✔️ | ❌ | ✔️ |
|
||||
| Room user list | ✔️ | ✔️ | ✔️ | ✔️ |
|
||||
| Display Room Description | ✔️ | ✔️ | ✔️ | ✔️ |
|
||||
| Edit Room Description | ✔️ | ❌ | ✔️ | ✔️ |
|
||||
| Highlights | ❌ ([#8]) | ✔️ | ✔️ | ✔️ |
|
||||
| Pushrules | ❌ | ✔️ | ❌ | ✔️ |
|
||||
| Send read markers | ❌ ([#11]) | ✔️ | ✔️ | ✔️ |
|
||||
| Display read markers | ❌ ([#11]) | ❌ | ❌ | ✔️ |
|
||||
| Sending Invites | ✔️ | ✔️ | ✔️ | ✔️ |
|
||||
| Accepting Invites | ✔️ | ✔️ | ✔️ | ✔️ |
|
||||
| Typing Notification | ✔️ | ✔️ | ✔️ | ✔️ |
|
||||
| E2E | ✔️ | ✔️ | ✔️ | ✔️ |
|
||||
| Replies | ✔️ | ✔️ | ❌ | ✔️ |
|
||||
| Attachment uploading | ✔️ | ❌ | ✔️ | ✔️ |
|
||||
| Attachment downloading | ✔️ | ✔️ | ✔️ | ✔️ |
|
||||
| Send stickers | ❌ | ❌ | ❌ | ✔️ |
|
||||
| Send formatted messages (markdown) | ❌ ([#10]) | ✔️ | ✔️ | ✔️ |
|
||||
| Rich Text Editor for formatted messages | ❌ | ❌ | ❌ | ✔️ |
|
||||
| Display formatted messages | ❌ ([#10]) | ✔️ | ✔️ | ✔️ |
|
||||
| Redacting | ✔️ | ✔️ | ✔️ | ✔️ |
|
||||
| Multiple Matrix Accounts | ✔️ | ❌ | ✔️ | ❌ |
|
||||
| New user registration | ❌ | ❌ | ❌ | ✔️ |
|
||||
| VOIP | ❌ | ❌ | ❌ | ✔️ |
|
||||
| Reactions | ❌ ([#2]) | ✔️ | ❌ | ✔️ |
|
||||
| Message editing | ❌ ([#4]) | ✔️ | ❌ | ✔️ |
|
||||
| Room upgrades | ❌ | ✔️ | ❌ | ✔️ |
|
||||
| Localisations | ❌ | 1 | ❌ | 44 |
|
||||
| SSO Support | ❌ | ✔️ | ✔️ | ✔️ |
|
||||
|
||||
## License
|
||||
|
||||
|
||||
106
src/base.rs
106
src/base.rs
@@ -41,7 +41,7 @@ use modalkit::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
message::{user_style, Message, Messages},
|
||||
message::{Message, Messages},
|
||||
worker::Requester,
|
||||
ApplicationSettings,
|
||||
};
|
||||
@@ -59,6 +59,14 @@ pub enum VerifyAction {
|
||||
Mismatch,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub enum MessageAction {
|
||||
Cancel,
|
||||
Download(Option<String>, bool),
|
||||
Redact(Option<String>),
|
||||
Reply,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub enum SetRoomField {
|
||||
Name(String),
|
||||
@@ -67,6 +75,9 @@ pub enum SetRoomField {
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub enum RoomAction {
|
||||
InviteAccept,
|
||||
InviteReject,
|
||||
InviteSend(OwnedUserId),
|
||||
Members(Box<CommandContext<ProgramContext>>),
|
||||
Set(SetRoomField),
|
||||
}
|
||||
@@ -77,26 +88,46 @@ impl From<SetRoomField> for RoomAction {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub enum SendAction {
|
||||
Submit,
|
||||
Upload(String),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub enum IambAction {
|
||||
Message(MessageAction),
|
||||
Room(RoomAction),
|
||||
Send(SendAction),
|
||||
Verify(VerifyAction, String),
|
||||
VerifyRequest(String),
|
||||
SendMessage(OwnedRoomId, String),
|
||||
ToggleScrollbackFocus,
|
||||
}
|
||||
|
||||
impl From<MessageAction> for IambAction {
|
||||
fn from(act: MessageAction) -> Self {
|
||||
IambAction::Message(act)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RoomAction> for IambAction {
|
||||
fn from(act: RoomAction) -> Self {
|
||||
IambAction::Room(act)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SendAction> for IambAction {
|
||||
fn from(act: SendAction) -> Self {
|
||||
IambAction::Send(act)
|
||||
}
|
||||
}
|
||||
|
||||
impl ApplicationAction for IambAction {
|
||||
fn is_edit_sequence<C: EditContext>(&self, _: &C) -> SequenceStatus {
|
||||
match self {
|
||||
IambAction::Message(..) => SequenceStatus::Break,
|
||||
IambAction::Room(..) => SequenceStatus::Break,
|
||||
IambAction::SendMessage(..) => SequenceStatus::Break,
|
||||
IambAction::Send(..) => SequenceStatus::Break,
|
||||
IambAction::ToggleScrollbackFocus => SequenceStatus::Break,
|
||||
IambAction::Verify(..) => SequenceStatus::Break,
|
||||
IambAction::VerifyRequest(..) => SequenceStatus::Break,
|
||||
@@ -105,8 +136,9 @@ impl ApplicationAction for IambAction {
|
||||
|
||||
fn is_last_action<C: EditContext>(&self, _: &C) -> SequenceStatus {
|
||||
match self {
|
||||
IambAction::Message(..) => SequenceStatus::Atom,
|
||||
IambAction::Room(..) => SequenceStatus::Atom,
|
||||
IambAction::SendMessage(..) => SequenceStatus::Atom,
|
||||
IambAction::Send(..) => SequenceStatus::Atom,
|
||||
IambAction::ToggleScrollbackFocus => SequenceStatus::Atom,
|
||||
IambAction::Verify(..) => SequenceStatus::Atom,
|
||||
IambAction::VerifyRequest(..) => SequenceStatus::Atom,
|
||||
@@ -115,8 +147,9 @@ impl ApplicationAction for IambAction {
|
||||
|
||||
fn is_last_selection<C: EditContext>(&self, _: &C) -> SequenceStatus {
|
||||
match self {
|
||||
IambAction::Message(..) => SequenceStatus::Ignore,
|
||||
IambAction::Room(..) => SequenceStatus::Ignore,
|
||||
IambAction::SendMessage(..) => SequenceStatus::Ignore,
|
||||
IambAction::Send(..) => SequenceStatus::Ignore,
|
||||
IambAction::ToggleScrollbackFocus => SequenceStatus::Ignore,
|
||||
IambAction::Verify(..) => SequenceStatus::Ignore,
|
||||
IambAction::VerifyRequest(..) => SequenceStatus::Ignore,
|
||||
@@ -125,8 +158,9 @@ impl ApplicationAction for IambAction {
|
||||
|
||||
fn is_switchable<C: EditContext>(&self, _: &C) -> bool {
|
||||
match self {
|
||||
IambAction::Message(..) => false,
|
||||
IambAction::Room(..) => false,
|
||||
IambAction::SendMessage(..) => false,
|
||||
IambAction::Send(..) => false,
|
||||
IambAction::ToggleScrollbackFocus => false,
|
||||
IambAction::Verify(..) => false,
|
||||
IambAction::VerifyRequest(..) => false,
|
||||
@@ -152,7 +186,7 @@ pub type IambResult<T> = UIResult<T, IambInfo>;
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum IambError {
|
||||
#[error("Unknown room identifier: {0}")]
|
||||
#[error("Invalid user identifier: {0}")]
|
||||
InvalidUserId(String),
|
||||
|
||||
#[error("Invalid verification user/device pair: {0}")]
|
||||
@@ -173,6 +207,24 @@ pub enum IambError {
|
||||
#[error("Serialization/deserialization error: {0}")]
|
||||
Serde(#[from] serde_json::Error),
|
||||
|
||||
#[error("Selected message does not have any attachments")]
|
||||
NoAttachment,
|
||||
|
||||
#[error("No message currently selected")]
|
||||
NoSelectedMessage,
|
||||
|
||||
#[error("Current window is not a room or space")]
|
||||
NoSelectedRoomOrSpace,
|
||||
|
||||
#[error("Current window is not a room")]
|
||||
NoSelectedRoom,
|
||||
|
||||
#[error("You do not have a current invitation to this room")]
|
||||
NotInvited,
|
||||
|
||||
#[error("You need to join the room before you can do that")]
|
||||
NotJoined,
|
||||
|
||||
#[error("Unknown room identifier: {0}")]
|
||||
UnknownRoom(OwnedRoomId),
|
||||
|
||||
@@ -222,24 +274,20 @@ impl RoomInfo {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_typing_spans(&self) -> Spans {
|
||||
fn get_typing_spans(&self, settings: &ApplicationSettings) -> Spans {
|
||||
let typers = self.get_typers();
|
||||
let n = typers.len();
|
||||
|
||||
match n {
|
||||
0 => Spans(vec![]),
|
||||
1 => {
|
||||
let user = typers[0].as_str();
|
||||
let user = Span::styled(user, user_style(user));
|
||||
let user = settings.get_user_span(typers[0].as_ref());
|
||||
|
||||
Spans(vec![user, Span::from(" is typing...")])
|
||||
},
|
||||
2 => {
|
||||
let user1 = typers[0].as_str();
|
||||
let user1 = Span::styled(user1, user_style(user1));
|
||||
|
||||
let user2 = typers[1].as_str();
|
||||
let user2 = Span::styled(user2, user_style(user2));
|
||||
let user1 = settings.get_user_span(typers[0].as_ref());
|
||||
let user2 = settings.get_user_span(typers[1].as_ref());
|
||||
|
||||
Spans(vec![
|
||||
user1,
|
||||
@@ -274,7 +322,7 @@ impl RoomInfo {
|
||||
let top = Rect::new(area.x, area.y, area.width, area.height - 1);
|
||||
let bar = Rect::new(area.x, area.y + top.height, area.width, 1);
|
||||
|
||||
Paragraph::new(self.get_typing_spans())
|
||||
Paragraph::new(self.get_typing_spans(settings))
|
||||
.alignment(Alignment::Center)
|
||||
.render(bar, buf);
|
||||
|
||||
@@ -448,11 +496,14 @@ impl ApplicationInfo for IambInfo {
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use super::*;
|
||||
use crate::config::{user_style, user_style_from_color};
|
||||
use crate::tests::*;
|
||||
use modalkit::tui::style::Color;
|
||||
|
||||
#[test]
|
||||
fn test_typing_spans() {
|
||||
let mut info = RoomInfo::default();
|
||||
let settings = mock_settings();
|
||||
|
||||
let users0 = vec![];
|
||||
let users1 = vec![TEST_USER1.clone()];
|
||||
@@ -473,18 +524,18 @@ pub mod tests {
|
||||
|
||||
// Nothing set.
|
||||
assert_eq!(info.users_typing, None);
|
||||
assert_eq!(info.get_typing_spans(), Spans(vec![]));
|
||||
assert_eq!(info.get_typing_spans(&settings), Spans(vec![]));
|
||||
|
||||
// Empty typing list.
|
||||
info.set_typing(users0);
|
||||
assert!(info.users_typing.is_some());
|
||||
assert_eq!(info.get_typing_spans(), Spans(vec![]));
|
||||
assert_eq!(info.get_typing_spans(&settings), Spans(vec![]));
|
||||
|
||||
// Single user typing.
|
||||
info.set_typing(users1);
|
||||
assert!(info.users_typing.is_some());
|
||||
assert_eq!(
|
||||
info.get_typing_spans(),
|
||||
info.get_typing_spans(&settings),
|
||||
Spans(vec![
|
||||
Span::styled("@user1:example.com", user_style("@user1:example.com")),
|
||||
Span::from(" is typing...")
|
||||
@@ -495,7 +546,7 @@ pub mod tests {
|
||||
info.set_typing(users2);
|
||||
assert!(info.users_typing.is_some());
|
||||
assert_eq!(
|
||||
info.get_typing_spans(),
|
||||
info.get_typing_spans(&settings),
|
||||
Spans(vec![
|
||||
Span::styled("@user1:example.com", user_style("@user1:example.com")),
|
||||
Span::raw(" and "),
|
||||
@@ -507,11 +558,22 @@ pub mod tests {
|
||||
// Four users typing.
|
||||
info.set_typing(users4);
|
||||
assert!(info.users_typing.is_some());
|
||||
assert_eq!(info.get_typing_spans(), Spans::from("Several people are typing..."));
|
||||
assert_eq!(info.get_typing_spans(&settings), Spans::from("Several people are typing..."));
|
||||
|
||||
// Five users typing.
|
||||
info.set_typing(users5);
|
||||
assert!(info.users_typing.is_some());
|
||||
assert_eq!(info.get_typing_spans(), Spans::from("Many people are typing..."));
|
||||
assert_eq!(info.get_typing_spans(&settings), Spans::from("Many people are typing..."));
|
||||
|
||||
// Test that USER5 gets rendered using the configured color and name.
|
||||
info.set_typing(vec![TEST_USER5.clone()]);
|
||||
assert!(info.users_typing.is_some());
|
||||
assert_eq!(
|
||||
info.get_typing_spans(&settings),
|
||||
Spans(vec![
|
||||
Span::styled("USER 5", user_style_from_color(Color::Black)),
|
||||
Span::from(" is typing...")
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
181
src/commands.rs
181
src/commands.rs
@@ -1,3 +1,7 @@
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use matrix_sdk::ruma::OwnedUserId;
|
||||
|
||||
use modalkit::{
|
||||
editing::base::OpenTarget,
|
||||
env::vim::command::{CommandContext, CommandDescription},
|
||||
@@ -8,10 +12,12 @@ use modalkit::{
|
||||
use crate::base::{
|
||||
IambAction,
|
||||
IambId,
|
||||
MessageAction,
|
||||
ProgramCommand,
|
||||
ProgramCommands,
|
||||
ProgramContext,
|
||||
RoomAction,
|
||||
SendAction,
|
||||
SetRoomField,
|
||||
VerifyAction,
|
||||
};
|
||||
@@ -19,6 +25,53 @@ use crate::base::{
|
||||
type ProgContext = CommandContext<ProgramContext>;
|
||||
type ProgResult = CommandResult<ProgramCommand>;
|
||||
|
||||
fn iamb_invite(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
|
||||
let args = desc.arg.strings()?;
|
||||
|
||||
if args.is_empty() {
|
||||
return Err(CommandError::InvalidArgument);
|
||||
}
|
||||
|
||||
let ract = match args[0].as_str() {
|
||||
"accept" => {
|
||||
if args.len() != 1 {
|
||||
return Err(CommandError::InvalidArgument);
|
||||
}
|
||||
|
||||
RoomAction::InviteAccept
|
||||
},
|
||||
"reject" => {
|
||||
if args.len() != 1 {
|
||||
return Err(CommandError::InvalidArgument);
|
||||
}
|
||||
|
||||
RoomAction::InviteReject
|
||||
},
|
||||
"send" => {
|
||||
if args.len() != 2 {
|
||||
return Err(CommandError::InvalidArgument);
|
||||
}
|
||||
|
||||
if let Ok(user) = OwnedUserId::try_from(args[1].as_str()) {
|
||||
RoomAction::InviteSend(user)
|
||||
} else {
|
||||
let msg = format!("Invalid user identifier: {}", args[1]);
|
||||
let err = CommandError::Error(msg);
|
||||
|
||||
return Err(err);
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
return Err(CommandError::InvalidArgument);
|
||||
},
|
||||
};
|
||||
|
||||
let iact = IambAction::from(ract);
|
||||
let step = CommandStep::Continue(iact.into(), ctx.context.take());
|
||||
|
||||
return Ok(step);
|
||||
}
|
||||
|
||||
fn iamb_verify(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
|
||||
let mut args = desc.arg.strings()?;
|
||||
|
||||
@@ -80,6 +133,41 @@ fn iamb_members(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
|
||||
return Ok(step);
|
||||
}
|
||||
|
||||
fn iamb_cancel(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
|
||||
if !desc.arg.text.is_empty() {
|
||||
return Result::Err(CommandError::InvalidArgument);
|
||||
}
|
||||
|
||||
let ract = IambAction::from(MessageAction::Cancel);
|
||||
let step = CommandStep::Continue(ract.into(), ctx.context.take());
|
||||
|
||||
return Ok(step);
|
||||
}
|
||||
|
||||
fn iamb_redact(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
|
||||
let args = desc.arg.strings()?;
|
||||
|
||||
if args.len() > 1 {
|
||||
return Result::Err(CommandError::InvalidArgument);
|
||||
}
|
||||
|
||||
let ract = IambAction::from(MessageAction::Redact(args.into_iter().next()));
|
||||
let step = CommandStep::Continue(ract.into(), ctx.context.take());
|
||||
|
||||
return Ok(step);
|
||||
}
|
||||
|
||||
fn iamb_reply(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
|
||||
if !desc.arg.text.is_empty() {
|
||||
return Result::Err(CommandError::InvalidArgument);
|
||||
}
|
||||
|
||||
let ract = IambAction::from(MessageAction::Reply);
|
||||
let step = CommandStep::Continue(ract.into(), ctx.context.take());
|
||||
|
||||
return Ok(step);
|
||||
}
|
||||
|
||||
fn iamb_rooms(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
|
||||
if !desc.arg.text.is_empty() {
|
||||
return Result::Err(CommandError::InvalidArgument);
|
||||
@@ -149,13 +237,47 @@ fn iamb_set(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
|
||||
return Ok(step);
|
||||
}
|
||||
|
||||
fn iamb_upload(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
|
||||
let mut args = desc.arg.strings()?;
|
||||
|
||||
if args.len() != 1 {
|
||||
return Result::Err(CommandError::InvalidArgument);
|
||||
}
|
||||
|
||||
let sact = SendAction::Upload(args.remove(0));
|
||||
let iact = IambAction::from(sact);
|
||||
let step = CommandStep::Continue(iact.into(), ctx.context.take());
|
||||
|
||||
return Ok(step);
|
||||
}
|
||||
|
||||
fn iamb_download(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
|
||||
let mut args = desc.arg.strings()?;
|
||||
|
||||
if args.len() > 1 {
|
||||
return Result::Err(CommandError::InvalidArgument);
|
||||
}
|
||||
|
||||
let mact = MessageAction::Download(args.pop(), desc.bang);
|
||||
let iact = IambAction::from(mact);
|
||||
let step = CommandStep::Continue(iact.into(), ctx.context.take());
|
||||
|
||||
return Ok(step);
|
||||
}
|
||||
|
||||
fn add_iamb_commands(cmds: &mut ProgramCommands) {
|
||||
cmds.add_command(ProgramCommand { names: vec!["cancel".into()], f: iamb_cancel });
|
||||
cmds.add_command(ProgramCommand { names: vec!["dms".into()], f: iamb_dms });
|
||||
cmds.add_command(ProgramCommand { names: vec!["download".into()], f: iamb_download });
|
||||
cmds.add_command(ProgramCommand { names: vec!["invite".into()], f: iamb_invite });
|
||||
cmds.add_command(ProgramCommand { names: vec!["join".into()], f: iamb_join });
|
||||
cmds.add_command(ProgramCommand { names: vec!["members".into()], f: iamb_members });
|
||||
cmds.add_command(ProgramCommand { names: vec!["redact".into()], f: iamb_redact });
|
||||
cmds.add_command(ProgramCommand { names: vec!["reply".into()], f: iamb_reply });
|
||||
cmds.add_command(ProgramCommand { names: vec!["rooms".into()], f: iamb_rooms });
|
||||
cmds.add_command(ProgramCommand { names: vec!["set".into()], f: iamb_set });
|
||||
cmds.add_command(ProgramCommand { names: vec!["spaces".into()], f: iamb_spaces });
|
||||
cmds.add_command(ProgramCommand { names: vec!["upload".into()], f: iamb_upload });
|
||||
cmds.add_command(ProgramCommand { names: vec!["verify".into()], f: iamb_verify });
|
||||
cmds.add_command(ProgramCommand { names: vec!["welcome".into()], f: iamb_welcome });
|
||||
}
|
||||
@@ -171,6 +293,7 @@ pub fn setup_commands() -> ProgramCommands {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use matrix_sdk::ruma::user_id;
|
||||
use modalkit::editing::action::WindowAction;
|
||||
|
||||
#[test]
|
||||
@@ -283,4 +406,62 @@ mod tests {
|
||||
let res = cmds.input_cmd("set room.topic A B C", ctx.clone());
|
||||
assert_eq!(res, Err(CommandError::InvalidArgument));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cmd_invite() {
|
||||
let mut cmds = setup_commands();
|
||||
let ctx = ProgramContext::default();
|
||||
|
||||
let res = cmds.input_cmd("invite accept", ctx.clone()).unwrap();
|
||||
let act = IambAction::Room(RoomAction::InviteAccept);
|
||||
assert_eq!(res, vec![(act.into(), ctx.clone())]);
|
||||
|
||||
let res = cmds.input_cmd("invite reject", ctx.clone()).unwrap();
|
||||
let act = IambAction::Room(RoomAction::InviteReject);
|
||||
assert_eq!(res, vec![(act.into(), ctx.clone())]);
|
||||
|
||||
let res = cmds.input_cmd("invite send @user:example.com", ctx.clone()).unwrap();
|
||||
let act =
|
||||
IambAction::Room(RoomAction::InviteSend(user_id!("@user:example.com").to_owned()));
|
||||
assert_eq!(res, vec![(act.into(), ctx.clone())]);
|
||||
|
||||
let res = cmds.input_cmd("invite", ctx.clone());
|
||||
assert_eq!(res, Err(CommandError::InvalidArgument));
|
||||
|
||||
let res = cmds.input_cmd("invite foo", ctx.clone());
|
||||
assert_eq!(res, Err(CommandError::InvalidArgument));
|
||||
|
||||
let res = cmds.input_cmd("invite accept @user:example.com", ctx.clone());
|
||||
assert_eq!(res, Err(CommandError::InvalidArgument));
|
||||
|
||||
let res = cmds.input_cmd("invite reject @user:example.com", ctx.clone());
|
||||
assert_eq!(res, Err(CommandError::InvalidArgument));
|
||||
|
||||
let res = cmds.input_cmd("invite send", ctx.clone());
|
||||
assert_eq!(res, Err(CommandError::InvalidArgument));
|
||||
|
||||
let res = cmds.input_cmd("invite @user:example.com", ctx.clone());
|
||||
assert_eq!(res, Err(CommandError::InvalidArgument));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cmd_redact() {
|
||||
let mut cmds = setup_commands();
|
||||
let ctx = ProgramContext::default();
|
||||
|
||||
let res = cmds.input_cmd("redact", ctx.clone()).unwrap();
|
||||
let act = IambAction::Message(MessageAction::Redact(None));
|
||||
assert_eq!(res, vec![(act.into(), ctx.clone())]);
|
||||
|
||||
let res = cmds.input_cmd("redact Removed", ctx.clone()).unwrap();
|
||||
let act = IambAction::Message(MessageAction::Redact(Some("Removed".into())));
|
||||
assert_eq!(res, vec![(act.into(), ctx.clone())]);
|
||||
|
||||
let res = cmds.input_cmd("redact \"Removed\"", ctx.clone()).unwrap();
|
||||
let act = IambAction::Message(MessageAction::Redact(Some("Removed".into())));
|
||||
assert_eq!(res, vec![(act.into(), ctx.clone())]);
|
||||
|
||||
let res = cmds.input_cmd("redact Removed Removed", ctx.clone());
|
||||
assert_eq!(res, Err(CommandError::InvalidArgument));
|
||||
}
|
||||
}
|
||||
|
||||
215
src/config.rs
215
src/config.rs
@@ -1,14 +1,22 @@
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use std::fs::File;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::io::BufReader;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process;
|
||||
|
||||
use clap::Parser;
|
||||
use matrix_sdk::ruma::OwnedUserId;
|
||||
use serde::Deserialize;
|
||||
use matrix_sdk::ruma::{OwnedUserId, UserId};
|
||||
use serde::{de::Error as SerdeError, de::Visitor, Deserialize, Deserializer};
|
||||
use url::Url;
|
||||
|
||||
use modalkit::tui::{
|
||||
style::{Color, Modifier as StyleModifier, Style},
|
||||
text::Span,
|
||||
};
|
||||
|
||||
macro_rules! usage {
|
||||
( $($args: tt)* ) => {
|
||||
println!($($args)*);
|
||||
@@ -16,6 +24,38 @@ macro_rules! usage {
|
||||
}
|
||||
}
|
||||
|
||||
const COLORS: [Color; 13] = [
|
||||
Color::Blue,
|
||||
Color::Cyan,
|
||||
Color::Green,
|
||||
Color::LightBlue,
|
||||
Color::LightGreen,
|
||||
Color::LightCyan,
|
||||
Color::LightMagenta,
|
||||
Color::LightRed,
|
||||
Color::LightYellow,
|
||||
Color::Magenta,
|
||||
Color::Red,
|
||||
Color::Reset,
|
||||
Color::Yellow,
|
||||
];
|
||||
|
||||
pub fn user_color(user: &str) -> Color {
|
||||
let mut hasher = DefaultHasher::new();
|
||||
user.hash(&mut hasher);
|
||||
let color = hasher.finish() as usize % COLORS.len();
|
||||
|
||||
COLORS[color]
|
||||
}
|
||||
|
||||
pub fn user_style_from_color(color: Color) -> Style {
|
||||
Style::default().fg(color).add_modifier(StyleModifier::BOLD)
|
||||
}
|
||||
|
||||
pub fn user_style(user: &str) -> Style {
|
||||
user_style_from_color(user_color(user))
|
||||
}
|
||||
|
||||
fn is_profile_char(c: char) -> bool {
|
||||
c.is_ascii_alphanumeric() || c == '.' || c == '-'
|
||||
}
|
||||
@@ -69,16 +109,88 @@ pub enum ConfigError {
|
||||
Invalid(#[from] serde_json::Error),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct UserColor(pub Color);
|
||||
pub struct UserColorVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for UserColorVisitor {
|
||||
type Value = UserColor;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str("a valid color")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: SerdeError,
|
||||
{
|
||||
match value {
|
||||
"none" => Ok(UserColor(Color::Reset)),
|
||||
"red" => Ok(UserColor(Color::Red)),
|
||||
"black" => Ok(UserColor(Color::Black)),
|
||||
"green" => Ok(UserColor(Color::Green)),
|
||||
"yellow" => Ok(UserColor(Color::Yellow)),
|
||||
"blue" => Ok(UserColor(Color::Blue)),
|
||||
"magenta" => Ok(UserColor(Color::Magenta)),
|
||||
"cyan" => Ok(UserColor(Color::Cyan)),
|
||||
"gray" => Ok(UserColor(Color::Gray)),
|
||||
"dark-gray" => Ok(UserColor(Color::DarkGray)),
|
||||
"light-red" => Ok(UserColor(Color::LightRed)),
|
||||
"light-green" => Ok(UserColor(Color::LightGreen)),
|
||||
"light-yellow" => Ok(UserColor(Color::LightYellow)),
|
||||
"light-blue" => Ok(UserColor(Color::LightBlue)),
|
||||
"light-magenta" => Ok(UserColor(Color::LightMagenta)),
|
||||
"light-cyan" => Ok(UserColor(Color::LightCyan)),
|
||||
"white" => Ok(UserColor(Color::White)),
|
||||
_ => Err(E::custom("Could not parse color")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for UserColor {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(UserColorVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)]
|
||||
pub struct UserDisplayTunables {
|
||||
pub color: Option<UserColor>,
|
||||
pub name: Option<String>,
|
||||
}
|
||||
|
||||
pub type UserOverrides = HashMap<OwnedUserId, UserDisplayTunables>;
|
||||
|
||||
fn merge_users(a: Option<UserOverrides>, b: Option<UserOverrides>) -> Option<UserOverrides> {
|
||||
match (a, b) {
|
||||
(Some(a), None) => Some(a),
|
||||
(None, Some(b)) => Some(b),
|
||||
(Some(mut a), Some(b)) => {
|
||||
for (k, v) in b {
|
||||
a.insert(k, v);
|
||||
}
|
||||
|
||||
Some(a)
|
||||
},
|
||||
(None, None) => None,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TunableValues {
|
||||
pub typing_notice: bool,
|
||||
pub typing_notice_display: bool,
|
||||
pub users: UserOverrides,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Deserialize)]
|
||||
pub struct Tunables {
|
||||
pub typing_notice: Option<bool>,
|
||||
pub typing_notice_display: Option<bool>,
|
||||
pub users: Option<UserOverrides>,
|
||||
}
|
||||
|
||||
impl Tunables {
|
||||
@@ -86,6 +198,7 @@ impl Tunables {
|
||||
Tunables {
|
||||
typing_notice: self.typing_notice.or(other.typing_notice),
|
||||
typing_notice_display: self.typing_notice_display.or(other.typing_notice_display),
|
||||
users: merge_users(self.users, other.users),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +206,7 @@ impl Tunables {
|
||||
TunableValues {
|
||||
typing_notice: self.typing_notice.unwrap_or(true),
|
||||
typing_notice_display: self.typing_notice.unwrap_or(true),
|
||||
users: self.users.unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,7 +237,11 @@ impl Directories {
|
||||
fn values(self) -> DirectoryValues {
|
||||
let cache = self
|
||||
.cache
|
||||
.or_else(dirs::cache_dir)
|
||||
.or_else(|| {
|
||||
let mut dir = dirs::cache_dir()?;
|
||||
dir.push("iamb");
|
||||
dir.into()
|
||||
})
|
||||
.expect("no dirs.cache value configured!");
|
||||
|
||||
let logs = self.logs.unwrap_or_else(|| {
|
||||
@@ -255,11 +373,32 @@ impl ApplicationSettings {
|
||||
|
||||
Ok(settings)
|
||||
}
|
||||
|
||||
pub fn get_user_span<'a>(&self, user_id: &'a UserId) -> Span<'a> {
|
||||
if let Some(user) = self.tunables.users.get(user_id) {
|
||||
let color = if let Some(UserColor(c)) = user.color {
|
||||
c
|
||||
} else {
|
||||
user_color(user_id.as_str())
|
||||
};
|
||||
|
||||
let style = user_style_from_color(color);
|
||||
|
||||
if let Some(name) = &user.name {
|
||||
Span::styled(name.clone(), style)
|
||||
} else {
|
||||
Span::styled(user_id.as_str(), style)
|
||||
}
|
||||
} else {
|
||||
Span::styled(user_id.as_str(), user_style(user_id.as_str()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use matrix_sdk::ruma::user_id;
|
||||
|
||||
#[test]
|
||||
fn test_profile_name_invalid() {
|
||||
@@ -283,4 +422,74 @@ mod tests {
|
||||
assert_eq!(validate_profile_name("a.b-c"), true);
|
||||
assert_eq!(validate_profile_name("a.B-c"), true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_merge_users() {
|
||||
let a = None;
|
||||
let b = vec![(user_id!("@a:b.c").to_owned(), UserDisplayTunables {
|
||||
color: Some(UserColor(Color::Red)),
|
||||
name: Some("Hello".into()),
|
||||
})]
|
||||
.into_iter()
|
||||
.collect::<HashMap<_, _>>();
|
||||
let c = vec![(user_id!("@a:b.c").to_owned(), UserDisplayTunables {
|
||||
color: Some(UserColor(Color::Green)),
|
||||
name: Some("World".into()),
|
||||
})]
|
||||
.into_iter()
|
||||
.collect::<HashMap<_, _>>();
|
||||
|
||||
let res = merge_users(a.clone(), a.clone());
|
||||
assert_eq!(res, None);
|
||||
|
||||
let res = merge_users(a.clone(), Some(b.clone()));
|
||||
assert_eq!(res, Some(b.clone()));
|
||||
|
||||
let res = merge_users(Some(b.clone()), a.clone());
|
||||
assert_eq!(res, Some(b.clone()));
|
||||
|
||||
let res = merge_users(Some(b.clone()), Some(b.clone()));
|
||||
assert_eq!(res, Some(b.clone()));
|
||||
|
||||
let res = merge_users(Some(b.clone()), Some(c.clone()));
|
||||
assert_eq!(res, Some(c.clone()));
|
||||
|
||||
let res = merge_users(Some(c.clone()), Some(b.clone()));
|
||||
assert_eq!(res, Some(b.clone()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_tunables() {
|
||||
let res: Tunables = serde_json::from_str("{}").unwrap();
|
||||
assert_eq!(res.typing_notice, None);
|
||||
assert_eq!(res.typing_notice_display, None);
|
||||
assert_eq!(res.users, None);
|
||||
|
||||
let res: Tunables = serde_json::from_str("{\"typing_notice\": true}").unwrap();
|
||||
assert_eq!(res.typing_notice, Some(true));
|
||||
assert_eq!(res.typing_notice_display, None);
|
||||
assert_eq!(res.users, None);
|
||||
|
||||
let res: Tunables = serde_json::from_str("{\"typing_notice\": false}").unwrap();
|
||||
assert_eq!(res.typing_notice, Some(false));
|
||||
assert_eq!(res.typing_notice_display, None);
|
||||
assert_eq!(res.users, None);
|
||||
|
||||
let res: Tunables = serde_json::from_str("{\"users\": {}}").unwrap();
|
||||
assert_eq!(res.typing_notice, None);
|
||||
assert_eq!(res.typing_notice_display, None);
|
||||
assert_eq!(res.users, Some(HashMap::new()));
|
||||
|
||||
let res: Tunables = serde_json::from_str(
|
||||
"{\"users\": {\"@a:b.c\": {\"color\": \"black\", \"name\": \"Tim\"}}}",
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(res.typing_notice, None);
|
||||
assert_eq!(res.typing_notice_display, None);
|
||||
let users = vec![(user_id!("@a:b.c").to_owned(), UserDisplayTunables {
|
||||
color: Some(UserColor(Color::Black)),
|
||||
name: Some("Tim".into()),
|
||||
})];
|
||||
assert_eq!(res.users, Some(users.into_iter().collect()));
|
||||
}
|
||||
}
|
||||
|
||||
99
src/main.rs
99
src/main.rs
@@ -9,6 +9,7 @@ use std::fs::{create_dir_all, File};
|
||||
use std::io::{stdout, BufReader, Stdout};
|
||||
use std::ops::DerefMut;
|
||||
use std::process;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
@@ -63,7 +64,6 @@ use crate::{
|
||||
ProgramStore,
|
||||
},
|
||||
config::{ApplicationSettings, Iamb},
|
||||
message::{Message, MessageContent, MessageTimeStamp},
|
||||
windows::IambWindow,
|
||||
worker::{ClientWorker, LoginStyle, Requester},
|
||||
};
|
||||
@@ -226,7 +226,7 @@ impl Application {
|
||||
}
|
||||
}
|
||||
|
||||
fn action_run(
|
||||
async fn action_run(
|
||||
&mut self,
|
||||
action: ProgramAction,
|
||||
ctx: ProgramContext,
|
||||
@@ -257,7 +257,7 @@ impl Application {
|
||||
},
|
||||
|
||||
// Simple delegations.
|
||||
Action::Application(act) => self.iamb_run(act, ctx, store)?,
|
||||
Action::Application(act) => self.iamb_run(act, ctx, store).await?,
|
||||
Action::CommandBar(act) => self.screen.command_bar(&act, &ctx)?,
|
||||
Action::Macro(act) => self.bindings.macro_command(&act, &ctx, store)?,
|
||||
Action::Scroll(style) => self.screen.scroll(&style, &ctx, store)?,
|
||||
@@ -314,7 +314,7 @@ impl Application {
|
||||
return Ok(info);
|
||||
}
|
||||
|
||||
fn iamb_run(
|
||||
async fn iamb_run(
|
||||
&mut self,
|
||||
action: IambAction,
|
||||
ctx: ProgramContext,
|
||||
@@ -327,24 +327,19 @@ impl Application {
|
||||
None
|
||||
},
|
||||
|
||||
IambAction::Message(act) => {
|
||||
self.screen.current_window_mut()?.message_command(act, ctx, store).await?
|
||||
},
|
||||
IambAction::Room(act) => {
|
||||
let acts = self.screen.current_window_mut()?.room_command(act, ctx, store)?;
|
||||
let acts = self.screen.current_window_mut()?.room_command(act, ctx, store).await?;
|
||||
self.action_prepend(acts);
|
||||
|
||||
None
|
||||
},
|
||||
|
||||
IambAction::SendMessage(room_id, msg) => {
|
||||
let (event_id, msg) = self.worker.send_message(room_id.clone(), msg)?;
|
||||
let user = store.application.settings.profile.user_id.clone();
|
||||
let info = store.application.get_room_info(room_id);
|
||||
let key = (MessageTimeStamp::LocalEcho, event_id);
|
||||
let msg = MessageContent::Original(msg.into());
|
||||
let msg = Message::new(msg, user, MessageTimeStamp::LocalEcho);
|
||||
info.messages.insert(key, msg);
|
||||
|
||||
None
|
||||
IambAction::Send(act) => {
|
||||
self.screen.current_window_mut()?.send_command(act, ctx, store).await?
|
||||
},
|
||||
|
||||
IambAction::Verify(act, user_dev) => {
|
||||
if let Some(sas) = store.application.verifications.get(&user_dev) {
|
||||
self.worker.verify(act, sas.clone())?
|
||||
@@ -378,7 +373,7 @@ impl Application {
|
||||
let mut keyskip = false;
|
||||
|
||||
while let Some((action, ctx)) = self.action_pop(keyskip) {
|
||||
match self.action_run(action, ctx, locked.deref_mut()) {
|
||||
match self.action_run(action, ctx, locked.deref_mut()).await {
|
||||
Ok(None) => {
|
||||
// Continue processing.
|
||||
continue;
|
||||
@@ -408,7 +403,7 @@ impl Application {
|
||||
}
|
||||
}
|
||||
|
||||
fn login(worker: Requester, settings: &ApplicationSettings) -> IambResult<()> {
|
||||
async fn login(worker: Requester, settings: &ApplicationSettings) -> IambResult<()> {
|
||||
println!("Logging in for {}...", settings.profile.user_id);
|
||||
|
||||
if settings.session_json.is_file() {
|
||||
@@ -447,38 +442,15 @@ fn print_exit<T: Display, N>(v: T) -> N {
|
||||
process::exit(2);
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> IambResult<()> {
|
||||
// Parse command-line flags.
|
||||
let iamb = Iamb::parse();
|
||||
|
||||
// Load configuration and set up the Matrix SDK.
|
||||
let settings = ApplicationSettings::load(iamb).unwrap_or_else(print_exit);
|
||||
|
||||
// Set up the tracing subscriber so we can log client messages.
|
||||
let log_prefix = format!("iamb-log-{}", settings.profile_name);
|
||||
let log_dir = settings.dirs.logs.as_path();
|
||||
|
||||
create_dir_all(settings.matrix_dir.as_path())?;
|
||||
create_dir_all(log_dir)?;
|
||||
|
||||
let appender = tracing_appender::rolling::daily(log_dir, log_prefix);
|
||||
let (appender, _) = tracing_appender::non_blocking(appender);
|
||||
|
||||
let subscriber = FmtSubscriber::builder()
|
||||
.with_writer(appender)
|
||||
.with_max_level(Level::WARN)
|
||||
.finish();
|
||||
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
|
||||
|
||||
async fn run(settings: ApplicationSettings) -> IambResult<()> {
|
||||
// Set up the async worker thread and global store.
|
||||
let worker = ClientWorker::spawn(settings.clone());
|
||||
let worker = ClientWorker::spawn(settings.clone()).await;
|
||||
let store = ChatStore::new(worker.clone(), settings.clone());
|
||||
let store = Store::new(store);
|
||||
let store = Arc::new(AsyncMutex::new(store));
|
||||
worker.init(store.clone());
|
||||
|
||||
login(worker, &settings).unwrap_or_else(print_exit);
|
||||
login(worker, &settings).await.unwrap_or_else(print_exit);
|
||||
|
||||
// Make sure panics clean up the terminal properly.
|
||||
let orig_hook = std::panic::take_hook();
|
||||
@@ -495,5 +467,44 @@ async fn main() -> IambResult<()> {
|
||||
// We can now run the application.
|
||||
application.run().await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> IambResult<()> {
|
||||
// Parse command-line flags.
|
||||
let iamb = Iamb::parse();
|
||||
|
||||
// Load configuration and set up the Matrix SDK.
|
||||
let settings = ApplicationSettings::load(iamb).unwrap_or_else(print_exit);
|
||||
|
||||
// Set up the tracing subscriber so we can log client messages.
|
||||
let log_prefix = format!("iamb-log-{}", settings.profile_name);
|
||||
let log_dir = settings.dirs.logs.as_path();
|
||||
|
||||
create_dir_all(settings.matrix_dir.as_path())?;
|
||||
create_dir_all(log_dir)?;
|
||||
|
||||
let appender = tracing_appender::rolling::daily(log_dir, log_prefix);
|
||||
let (appender, guard) = tracing_appender::non_blocking(appender);
|
||||
|
||||
let subscriber = FmtSubscriber::builder()
|
||||
.with_writer(appender)
|
||||
.with_max_level(Level::TRACE)
|
||||
.finish();
|
||||
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
|
||||
|
||||
let rt = tokio::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
.thread_name_fn(|| {
|
||||
static ATOMIC_ID: AtomicUsize = AtomicUsize::new(0);
|
||||
let id = ATOMIC_ID.fetch_add(1, Ordering::SeqCst);
|
||||
format!("iamb-worker-{}", id)
|
||||
})
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
rt.block_on(async move { run(settings).await })?;
|
||||
|
||||
drop(guard);
|
||||
process::exit(0);
|
||||
}
|
||||
|
||||
253
src/message.rs
253
src/message.rs
@@ -12,45 +12,41 @@ use unicode_width::UnicodeWidthStr;
|
||||
|
||||
use matrix_sdk::ruma::{
|
||||
events::{
|
||||
room::message::{MessageType, RoomMessageEventContent},
|
||||
MessageLikeEvent,
|
||||
room::{
|
||||
message::{
|
||||
MessageType,
|
||||
OriginalRoomMessageEvent,
|
||||
RedactedRoomMessageEvent,
|
||||
RoomMessageEvent,
|
||||
RoomMessageEventContent,
|
||||
},
|
||||
redaction::SyncRoomRedactionEvent,
|
||||
},
|
||||
Redact,
|
||||
},
|
||||
MilliSecondsSinceUnixEpoch,
|
||||
OwnedEventId,
|
||||
OwnedUserId,
|
||||
RoomVersionId,
|
||||
UInt,
|
||||
};
|
||||
|
||||
use modalkit::tui::{
|
||||
style::{Color, Modifier as StyleModifier, Style},
|
||||
style::{Modifier as StyleModifier, Style},
|
||||
text::{Span, Spans, Text},
|
||||
};
|
||||
|
||||
use modalkit::editing::{base::ViewportContext, cursor::Cursor};
|
||||
|
||||
use crate::base::{IambResult, RoomInfo};
|
||||
use crate::{
|
||||
base::{IambResult, RoomInfo},
|
||||
config::ApplicationSettings,
|
||||
};
|
||||
|
||||
pub type MessageEvent = MessageLikeEvent<RoomMessageEventContent>;
|
||||
pub type MessageFetchResult = IambResult<(Option<String>, Vec<MessageEvent>)>;
|
||||
pub type MessageFetchResult = IambResult<(Option<String>, Vec<RoomMessageEvent>)>;
|
||||
pub type MessageKey = (MessageTimeStamp, OwnedEventId);
|
||||
pub type Messages = BTreeMap<MessageKey, Message>;
|
||||
|
||||
const COLORS: [Color; 13] = [
|
||||
Color::Blue,
|
||||
Color::Cyan,
|
||||
Color::Green,
|
||||
Color::LightBlue,
|
||||
Color::LightGreen,
|
||||
Color::LightCyan,
|
||||
Color::LightMagenta,
|
||||
Color::LightRed,
|
||||
Color::LightYellow,
|
||||
Color::Magenta,
|
||||
Color::Red,
|
||||
Color::Reset,
|
||||
Color::Yellow,
|
||||
];
|
||||
|
||||
const USER_GUTTER: usize = 30;
|
||||
const TIME_GUTTER: usize = 12;
|
||||
const MIN_MSG_LEN: usize = 30;
|
||||
@@ -66,18 +62,6 @@ const USER_GUTTER_EMPTY_SPAN: Span<'static> = Span {
|
||||
},
|
||||
};
|
||||
|
||||
pub(crate) fn user_color(user: &str) -> Color {
|
||||
let mut hasher = DefaultHasher::new();
|
||||
user.hash(&mut hasher);
|
||||
let color = hasher.finish() as usize % COLORS.len();
|
||||
|
||||
COLORS[color]
|
||||
}
|
||||
|
||||
pub(crate) fn user_style(user: &str) -> Style {
|
||||
Style::default().fg(user_color(user)).add_modifier(StyleModifier::BOLD)
|
||||
}
|
||||
|
||||
struct WrappedLinesIterator<'a> {
|
||||
iter: Lines<'a>,
|
||||
curr: Option<&'a str>,
|
||||
@@ -171,6 +155,13 @@ impl MessageTimeStamp {
|
||||
fn is_local_echo(&self) -> bool {
|
||||
matches!(self, MessageTimeStamp::LocalEcho)
|
||||
}
|
||||
|
||||
pub fn as_millis(&self) -> Option<MilliSecondsSinceUnixEpoch> {
|
||||
match self {
|
||||
MessageTimeStamp::OriginServer(ms) => MilliSecondsSinceUnixEpoch(*ms).into(),
|
||||
MessageTimeStamp::LocalEcho => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Ord for MessageTimeStamp {
|
||||
@@ -329,70 +320,106 @@ impl PartialOrd for MessageCursor {
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum MessageContent {
|
||||
Original(Box<RoomMessageEventContent>),
|
||||
Redacted,
|
||||
pub enum MessageEvent {
|
||||
Original(Box<OriginalRoomMessageEvent>),
|
||||
Redacted(Box<RedactedRoomMessageEvent>),
|
||||
Local(Box<RoomMessageEventContent>),
|
||||
}
|
||||
|
||||
impl AsRef<str> for MessageContent {
|
||||
fn as_ref(&self) -> &str {
|
||||
impl MessageEvent {
|
||||
pub fn show(&self) -> Cow<'_, str> {
|
||||
match self {
|
||||
MessageContent::Original(ev) => {
|
||||
match &ev.msgtype {
|
||||
MessageType::Text(content) => {
|
||||
return content.body.as_ref();
|
||||
},
|
||||
MessageType::Emote(content) => {
|
||||
return content.body.as_ref();
|
||||
},
|
||||
MessageType::Notice(content) => {
|
||||
return content.body.as_str();
|
||||
},
|
||||
MessageType::ServerNotice(_) => {
|
||||
// XXX: implement
|
||||
MessageEvent::Original(ev) => show_room_content(&ev.content),
|
||||
MessageEvent::Redacted(ev) => {
|
||||
let reason = ev
|
||||
.unsigned
|
||||
.redacted_because
|
||||
.as_ref()
|
||||
.and_then(|e| e.as_original())
|
||||
.and_then(|r| r.content.reason.as_ref());
|
||||
|
||||
return "[server notice]";
|
||||
},
|
||||
MessageType::VerificationRequest(_) => {
|
||||
// XXX: implement
|
||||
|
||||
return "[verification request]";
|
||||
},
|
||||
MessageType::Audio(..) => {
|
||||
return "[audio]";
|
||||
},
|
||||
MessageType::File(..) => {
|
||||
return "[file]";
|
||||
},
|
||||
MessageType::Image(..) => {
|
||||
return "[image]";
|
||||
},
|
||||
MessageType::Video(..) => {
|
||||
return "[video]";
|
||||
},
|
||||
_ => return "[unknown message type]",
|
||||
if let Some(r) = reason {
|
||||
Cow::Owned(format!("[Redacted: {:?}]", r))
|
||||
} else {
|
||||
Cow::Borrowed("[Redacted]")
|
||||
}
|
||||
},
|
||||
MessageContent::Redacted => "[redacted]",
|
||||
MessageEvent::Local(content) => show_room_content(content),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn redact(&mut self, redaction: SyncRoomRedactionEvent, version: &RoomVersionId) {
|
||||
match self {
|
||||
MessageEvent::Redacted(_) => return,
|
||||
MessageEvent::Local(_) => return,
|
||||
MessageEvent::Original(ev) => {
|
||||
let redacted = ev.clone().redact(redaction, version);
|
||||
*self = MessageEvent::Redacted(Box::new(redacted));
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn show_room_content(content: &RoomMessageEventContent) -> Cow<'_, str> {
|
||||
let s = match &content.msgtype {
|
||||
MessageType::Text(content) => content.body.as_ref(),
|
||||
MessageType::Emote(content) => content.body.as_ref(),
|
||||
MessageType::Notice(content) => content.body.as_str(),
|
||||
MessageType::ServerNotice(content) => content.body.as_str(),
|
||||
|
||||
MessageType::VerificationRequest(_) => {
|
||||
// XXX: implement
|
||||
|
||||
return Cow::Owned("[verification request]".into());
|
||||
},
|
||||
MessageType::Audio(content) => {
|
||||
return Cow::Owned(format!("[Attached Audio: {}]", content.body));
|
||||
},
|
||||
MessageType::File(content) => {
|
||||
return Cow::Owned(format!("[Attached File: {}]", content.body));
|
||||
},
|
||||
MessageType::Image(content) => {
|
||||
return Cow::Owned(format!("[Attached Image: {}]", content.body));
|
||||
},
|
||||
MessageType::Video(content) => {
|
||||
return Cow::Owned(format!("[Attached Video: {}]", content.body));
|
||||
},
|
||||
_ => {
|
||||
return Cow::Owned(format!("[Unknown message type: {:?}]", content.msgtype()));
|
||||
},
|
||||
};
|
||||
|
||||
Cow::Borrowed(s)
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Message {
|
||||
pub content: MessageContent,
|
||||
pub event: MessageEvent,
|
||||
pub sender: OwnedUserId,
|
||||
pub timestamp: MessageTimeStamp,
|
||||
pub downloaded: bool,
|
||||
}
|
||||
|
||||
impl Message {
|
||||
pub fn new(content: MessageContent, sender: OwnedUserId, timestamp: MessageTimeStamp) -> Self {
|
||||
Message { content, sender, timestamp }
|
||||
pub fn new(event: MessageEvent, sender: OwnedUserId, timestamp: MessageTimeStamp) -> Self {
|
||||
Message { event, sender, timestamp, downloaded: false }
|
||||
}
|
||||
|
||||
pub fn show(&self, selected: bool, vwctx: &ViewportContext<MessageCursor>) -> Text {
|
||||
pub fn show(
|
||||
&self,
|
||||
prev: Option<&Message>,
|
||||
selected: bool,
|
||||
vwctx: &ViewportContext<MessageCursor>,
|
||||
settings: &ApplicationSettings,
|
||||
) -> Text {
|
||||
let width = vwctx.get_width();
|
||||
let msg = self.as_ref();
|
||||
let mut msg = self.event.show();
|
||||
|
||||
if self.downloaded {
|
||||
msg.to_mut().push_str(" \u{2705}");
|
||||
}
|
||||
|
||||
let msg = msg.as_ref();
|
||||
|
||||
let mut lines = vec![];
|
||||
|
||||
@@ -410,11 +437,11 @@ impl Message {
|
||||
let lw = width - USER_GUTTER - TIME_GUTTER;
|
||||
|
||||
for (i, (line, w)) in wrap(msg, lw).enumerate() {
|
||||
let line = Span::styled(line, style);
|
||||
let line = Span::styled(line.to_string(), style);
|
||||
let trailing = Span::styled(space(lw.saturating_sub(w)), style);
|
||||
|
||||
if i == 0 {
|
||||
let user = self.show_sender(true);
|
||||
let user = self.show_sender(prev, true, settings);
|
||||
|
||||
if let Some(time) = self.timestamp.show() {
|
||||
lines.push(Spans(vec![user, line, trailing, time]))
|
||||
@@ -431,11 +458,11 @@ impl Message {
|
||||
let lw = width - USER_GUTTER;
|
||||
|
||||
for (i, (line, w)) in wrap(msg, lw).enumerate() {
|
||||
let line = Span::styled(line, style);
|
||||
let line = Span::styled(line.to_string(), style);
|
||||
let trailing = Span::styled(space(lw.saturating_sub(w)), style);
|
||||
|
||||
let prefix = if i == 0 {
|
||||
self.show_sender(true)
|
||||
self.show_sender(prev, true, settings)
|
||||
} else {
|
||||
USER_GUTTER_EMPTY_SPAN
|
||||
};
|
||||
@@ -443,7 +470,7 @@ impl Message {
|
||||
lines.push(Spans(vec![prefix, line, trailing]))
|
||||
}
|
||||
} else {
|
||||
lines.push(Spans::from(self.show_sender(false)));
|
||||
lines.push(Spans::from(self.show_sender(prev, false, settings)));
|
||||
|
||||
for (line, _) in wrap(msg, width.saturating_sub(2)) {
|
||||
let line = format!(" {}", line);
|
||||
@@ -456,44 +483,64 @@ impl Message {
|
||||
return Text { lines };
|
||||
}
|
||||
|
||||
fn show_sender(&self, align_right: bool) -> Span {
|
||||
let sender = self.sender.to_string();
|
||||
let style = user_style(sender.as_str());
|
||||
fn show_sender(
|
||||
&self,
|
||||
prev: Option<&Message>,
|
||||
align_right: bool,
|
||||
settings: &ApplicationSettings,
|
||||
) -> Span {
|
||||
let user = if matches!(prev, Some(prev) if self.sender == prev.sender) {
|
||||
USER_GUTTER_EMPTY_SPAN
|
||||
} else {
|
||||
settings.get_user_span(self.sender.as_ref())
|
||||
};
|
||||
|
||||
let Span { content, style } = user;
|
||||
let stop = content.len().min(28);
|
||||
let s = &content[..stop];
|
||||
|
||||
let sender = if align_right {
|
||||
format!("{: >width$} ", sender, width = 28)
|
||||
format!("{: >width$} ", s, width = 28)
|
||||
} else {
|
||||
format!("{: <width$} ", sender, width = 28)
|
||||
format!("{: <width$} ", s, width = 28)
|
||||
};
|
||||
|
||||
Span::styled(sender, style)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MessageEvent> for Message {
|
||||
fn from(event: MessageEvent) -> Self {
|
||||
match event {
|
||||
MessageLikeEvent::Original(ev) => {
|
||||
let content = MessageContent::Original(ev.content.into());
|
||||
impl From<OriginalRoomMessageEvent> for Message {
|
||||
fn from(event: OriginalRoomMessageEvent) -> Self {
|
||||
let timestamp = event.origin_server_ts.into();
|
||||
let user_id = event.sender.clone();
|
||||
let content = MessageEvent::Original(event.into());
|
||||
|
||||
Message::new(content, ev.sender, ev.origin_server_ts.into())
|
||||
},
|
||||
MessageLikeEvent::Redacted(ev) => {
|
||||
Message::new(MessageContent::Redacted, ev.sender, ev.origin_server_ts.into())
|
||||
},
|
||||
}
|
||||
Message::new(content, user_id, timestamp)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<str> for Message {
|
||||
fn as_ref(&self) -> &str {
|
||||
self.content.as_ref()
|
||||
impl From<RedactedRoomMessageEvent> for Message {
|
||||
fn from(event: RedactedRoomMessageEvent) -> Self {
|
||||
let timestamp = event.origin_server_ts.into();
|
||||
let user_id = event.sender.clone();
|
||||
let content = MessageEvent::Redacted(event.into());
|
||||
|
||||
Message::new(content, user_id, timestamp)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RoomMessageEvent> for Message {
|
||||
fn from(event: RoomMessageEvent) -> Self {
|
||||
match event {
|
||||
RoomMessageEvent::Original(ev) => ev.into(),
|
||||
RoomMessageEvent::Redacted(ev) => ev.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToString for Message {
|
||||
fn to_string(&self) -> String {
|
||||
self.as_ref().to_string()
|
||||
self.event.show().into_owned()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
112
src/tests.rs
112
src/tests.rs
@@ -1,29 +1,37 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use matrix_sdk::ruma::{
|
||||
event_id,
|
||||
events::room::message::RoomMessageEventContent,
|
||||
events::room::message::{OriginalRoomMessageEvent, RoomMessageEventContent},
|
||||
server_name,
|
||||
user_id,
|
||||
EventId,
|
||||
OwnedEventId,
|
||||
OwnedRoomId,
|
||||
OwnedUserId,
|
||||
RoomId,
|
||||
UInt,
|
||||
};
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::sync::mpsc::sync_channel;
|
||||
use url::Url;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use modalkit::tui::style::Color;
|
||||
use tokio::sync::mpsc::unbounded_channel;
|
||||
use url::Url;
|
||||
|
||||
use crate::{
|
||||
base::{ChatStore, ProgramStore, RoomFetchStatus, RoomInfo},
|
||||
config::{ApplicationSettings, DirectoryValues, ProfileConfig, TunableValues},
|
||||
config::{
|
||||
ApplicationSettings,
|
||||
DirectoryValues,
|
||||
ProfileConfig,
|
||||
TunableValues,
|
||||
UserColor,
|
||||
UserDisplayTunables,
|
||||
},
|
||||
message::{
|
||||
Message,
|
||||
MessageContent,
|
||||
MessageEvent,
|
||||
MessageKey,
|
||||
MessageTimeStamp::{LocalEcho, OriginServer},
|
||||
Messages,
|
||||
@@ -35,57 +43,72 @@ lazy_static! {
|
||||
pub static ref TEST_ROOM1_ID: OwnedRoomId = RoomId::new(server_name!("example.com")).to_owned();
|
||||
pub static ref TEST_USER1: OwnedUserId = user_id!("@user1:example.com").to_owned();
|
||||
pub static ref TEST_USER2: OwnedUserId = user_id!("@user2:example.com").to_owned();
|
||||
pub static ref TEST_USER3: OwnedUserId = user_id!("@user2:example.com").to_owned();
|
||||
pub static ref TEST_USER4: OwnedUserId = user_id!("@user2:example.com").to_owned();
|
||||
pub static ref TEST_USER5: OwnedUserId = user_id!("@user2:example.com").to_owned();
|
||||
pub static ref MSG1_KEY: MessageKey = (LocalEcho, EventId::new(server_name!("example.com")));
|
||||
pub static ref MSG2_KEY: MessageKey =
|
||||
(OriginServer(UInt::new(1).unwrap()), EventId::new(server_name!("example.com")));
|
||||
pub static ref MSG3_KEY: MessageKey = (
|
||||
OriginServer(UInt::new(2).unwrap()),
|
||||
event_id!("$5jRz3KfVhaUzXtVj7k:example.com").to_owned()
|
||||
);
|
||||
pub static ref MSG4_KEY: MessageKey = (
|
||||
OriginServer(UInt::new(2).unwrap()),
|
||||
event_id!("$JP6qFV7WyXk5ZnexM3:example.com").to_owned()
|
||||
);
|
||||
pub static ref MSG5_KEY: MessageKey =
|
||||
(OriginServer(UInt::new(8).unwrap()), EventId::new(server_name!("example.com")));
|
||||
pub static ref TEST_USER3: OwnedUserId = user_id!("@user3:example.com").to_owned();
|
||||
pub static ref TEST_USER4: OwnedUserId = user_id!("@user4:example.com").to_owned();
|
||||
pub static ref TEST_USER5: OwnedUserId = user_id!("@user5:example.com").to_owned();
|
||||
pub static ref MSG1_EVID: OwnedEventId = EventId::new(server_name!("example.com"));
|
||||
pub static ref MSG2_EVID: OwnedEventId = EventId::new(server_name!("example.com"));
|
||||
pub static ref MSG3_EVID: OwnedEventId =
|
||||
event_id!("$5jRz3KfVhaUzXtVj7k:example.com").to_owned();
|
||||
pub static ref MSG4_EVID: OwnedEventId =
|
||||
event_id!("$JP6qFV7WyXk5ZnexM3:example.com").to_owned();
|
||||
pub static ref MSG5_EVID: OwnedEventId = EventId::new(server_name!("example.com"));
|
||||
pub static ref MSG1_KEY: MessageKey = (LocalEcho, MSG1_EVID.clone());
|
||||
pub static ref MSG2_KEY: MessageKey = (OriginServer(UInt::new(1).unwrap()), MSG2_EVID.clone());
|
||||
pub static ref MSG3_KEY: MessageKey = (OriginServer(UInt::new(2).unwrap()), MSG3_EVID.clone());
|
||||
pub static ref MSG4_KEY: MessageKey = (OriginServer(UInt::new(2).unwrap()), MSG4_EVID.clone());
|
||||
pub static ref MSG5_KEY: MessageKey = (OriginServer(UInt::new(8).unwrap()), MSG5_EVID.clone());
|
||||
}
|
||||
|
||||
pub fn mock_room1_message(
|
||||
content: RoomMessageEventContent,
|
||||
sender: OwnedUserId,
|
||||
key: MessageKey,
|
||||
) -> Message {
|
||||
let origin_server_ts = key.0.as_millis().unwrap();
|
||||
let event_id = key.1;
|
||||
|
||||
let event = OriginalRoomMessageEvent {
|
||||
content,
|
||||
event_id,
|
||||
sender,
|
||||
origin_server_ts,
|
||||
room_id: TEST_ROOM1_ID.clone(),
|
||||
unsigned: Default::default(),
|
||||
};
|
||||
|
||||
event.into()
|
||||
}
|
||||
|
||||
pub fn mock_message1() -> Message {
|
||||
let content = RoomMessageEventContent::text_plain("writhe");
|
||||
let content = MessageContent::Original(content.into());
|
||||
let content = MessageEvent::Local(content.into());
|
||||
|
||||
Message::new(content, TEST_USER1.clone(), MSG1_KEY.0)
|
||||
}
|
||||
|
||||
pub fn mock_message2() -> Message {
|
||||
let content = RoomMessageEventContent::text_plain("helium");
|
||||
let content = MessageContent::Original(content.into());
|
||||
|
||||
Message::new(content, TEST_USER2.clone(), MSG2_KEY.0)
|
||||
mock_room1_message(content, TEST_USER2.clone(), MSG2_KEY.clone())
|
||||
}
|
||||
|
||||
pub fn mock_message3() -> Message {
|
||||
let content = RoomMessageEventContent::text_plain("this\nis\na\nmultiline\nmessage");
|
||||
let content = MessageContent::Original(content.into());
|
||||
|
||||
Message::new(content, TEST_USER2.clone(), MSG3_KEY.0)
|
||||
mock_room1_message(content, TEST_USER2.clone(), MSG3_KEY.clone())
|
||||
}
|
||||
|
||||
pub fn mock_message4() -> Message {
|
||||
let content = RoomMessageEventContent::text_plain("help");
|
||||
let content = MessageContent::Original(content.into());
|
||||
|
||||
Message::new(content, TEST_USER1.clone(), MSG4_KEY.0)
|
||||
mock_room1_message(content, TEST_USER1.clone(), MSG4_KEY.clone())
|
||||
}
|
||||
|
||||
pub fn mock_message5() -> Message {
|
||||
let content = RoomMessageEventContent::text_plain("character");
|
||||
let content = MessageContent::Original(content.into());
|
||||
|
||||
Message::new(content, TEST_USER2.clone(), MSG5_KEY.0)
|
||||
mock_room1_message(content, TEST_USER2.clone(), MSG4_KEY.clone())
|
||||
}
|
||||
|
||||
pub fn mock_messages() -> Messages {
|
||||
@@ -118,6 +141,19 @@ pub fn mock_dirs() -> DirectoryValues {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mock_tunables() -> TunableValues {
|
||||
TunableValues {
|
||||
typing_notice: true,
|
||||
typing_notice_display: true,
|
||||
users: vec![(TEST_USER5.clone(), UserDisplayTunables {
|
||||
color: Some(UserColor(Color::Black)),
|
||||
name: Some("USER 5".into()),
|
||||
})]
|
||||
.into_iter()
|
||||
.collect::<HashMap<_, _>>(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mock_settings() -> ApplicationSettings {
|
||||
ApplicationSettings {
|
||||
matrix_dir: PathBuf::new(),
|
||||
@@ -129,14 +165,16 @@ pub fn mock_settings() -> ApplicationSettings {
|
||||
settings: None,
|
||||
dirs: None,
|
||||
},
|
||||
tunables: TunableValues { typing_notice: true, typing_notice_display: true },
|
||||
tunables: mock_tunables(),
|
||||
dirs: mock_dirs(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mock_store() -> ProgramStore {
|
||||
let (tx, _) = sync_channel(5);
|
||||
let worker = Requester { tx };
|
||||
pub async fn mock_store() -> ProgramStore {
|
||||
let (tx, _) = unbounded_channel();
|
||||
let homeserver = Url::parse("https://localhost").unwrap();
|
||||
let client = matrix_sdk::Client::new(homeserver).await.unwrap();
|
||||
let worker = Requester { tx, client };
|
||||
|
||||
let mut store = ChatStore::new(worker, mock_settings());
|
||||
let room_id = TEST_ROOM1_ID.clone();
|
||||
|
||||
@@ -51,19 +51,19 @@ use modalkit::{
|
||||
},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
base::{
|
||||
ChatStore,
|
||||
IambBufferId,
|
||||
IambId,
|
||||
IambInfo,
|
||||
IambResult,
|
||||
ProgramAction,
|
||||
ProgramContext,
|
||||
ProgramStore,
|
||||
RoomAction,
|
||||
},
|
||||
message::user_style,
|
||||
use crate::base::{
|
||||
ChatStore,
|
||||
IambBufferId,
|
||||
IambError,
|
||||
IambId,
|
||||
IambInfo,
|
||||
IambResult,
|
||||
MessageAction,
|
||||
ProgramAction,
|
||||
ProgramContext,
|
||||
ProgramStore,
|
||||
RoomAction,
|
||||
SendAction,
|
||||
};
|
||||
|
||||
use self::{room::RoomState, welcome::WelcomeState};
|
||||
@@ -105,6 +105,20 @@ fn selected_text(s: &str, selected: bool) -> Text {
|
||||
Text::from(selected_span(s, selected))
|
||||
}
|
||||
|
||||
fn room_cmp(a: &MatrixRoom, b: &MatrixRoom) -> Ordering {
|
||||
let ca1 = a.canonical_alias();
|
||||
let ca2 = b.canonical_alias();
|
||||
|
||||
let ord = match (ca1, ca2) {
|
||||
(None, None) => Ordering::Equal,
|
||||
(None, Some(_)) => Ordering::Greater,
|
||||
(Some(_), None) => Ordering::Less,
|
||||
(Some(ca1), Some(ca2)) => ca1.cmp(&ca2),
|
||||
};
|
||||
|
||||
ord.then_with(|| a.room_id().cmp(b.room_id()))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn room_prompt(
|
||||
room_id: &RoomId,
|
||||
@@ -168,19 +182,42 @@ impl IambWindow {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn room_command(
|
||||
pub async fn message_command(
|
||||
&mut self,
|
||||
act: MessageAction,
|
||||
ctx: ProgramContext,
|
||||
store: &mut ProgramStore,
|
||||
) -> IambResult<EditInfo> {
|
||||
if let IambWindow::Room(w) = self {
|
||||
w.message_command(act, ctx, store).await
|
||||
} else {
|
||||
return Err(IambError::NoSelectedRoom.into());
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn room_command(
|
||||
&mut self,
|
||||
act: RoomAction,
|
||||
ctx: ProgramContext,
|
||||
store: &mut ProgramStore,
|
||||
) -> IambResult<Vec<(Action<IambInfo>, ProgramContext)>> {
|
||||
if let IambWindow::Room(w) = self {
|
||||
w.room_command(act, ctx, store)
|
||||
w.room_command(act, ctx, store).await
|
||||
} else {
|
||||
let msg = "No room currently focused!";
|
||||
let err = UIError::Failure(msg.into());
|
||||
return Err(IambError::NoSelectedRoomOrSpace.into());
|
||||
}
|
||||
}
|
||||
|
||||
return Err(err);
|
||||
pub async fn send_command(
|
||||
&mut self,
|
||||
act: SendAction,
|
||||
ctx: ProgramContext,
|
||||
store: &mut ProgramStore,
|
||||
) -> IambResult<EditInfo> {
|
||||
if let IambWindow::Room(w) = self {
|
||||
w.send_command(act, ctx, store).await
|
||||
} else {
|
||||
return Err(IambError::NoSelectedRoom.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -306,9 +343,14 @@ impl WindowOps<IambInfo> for IambWindow {
|
||||
.render(area, buf, state);
|
||||
},
|
||||
IambWindow::RoomList(state) => {
|
||||
let joined = store.application.worker.joined_rooms();
|
||||
let items = joined.into_iter().map(|(id, name)| RoomItem::new(id, name, store));
|
||||
state.set(items.collect());
|
||||
let joined = store.application.worker.active_rooms();
|
||||
let mut items = joined
|
||||
.into_iter()
|
||||
.map(|(room, name)| RoomItem::new(room, name, store))
|
||||
.collect::<Vec<_>>();
|
||||
items.sort();
|
||||
|
||||
state.set(items);
|
||||
|
||||
List::new(store)
|
||||
.empty_message("You haven't joined any rooms yet")
|
||||
@@ -518,6 +560,26 @@ impl RoomItem {
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for RoomItem {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.room.room_id() == other.room.room_id()
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for RoomItem {}
|
||||
|
||||
impl Ord for RoomItem {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
room_cmp(&self.room, &other.room)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for RoomItem {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
self.cmp(other).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl ToString for RoomItem {
|
||||
fn to_string(&self) -> String {
|
||||
return self.name.clone();
|
||||
@@ -604,6 +666,26 @@ impl SpaceItem {
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for SpaceItem {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.room.room_id() == other.room.room_id()
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for SpaceItem {}
|
||||
|
||||
impl Ord for SpaceItem {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
room_cmp(&self.room, &other.room)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for SpaceItem {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
self.cmp(other).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl ToString for SpaceItem {
|
||||
fn to_string(&self) -> String {
|
||||
return self.room.room_id().to_string();
|
||||
@@ -845,15 +927,18 @@ impl ToString for MemberItem {
|
||||
}
|
||||
|
||||
impl ListItem<IambInfo> for MemberItem {
|
||||
fn show(&self, selected: bool, _: &ViewportContext<ListCursor>, _: &mut ProgramStore) -> Text {
|
||||
let mut style = user_style(self.member.user_id().as_str());
|
||||
fn show(
|
||||
&self,
|
||||
selected: bool,
|
||||
_: &ViewportContext<ListCursor>,
|
||||
store: &mut ProgramStore,
|
||||
) -> Text {
|
||||
let mut user = store.application.settings.get_user_span(self.member.user_id());
|
||||
|
||||
if selected {
|
||||
style = style.add_modifier(StyleModifier::REVERSED);
|
||||
user.style = user.style.add_modifier(StyleModifier::REVERSED);
|
||||
}
|
||||
|
||||
let user = Span::styled(self.to_string(), style);
|
||||
|
||||
let state = match self.member.membership() {
|
||||
MembershipState::Ban => Span::raw(" (banned)").into(),
|
||||
MembershipState::Invite => Span::raw(" (invited)").into(),
|
||||
|
||||
@@ -1,11 +1,31 @@
|
||||
use std::borrow::Cow;
|
||||
use std::ffi::OsStr;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use matrix_sdk::{
|
||||
attachment::AttachmentConfig,
|
||||
media::{MediaFormat, MediaRequest},
|
||||
room::Room as MatrixRoom,
|
||||
ruma::{OwnedRoomId, RoomId},
|
||||
ruma::{
|
||||
events::room::message::{
|
||||
MessageType,
|
||||
OriginalRoomMessageEvent,
|
||||
RoomMessageEventContent,
|
||||
TextMessageEventContent,
|
||||
},
|
||||
OwnedRoomId,
|
||||
RoomId,
|
||||
},
|
||||
};
|
||||
|
||||
use modalkit::tui::{buffer::Buffer, layout::Rect, widgets::StatefulWidget};
|
||||
|
||||
use modalkit::{
|
||||
tui::{
|
||||
buffer::Buffer,
|
||||
layout::Rect,
|
||||
text::{Span, Spans},
|
||||
widgets::{Paragraph, StatefulWidget, Widget},
|
||||
},
|
||||
widgets::textbox::{TextBox, TextBoxState},
|
||||
widgets::TerminalCursor,
|
||||
widgets::{PromptActions, WindowOps},
|
||||
@@ -18,10 +38,12 @@ use modalkit::editing::{
|
||||
EditResult,
|
||||
Editable,
|
||||
EditorAction,
|
||||
InfoMessage,
|
||||
Jumpable,
|
||||
PromptAction,
|
||||
Promptable,
|
||||
Scrollable,
|
||||
UIError,
|
||||
},
|
||||
base::{CloseFlags, Count, MoveDir1D, PositionList, ScrollStyle, WordStyle},
|
||||
context::Resolve,
|
||||
@@ -32,14 +54,20 @@ use modalkit::editing::{
|
||||
use crate::base::{
|
||||
IambAction,
|
||||
IambBufferId,
|
||||
IambError,
|
||||
IambInfo,
|
||||
IambResult,
|
||||
MessageAction,
|
||||
ProgramAction,
|
||||
ProgramContext,
|
||||
ProgramStore,
|
||||
RoomFocus,
|
||||
RoomInfo,
|
||||
SendAction,
|
||||
};
|
||||
|
||||
use crate::message::{Message, MessageEvent, MessageKey, MessageTimeStamp};
|
||||
|
||||
use super::scrollback::{Scrollback, ScrollbackState};
|
||||
|
||||
pub struct ChatState {
|
||||
@@ -52,6 +80,8 @@ pub struct ChatState {
|
||||
|
||||
scrollback: ScrollbackState,
|
||||
focus: RoomFocus,
|
||||
|
||||
reply_to: Option<MessageKey>,
|
||||
}
|
||||
|
||||
impl ChatState {
|
||||
@@ -72,9 +102,243 @@ impl ChatState {
|
||||
|
||||
scrollback,
|
||||
focus: RoomFocus::MessageBar,
|
||||
|
||||
reply_to: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_reply_to<'a>(&self, info: &'a RoomInfo) -> Option<&'a OriginalRoomMessageEvent> {
|
||||
let key = self.reply_to.as_ref()?;
|
||||
let msg = info.messages.get(key)?;
|
||||
|
||||
if let MessageEvent::Original(ev) = &msg.event {
|
||||
Some(ev)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn reset(&mut self) -> EditRope {
|
||||
self.reply_to = None;
|
||||
self.tbox.reset()
|
||||
}
|
||||
|
||||
pub fn refresh_room(&mut self, store: &mut ProgramStore) {
|
||||
if let Some(room) = store.application.worker.client.get_room(self.id()) {
|
||||
self.room = room;
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn message_command(
|
||||
&mut self,
|
||||
act: MessageAction,
|
||||
_: ProgramContext,
|
||||
store: &mut ProgramStore,
|
||||
) -> IambResult<EditInfo> {
|
||||
let client = &store.application.worker.client;
|
||||
|
||||
let settings = &store.application.settings;
|
||||
let info = store.application.rooms.entry(self.room_id.clone()).or_default();
|
||||
|
||||
let msg = self.scrollback.get_mut(info).ok_or(IambError::NoSelectedMessage)?;
|
||||
|
||||
match act {
|
||||
MessageAction::Cancel => {
|
||||
self.reply_to = None;
|
||||
|
||||
Ok(None)
|
||||
},
|
||||
MessageAction::Download(filename, force) => {
|
||||
if let MessageEvent::Original(ev) = &msg.event {
|
||||
let media = client.media();
|
||||
|
||||
let mut filename = match filename {
|
||||
Some(f) => PathBuf::from(f),
|
||||
None => settings.dirs.downloads.clone(),
|
||||
};
|
||||
|
||||
let source = match &ev.content.msgtype {
|
||||
MessageType::Audio(c) => {
|
||||
if filename.is_dir() {
|
||||
filename.push(c.body.as_str());
|
||||
}
|
||||
|
||||
c.source.clone()
|
||||
},
|
||||
MessageType::File(c) => {
|
||||
if filename.is_dir() {
|
||||
if let Some(name) = &c.filename {
|
||||
filename.push(name);
|
||||
} else {
|
||||
filename.push(c.body.as_str());
|
||||
}
|
||||
}
|
||||
|
||||
c.source.clone()
|
||||
},
|
||||
MessageType::Image(c) => {
|
||||
if filename.is_dir() {
|
||||
filename.push(c.body.as_str());
|
||||
}
|
||||
|
||||
c.source.clone()
|
||||
},
|
||||
MessageType::Video(c) => {
|
||||
if filename.is_dir() {
|
||||
filename.push(c.body.as_str());
|
||||
}
|
||||
|
||||
c.source.clone()
|
||||
},
|
||||
_ => {
|
||||
return Err(IambError::NoAttachment.into());
|
||||
},
|
||||
};
|
||||
|
||||
if !force && filename.exists() {
|
||||
let msg = format!(
|
||||
"The file {} already exists; use :download! to overwrite it.",
|
||||
filename.display()
|
||||
);
|
||||
let err = UIError::Failure(msg);
|
||||
|
||||
return Err(err);
|
||||
}
|
||||
|
||||
let req = MediaRequest { source, format: MediaFormat::File };
|
||||
|
||||
let bytes =
|
||||
media.get_media_content(&req, true).await.map_err(IambError::from)?;
|
||||
|
||||
fs::write(filename.as_path(), bytes.as_slice())?;
|
||||
|
||||
msg.downloaded = true;
|
||||
|
||||
let info = InfoMessage::from(format!(
|
||||
"Attachment downloaded to {}",
|
||||
filename.display()
|
||||
));
|
||||
|
||||
return Ok(info.into());
|
||||
}
|
||||
|
||||
Err(IambError::NoAttachment.into())
|
||||
},
|
||||
MessageAction::Redact(reason) => {
|
||||
let room = store
|
||||
.application
|
||||
.worker
|
||||
.client
|
||||
.get_joined_room(self.id())
|
||||
.ok_or(IambError::NotJoined)?;
|
||||
|
||||
let event_id = match &msg.event {
|
||||
MessageEvent::Original(ev) => ev.event_id.clone(),
|
||||
MessageEvent::Local(_) => {
|
||||
self.scrollback.get_key(info).ok_or(IambError::NoSelectedMessage)?.1
|
||||
},
|
||||
MessageEvent::Redacted(_) => {
|
||||
let msg = "";
|
||||
let err = UIError::Failure(msg.into());
|
||||
|
||||
return Err(err);
|
||||
},
|
||||
};
|
||||
|
||||
let event_id = event_id.as_ref();
|
||||
let reason = reason.as_deref();
|
||||
let _ = room.redact(event_id, reason, None).await.map_err(IambError::from)?;
|
||||
|
||||
Ok(None)
|
||||
},
|
||||
MessageAction::Reply => {
|
||||
self.reply_to = self.scrollback.get_key(info);
|
||||
self.focus = RoomFocus::MessageBar;
|
||||
|
||||
Ok(None)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn send_command(
|
||||
&mut self,
|
||||
act: SendAction,
|
||||
_: ProgramContext,
|
||||
store: &mut ProgramStore,
|
||||
) -> IambResult<EditInfo> {
|
||||
let room = store
|
||||
.application
|
||||
.worker
|
||||
.client
|
||||
.get_joined_room(self.id())
|
||||
.ok_or(IambError::NotJoined)?;
|
||||
let info = store.application.rooms.entry(self.id().to_owned()).or_default();
|
||||
|
||||
let (event_id, msg) = match act {
|
||||
SendAction::Submit => {
|
||||
let msg = self.tbox.get_text();
|
||||
|
||||
if msg.is_empty() {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let msg = TextMessageEventContent::plain(msg);
|
||||
let msg = MessageType::Text(msg);
|
||||
|
||||
let mut msg = RoomMessageEventContent::new(msg);
|
||||
|
||||
if let Some(m) = self.get_reply_to(info) {
|
||||
// XXX: Switch to RoomMessageEventContent::reply() once it's stable?
|
||||
msg = msg.make_reply_to(m);
|
||||
}
|
||||
|
||||
// XXX: second parameter can be a locally unique transaction id.
|
||||
// Useful for doing retries.
|
||||
let resp = room.send(msg.clone(), None).await.map_err(IambError::from)?;
|
||||
let event_id = resp.event_id;
|
||||
|
||||
// Reset message bar state now that it's been sent.
|
||||
self.reset();
|
||||
|
||||
(event_id, msg)
|
||||
},
|
||||
SendAction::Upload(file) => {
|
||||
let path = Path::new(file.as_str());
|
||||
let mime = mime_guess::from_path(path).first_or(mime::APPLICATION_OCTET_STREAM);
|
||||
|
||||
let bytes = fs::read(path)?;
|
||||
let name = path
|
||||
.file_name()
|
||||
.map(OsStr::to_string_lossy)
|
||||
.unwrap_or_else(|| Cow::from("Attachment"));
|
||||
let config = AttachmentConfig::new();
|
||||
|
||||
let resp = room
|
||||
.send_attachment(name.as_ref(), &mime, bytes.as_ref(), config)
|
||||
.await
|
||||
.map_err(IambError::from)?;
|
||||
|
||||
// Mock up the local echo message for the scrollback.
|
||||
let msg = TextMessageEventContent::plain(format!("[Attached File: {}]", name));
|
||||
let msg = MessageType::Text(msg);
|
||||
let msg = RoomMessageEventContent::new(msg);
|
||||
|
||||
(resp.event_id, msg)
|
||||
},
|
||||
};
|
||||
|
||||
let user = store.application.settings.profile.user_id.clone();
|
||||
let key = (MessageTimeStamp::LocalEcho, event_id);
|
||||
let msg = MessageEvent::Local(msg.into());
|
||||
let msg = Message::new(msg, user, MessageTimeStamp::LocalEcho);
|
||||
info.messages.insert(key, msg);
|
||||
|
||||
// Jump to the end of the scrollback to show the message.
|
||||
self.scrollback.goto_latest();
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
pub fn focus_toggle(&mut self) {
|
||||
self.focus = match self.focus {
|
||||
RoomFocus::Scrollback => RoomFocus::MessageBar,
|
||||
@@ -147,6 +411,8 @@ impl WindowOps<IambInfo> for ChatState {
|
||||
|
||||
scrollback: self.scrollback.dup(store),
|
||||
focus: self.focus,
|
||||
|
||||
reply_to: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,17 +495,9 @@ impl PromptActions<ProgramContext, ProgramStore, IambInfo> for ChatState {
|
||||
ctx: &ProgramContext,
|
||||
_: &mut ProgramStore,
|
||||
) -> EditResult<Vec<(ProgramAction, ProgramContext)>, IambInfo> {
|
||||
let txt = self.tbox.reset_text();
|
||||
let act = SendAction::Submit;
|
||||
|
||||
let act = if txt.is_empty() {
|
||||
vec![]
|
||||
} else {
|
||||
let act = IambAction::SendMessage(self.room_id.clone(), txt).into();
|
||||
|
||||
vec![(act, ctx.clone())]
|
||||
};
|
||||
|
||||
Ok(act)
|
||||
Ok(vec![(IambAction::from(act).into(), ctx.clone())])
|
||||
}
|
||||
|
||||
fn abort(
|
||||
@@ -254,7 +512,7 @@ impl PromptActions<ProgramContext, ProgramStore, IambInfo> for ChatState {
|
||||
return Ok(vec![]);
|
||||
}
|
||||
|
||||
let text = self.tbox.reset().trim();
|
||||
let text = self.reset().trim();
|
||||
|
||||
if text.is_empty() {
|
||||
let _ = self.sent.end();
|
||||
@@ -328,15 +586,34 @@ impl<'a> StatefulWidget for Chat<'a> {
|
||||
let lines = state.tbox.has_lines(5).max(1) as u16;
|
||||
let drawh = area.height;
|
||||
let texth = lines.min(drawh).clamp(1, 5);
|
||||
let scrollh = drawh.saturating_sub(texth);
|
||||
let desch = if state.reply_to.is_some() {
|
||||
drawh.saturating_sub(texth).min(1)
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let scrollh = drawh.saturating_sub(texth).saturating_sub(desch);
|
||||
|
||||
let scrollarea = Rect::new(area.x, area.y, area.width, scrollh);
|
||||
let textarea = Rect::new(scrollarea.x, scrollarea.y + scrollh, scrollarea.width, texth);
|
||||
let descarea = Rect::new(area.x, scrollarea.y + scrollh, area.width, desch);
|
||||
let textarea = Rect::new(area.x, descarea.y + desch, area.width, texth);
|
||||
|
||||
let scrollback_focused = state.focus.is_scrollback() && self.focused;
|
||||
let scrollback = Scrollback::new(self.store).focus(scrollback_focused);
|
||||
scrollback.render(scrollarea, buf, &mut state.scrollback);
|
||||
|
||||
let desc_spans = state.reply_to.as_ref().and_then(|k| {
|
||||
let room = self.store.application.rooms.get(state.id())?;
|
||||
let msg = room.messages.get(k)?;
|
||||
let user = self.store.application.settings.get_user_span(msg.sender.as_ref());
|
||||
let spans = Spans(vec![Span::from("Replying to "), user]);
|
||||
|
||||
spans.into()
|
||||
});
|
||||
|
||||
if let Some(desc_spans) = desc_spans {
|
||||
Paragraph::new(desc_spans).render(descarea, buf);
|
||||
}
|
||||
|
||||
let prompt = if self.focused { "> " } else { " " };
|
||||
|
||||
let tbox = TextBox::new().prompt(prompt);
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
use matrix_sdk::room::Room as MatrixRoom;
|
||||
use matrix_sdk::ruma::RoomId;
|
||||
use matrix_sdk::DisplayName;
|
||||
use matrix_sdk::{
|
||||
room::{Invited, Room as MatrixRoom},
|
||||
ruma::RoomId,
|
||||
DisplayName,
|
||||
};
|
||||
|
||||
use modalkit::tui::{
|
||||
buffer::Buffer,
|
||||
layout::Rect,
|
||||
layout::{Alignment, Rect},
|
||||
style::{Modifier as StyleModifier, Style},
|
||||
text::{Span, Spans},
|
||||
widgets::StatefulWidget,
|
||||
text::{Span, Spans, Text},
|
||||
widgets::{Paragraph, StatefulWidget, Widget},
|
||||
};
|
||||
|
||||
use modalkit::{
|
||||
@@ -37,13 +39,16 @@ use modalkit::{
|
||||
};
|
||||
|
||||
use crate::base::{
|
||||
IambError,
|
||||
IambId,
|
||||
IambInfo,
|
||||
IambResult,
|
||||
MessageAction,
|
||||
ProgramAction,
|
||||
ProgramContext,
|
||||
ProgramStore,
|
||||
RoomAction,
|
||||
SendAction,
|
||||
};
|
||||
|
||||
use self::chat::ChatState;
|
||||
@@ -92,13 +97,106 @@ impl RoomState {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn room_command(
|
||||
pub fn refresh_room(&mut self, store: &mut ProgramStore) {
|
||||
match self {
|
||||
RoomState::Chat(chat) => chat.refresh_room(store),
|
||||
RoomState::Space(space) => space.refresh_room(store),
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_invite(
|
||||
&self,
|
||||
invited: Invited,
|
||||
area: Rect,
|
||||
buf: &mut Buffer,
|
||||
store: &mut ProgramStore,
|
||||
) {
|
||||
let inviter = store.application.worker.get_inviter(invited.clone());
|
||||
|
||||
let name = match invited.canonical_alias() {
|
||||
Some(alias) => alias.to_string(),
|
||||
None => format!("{:?}", store.application.get_room_title(self.id())),
|
||||
};
|
||||
|
||||
let mut invited = vec![Span::from(format!(
|
||||
"You have been invited to join {}",
|
||||
name
|
||||
))];
|
||||
|
||||
if let Ok(Some(inviter)) = &inviter {
|
||||
invited.push(Span::from(" by "));
|
||||
invited.push(store.application.settings.get_user_span(inviter.user_id()));
|
||||
}
|
||||
|
||||
let l1 = Spans(invited);
|
||||
let l2 = Spans::from(
|
||||
"You can run `:invite accept` or `:invite reject` to accept or reject this invitation.",
|
||||
);
|
||||
let text = Text { lines: vec![l1, l2] };
|
||||
|
||||
Paragraph::new(text).alignment(Alignment::Center).render(area, buf);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
pub async fn message_command(
|
||||
&mut self,
|
||||
act: MessageAction,
|
||||
ctx: ProgramContext,
|
||||
store: &mut ProgramStore,
|
||||
) -> IambResult<EditInfo> {
|
||||
match self {
|
||||
RoomState::Chat(chat) => chat.message_command(act, ctx, store).await,
|
||||
RoomState::Space(_) => Err(IambError::NoSelectedMessage.into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn send_command(
|
||||
&mut self,
|
||||
act: SendAction,
|
||||
ctx: ProgramContext,
|
||||
store: &mut ProgramStore,
|
||||
) -> IambResult<EditInfo> {
|
||||
match self {
|
||||
RoomState::Chat(chat) => chat.send_command(act, ctx, store).await,
|
||||
RoomState::Space(_) => Err(IambError::NoSelectedRoom.into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn room_command(
|
||||
&mut self,
|
||||
act: RoomAction,
|
||||
_: ProgramContext,
|
||||
store: &mut ProgramStore,
|
||||
) -> IambResult<Vec<(Action<IambInfo>, ProgramContext)>> {
|
||||
match act {
|
||||
RoomAction::InviteAccept => {
|
||||
if let Some(room) = store.application.worker.client.get_invited_room(self.id()) {
|
||||
room.accept_invitation().await.map_err(IambError::from)?;
|
||||
|
||||
Ok(vec![])
|
||||
} else {
|
||||
Err(IambError::NotInvited.into())
|
||||
}
|
||||
},
|
||||
RoomAction::InviteReject => {
|
||||
if let Some(room) = store.application.worker.client.get_invited_room(self.id()) {
|
||||
room.reject_invitation().await.map_err(IambError::from)?;
|
||||
|
||||
Ok(vec![])
|
||||
} else {
|
||||
Err(IambError::NotInvited.into())
|
||||
}
|
||||
},
|
||||
RoomAction::InviteSend(user) => {
|
||||
if let Some(room) = store.application.worker.client.get_joined_room(self.id()) {
|
||||
room.invite_user_by_id(user.as_ref()).await.map_err(IambError::from)?;
|
||||
|
||||
Ok(vec![])
|
||||
} else {
|
||||
Err(IambError::NotJoined.into())
|
||||
}
|
||||
},
|
||||
RoomAction::Members(mut cmd) => {
|
||||
let width = Count::Exact(30);
|
||||
let act =
|
||||
@@ -209,6 +307,14 @@ impl TerminalCursor for RoomState {
|
||||
|
||||
impl WindowOps<IambInfo> for RoomState {
|
||||
fn draw(&mut self, area: Rect, buf: &mut Buffer, focused: bool, store: &mut ProgramStore) {
|
||||
if let MatrixRoom::Invited(_) = self.room() {
|
||||
self.refresh_room(store);
|
||||
}
|
||||
|
||||
if let MatrixRoom::Invited(invited) = self.room() {
|
||||
self.draw_invite(invited.clone(), area, buf, store);
|
||||
}
|
||||
|
||||
match self {
|
||||
RoomState::Chat(chat) => chat.draw(area, buf, focused, store),
|
||||
RoomState::Space(space) => {
|
||||
|
||||
@@ -61,6 +61,7 @@ use modalkit::editing::{
|
||||
|
||||
use crate::{
|
||||
base::{IambBufferId, IambInfo, ProgramContext, ProgramStore, RoomFocus, RoomInfo},
|
||||
config::ApplicationSettings,
|
||||
message::{Message, MessageCursor, MessageKey},
|
||||
};
|
||||
|
||||
@@ -103,11 +104,26 @@ fn nth_after(pos: MessageKey, n: usize, info: &RoomInfo) -> MessageCursor {
|
||||
}
|
||||
|
||||
pub struct ScrollbackState {
|
||||
/// The room identifier.
|
||||
room_id: OwnedRoomId,
|
||||
|
||||
/// The buffer identifier used for saving marks, etc.
|
||||
id: IambBufferId,
|
||||
|
||||
/// The currently selected message in the scrollback.
|
||||
cursor: MessageCursor,
|
||||
|
||||
/// Contextual info about the viewport used during rendering.
|
||||
viewctx: ViewportContext<MessageCursor>,
|
||||
|
||||
/// The jumplist of visited messages.
|
||||
jumped: HistoryList<MessageCursor>,
|
||||
|
||||
/// Whether the full message should be drawn during the next render() call.
|
||||
///
|
||||
/// This is used to ensure that ^E/^Y work nicely when the cursor is currently
|
||||
/// on a multiline message.
|
||||
show_full_on_redraw: bool,
|
||||
}
|
||||
|
||||
impl ScrollbackState {
|
||||
@@ -116,8 +132,20 @@ impl ScrollbackState {
|
||||
let cursor = MessageCursor::default();
|
||||
let viewctx = ViewportContext::default();
|
||||
let jumped = HistoryList::default();
|
||||
let show_full_on_redraw = false;
|
||||
|
||||
ScrollbackState { room_id, id, cursor, viewctx, jumped }
|
||||
ScrollbackState {
|
||||
room_id,
|
||||
id,
|
||||
cursor,
|
||||
viewctx,
|
||||
jumped,
|
||||
show_full_on_redraw,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn goto_latest(&mut self) {
|
||||
self.cursor = MessageCursor::latest();
|
||||
}
|
||||
|
||||
/// Set the dimensions and placement within the terminal window for this list.
|
||||
@@ -125,6 +153,21 @@ impl ScrollbackState {
|
||||
self.viewctx.dimensions = (area.width as usize, area.height as usize);
|
||||
}
|
||||
|
||||
pub fn get_key(&self, info: &mut RoomInfo) -> Option<MessageKey> {
|
||||
self.cursor
|
||||
.timestamp
|
||||
.clone()
|
||||
.or_else(|| info.messages.last_key_value().map(|kv| kv.0.clone()))
|
||||
}
|
||||
|
||||
pub fn get_mut<'a>(&mut self, info: &'a mut RoomInfo) -> Option<&'a mut Message> {
|
||||
if let Some(k) = &self.cursor.timestamp {
|
||||
info.messages.get_mut(k)
|
||||
} else {
|
||||
info.messages.last_entry().map(|o| o.into_mut())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn messages<'a>(
|
||||
&self,
|
||||
range: EditRange<MessageCursor>,
|
||||
@@ -148,7 +191,13 @@ impl ScrollbackState {
|
||||
}
|
||||
}
|
||||
|
||||
fn scrollview(&mut self, idx: MessageKey, pos: MovePosition, info: &RoomInfo) {
|
||||
fn scrollview(
|
||||
&mut self,
|
||||
idx: MessageKey,
|
||||
pos: MovePosition,
|
||||
info: &RoomInfo,
|
||||
settings: &ApplicationSettings,
|
||||
) {
|
||||
let selidx = if let Some(key) = self.cursor.to_key(info) {
|
||||
key
|
||||
} else {
|
||||
@@ -165,7 +214,7 @@ impl ScrollbackState {
|
||||
|
||||
for (key, item) in info.messages.range(..=&idx).rev() {
|
||||
let sel = selidx == key;
|
||||
let len = item.show(sel, &self.viewctx).lines.len();
|
||||
let len = item.show(None, sel, &self.viewctx, settings).lines.len();
|
||||
|
||||
if key == &idx {
|
||||
lines += len / 2;
|
||||
@@ -187,7 +236,7 @@ impl ScrollbackState {
|
||||
|
||||
for (key, item) in info.messages.range(..=&idx).rev() {
|
||||
let sel = key == selidx;
|
||||
let len = item.show(sel, &self.viewctx).lines.len();
|
||||
let len = item.show(None, sel, &self.viewctx, settings).lines.len();
|
||||
|
||||
lines += len;
|
||||
|
||||
@@ -202,7 +251,7 @@ impl ScrollbackState {
|
||||
}
|
||||
}
|
||||
|
||||
fn shift_cursor(&mut self, info: &RoomInfo) {
|
||||
fn shift_cursor(&mut self, info: &RoomInfo, settings: &ApplicationSettings) {
|
||||
let last_key = if let Some(k) = info.messages.last_key_value() {
|
||||
k.0
|
||||
} else {
|
||||
@@ -227,7 +276,7 @@ impl ScrollbackState {
|
||||
break;
|
||||
}
|
||||
|
||||
lines += item.show(false, &self.viewctx).height().max(1);
|
||||
lines += item.show(None, false, &self.viewctx, settings).height().max(1);
|
||||
|
||||
if lines >= self.viewctx.get_height() {
|
||||
// We've reached the end of the viewport; move cursor into it.
|
||||
@@ -382,7 +431,7 @@ impl ScrollbackState {
|
||||
continue;
|
||||
}
|
||||
|
||||
if needle.is_match(msg.as_ref()) {
|
||||
if needle.is_match(msg.event.show().as_ref()) {
|
||||
mc = MessageCursor::from(key.clone()).into();
|
||||
count -= 1;
|
||||
}
|
||||
@@ -406,7 +455,7 @@ impl ScrollbackState {
|
||||
break;
|
||||
}
|
||||
|
||||
if needle.is_match(msg.as_ref()) {
|
||||
if needle.is_match(msg.event.show().as_ref()) {
|
||||
mc = MessageCursor::from(key.clone()).into();
|
||||
count -= 1;
|
||||
}
|
||||
@@ -447,6 +496,7 @@ impl WindowOps<IambInfo> for ScrollbackState {
|
||||
cursor: self.cursor.clone(),
|
||||
viewctx: self.viewctx.clone(),
|
||||
jumped: self.jumped.clone(),
|
||||
show_full_on_redraw: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -567,6 +617,8 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
|
||||
self.cursor = pos;
|
||||
}
|
||||
|
||||
self.show_full_on_redraw = true;
|
||||
|
||||
return Ok(None);
|
||||
},
|
||||
EditAction::Yank => {
|
||||
@@ -652,7 +704,7 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
|
||||
let mut yanked = EditRope::from("");
|
||||
|
||||
for (_, msg) in self.messages(range, info) {
|
||||
yanked += EditRope::from(msg.as_ref());
|
||||
yanked += EditRope::from(msg.event.show().into_owned());
|
||||
yanked += EditRope::from('\n');
|
||||
}
|
||||
|
||||
@@ -930,7 +982,8 @@ impl ScrollActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
|
||||
ctx: &ProgramContext,
|
||||
store: &mut ProgramStore,
|
||||
) -> EditResult<EditInfo, IambInfo> {
|
||||
let info = store.application.get_room_info(self.room_id.clone());
|
||||
let info = store.application.rooms.entry(self.room_id.clone()).or_default();
|
||||
let settings = &store.application.settings;
|
||||
let mut corner = self.viewctx.corner.clone();
|
||||
|
||||
let last_key = if let Some(k) = info.messages.last_key_value() {
|
||||
@@ -956,7 +1009,7 @@ impl ScrollActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
|
||||
|
||||
for (key, item) in info.messages.range(..=&corner_key).rev() {
|
||||
let sel = key == cursor_key;
|
||||
let txt = item.show(sel, &self.viewctx);
|
||||
let txt = item.show(None, sel, &self.viewctx, settings);
|
||||
let len = txt.height().max(1);
|
||||
let max = len.saturating_sub(1);
|
||||
|
||||
@@ -982,7 +1035,7 @@ impl ScrollActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
|
||||
MoveDir2D::Down => {
|
||||
for (key, item) in info.messages.range(&corner_key..) {
|
||||
let sel = key == cursor_key;
|
||||
let txt = item.show(sel, &self.viewctx);
|
||||
let txt = item.show(None, sel, &self.viewctx, settings);
|
||||
let len = txt.height().max(1);
|
||||
let max = len.saturating_sub(1);
|
||||
|
||||
@@ -1018,7 +1071,7 @@ impl ScrollActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
|
||||
}
|
||||
|
||||
self.viewctx.corner = corner;
|
||||
self.shift_cursor(info);
|
||||
self.shift_cursor(info, settings);
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
@@ -1038,10 +1091,11 @@ impl ScrollActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
|
||||
Err(err)
|
||||
},
|
||||
Axis::Vertical => {
|
||||
let info = store.application.get_room_info(self.room_id.clone());
|
||||
let info = store.application.rooms.entry(self.room_id.clone()).or_default();
|
||||
let settings = &store.application.settings;
|
||||
|
||||
if let Some(key) = self.cursor.to_key(info).cloned() {
|
||||
self.scrollview(key, pos, info);
|
||||
self.scrollview(key, pos, info, settings);
|
||||
}
|
||||
|
||||
Ok(None)
|
||||
@@ -1126,6 +1180,7 @@ impl<'a> StatefulWidget for Scrollback<'a> {
|
||||
|
||||
fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
|
||||
let info = self.store.application.rooms.entry(state.room_id.clone()).or_default();
|
||||
let settings = &self.store.application.settings;
|
||||
let area = info.render_typing(area, buf, &self.store.application.settings);
|
||||
|
||||
state.set_term_info(area);
|
||||
@@ -1149,21 +1204,28 @@ impl<'a> StatefulWidget for Scrollback<'a> {
|
||||
};
|
||||
|
||||
let corner = &state.viewctx.corner;
|
||||
let corner_key = match (&corner.timestamp, &cursor.timestamp) {
|
||||
(_, None) => nth_key_before(cursor_key.clone(), height, info),
|
||||
(None, _) => nth_key_before(cursor_key.clone(), height, info),
|
||||
(Some(k), _) => k.clone(),
|
||||
let corner_key = if let Some(k) = &corner.timestamp {
|
||||
k.clone()
|
||||
} else {
|
||||
nth_key_before(cursor_key.clone(), height, info)
|
||||
};
|
||||
|
||||
let foc = self.focused || cursor.timestamp.is_some();
|
||||
let full = std::mem::take(&mut state.show_full_on_redraw) || cursor.timestamp.is_none();
|
||||
let mut lines = vec![];
|
||||
let mut sawit = false;
|
||||
let mut prev = None;
|
||||
|
||||
for (key, item) in info.messages.range(&corner_key..) {
|
||||
let sel = key == cursor_key;
|
||||
let txt = item.show(self.focused && sel, &state.viewctx);
|
||||
let txt = item.show(prev, foc && sel, &state.viewctx, settings);
|
||||
|
||||
prev = Some(item);
|
||||
|
||||
let incomplete_ok = !full || !sel;
|
||||
|
||||
for (row, line) in txt.lines.into_iter().enumerate() {
|
||||
if sawit && lines.len() >= height {
|
||||
if sawit && lines.len() >= height && incomplete_ok {
|
||||
// Check whether we've seen the first line of the
|
||||
// selected message and can fill the screen.
|
||||
break;
|
||||
@@ -1211,10 +1273,10 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::tests::*;
|
||||
|
||||
#[test]
|
||||
fn test_search_messages() {
|
||||
#[tokio::test]
|
||||
async fn test_search_messages() {
|
||||
let room_id = TEST_ROOM1_ID.clone();
|
||||
let mut store = mock_store();
|
||||
let mut store = mock_store().await;
|
||||
let mut scrollback = ScrollbackState::new(room_id.clone());
|
||||
let ctx = ProgramContext::default();
|
||||
|
||||
@@ -1255,9 +1317,9 @@ mod tests {
|
||||
assert_eq!(scrollback.cursor, MSG1_KEY.clone().into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_movement() {
|
||||
let mut store = mock_store();
|
||||
#[tokio::test]
|
||||
async fn test_movement() {
|
||||
let mut store = mock_store().await;
|
||||
let mut scrollback = ScrollbackState::new(TEST_ROOM1_ID.clone());
|
||||
let ctx = ProgramContext::default();
|
||||
|
||||
@@ -1289,9 +1351,9 @@ mod tests {
|
||||
assert_eq!(scrollback.cursor, MSG1_KEY.clone().into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dirscroll() {
|
||||
let mut store = mock_store();
|
||||
#[tokio::test]
|
||||
async fn test_dirscroll() {
|
||||
let mut store = mock_store().await;
|
||||
let mut scrollback = ScrollbackState::new(TEST_ROOM1_ID.clone());
|
||||
let ctx = ProgramContext::default();
|
||||
|
||||
@@ -1423,9 +1485,9 @@ mod tests {
|
||||
assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG3_KEY.clone(), 4));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cursorpos() {
|
||||
let mut store = mock_store();
|
||||
#[tokio::test]
|
||||
async fn test_cursorpos() {
|
||||
let mut store = mock_store().await;
|
||||
let mut scrollback = ScrollbackState::new(TEST_ROOM1_ID.clone());
|
||||
let ctx = ProgramContext::default();
|
||||
|
||||
|
||||
@@ -31,6 +31,12 @@ impl SpaceState {
|
||||
SpaceState { room_id, room, list }
|
||||
}
|
||||
|
||||
pub fn refresh_room(&mut self, store: &mut ProgramStore) {
|
||||
if let Some(room) = store.application.worker.client.get_room(self.id()) {
|
||||
self.room = room;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn room(&self) -> &MatrixRoom {
|
||||
&self.room
|
||||
}
|
||||
@@ -88,7 +94,13 @@ impl<'a> StatefulWidget for Space<'a> {
|
||||
type State = SpaceState;
|
||||
|
||||
fn render(self, area: Rect, buffer: &mut Buffer, state: &mut Self::State) {
|
||||
let members = self.store.application.worker.space_members(state.room_id.clone()).unwrap();
|
||||
let members =
|
||||
if let Ok(m) = self.store.application.worker.space_members(state.room_id.clone()) {
|
||||
m
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
|
||||
let items = members
|
||||
.into_iter()
|
||||
.filter_map(|id| {
|
||||
|
||||
343
src/worker.rs
343
src/worker.rs
@@ -1,12 +1,14 @@
|
||||
use std::convert::TryFrom;
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::fs::File;
|
||||
use std::io::BufWriter;
|
||||
use std::str::FromStr;
|
||||
use std::sync::mpsc::{sync_channel, Receiver, RecvTimeoutError, SyncSender};
|
||||
use std::sync::mpsc::{sync_channel, Receiver, SyncSender};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use gethostname::gethostname;
|
||||
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
|
||||
use tokio::task::JoinHandle;
|
||||
use tracing::error;
|
||||
|
||||
@@ -15,7 +17,7 @@ use matrix_sdk::{
|
||||
encryption::verification::{SasVerification, Verification},
|
||||
event_handler::Ctx,
|
||||
reqwest,
|
||||
room::{Messages, MessagesOptions, Room as MatrixRoom, RoomMember},
|
||||
room::{Invited, Messages, MessagesOptions, Room as MatrixRoom, RoomMember},
|
||||
ruma::{
|
||||
api::client::{
|
||||
room::create_room::v3::{Request as CreateRoomRequest, RoomPreset},
|
||||
@@ -31,8 +33,9 @@ use matrix_sdk::{
|
||||
VerificationMethod,
|
||||
},
|
||||
room::{
|
||||
message::{MessageType, RoomMessageEventContent, TextMessageEventContent},
|
||||
message::{MessageType, RoomMessageEventContent},
|
||||
name::RoomNameEventContent,
|
||||
redaction::{OriginalSyncRoomRedactionEvent, SyncRoomRedactionEvent},
|
||||
topic::RoomTopicEventContent,
|
||||
},
|
||||
typing::SyncTypingEvent,
|
||||
@@ -41,10 +44,10 @@ use matrix_sdk::{
|
||||
SyncMessageLikeEvent,
|
||||
SyncStateEvent,
|
||||
},
|
||||
OwnedEventId,
|
||||
OwnedRoomId,
|
||||
OwnedRoomOrAliasId,
|
||||
OwnedUserId,
|
||||
RoomVersionId,
|
||||
},
|
||||
Client,
|
||||
DisplayName,
|
||||
@@ -67,6 +70,7 @@ fn initial_devname() -> String {
|
||||
format!("{} on {}", IAMB_DEVICE_NAME, gethostname().to_string_lossy())
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum LoginStyle {
|
||||
SessionRestore(Session),
|
||||
Password(String),
|
||||
@@ -95,29 +99,116 @@ fn oneshot<T>() -> (ClientReply<T>, ClientResponse<T>) {
|
||||
return (reply, response);
|
||||
}
|
||||
|
||||
type EchoPair = (OwnedEventId, RoomMessageEventContent);
|
||||
|
||||
pub enum WorkerTask {
|
||||
ActiveRooms(ClientReply<Vec<(MatrixRoom, DisplayName)>>),
|
||||
DirectMessages(ClientReply<Vec<(MatrixRoom, DisplayName)>>),
|
||||
Init(AsyncProgramStore, ClientReply<()>),
|
||||
LoadOlder(OwnedRoomId, Option<String>, u32, ClientReply<MessageFetchResult>),
|
||||
Login(LoginStyle, ClientReply<IambResult<EditInfo>>),
|
||||
GetInviter(Invited, ClientReply<IambResult<Option<RoomMember>>>),
|
||||
GetRoom(OwnedRoomId, ClientReply<IambResult<(MatrixRoom, DisplayName)>>),
|
||||
JoinRoom(String, ClientReply<IambResult<OwnedRoomId>>),
|
||||
JoinedRooms(ClientReply<Vec<(MatrixRoom, DisplayName)>>),
|
||||
Members(OwnedRoomId, ClientReply<IambResult<Vec<RoomMember>>>),
|
||||
SpaceMembers(OwnedRoomId, ClientReply<IambResult<Vec<OwnedRoomId>>>),
|
||||
Spaces(ClientReply<Vec<(MatrixRoom, DisplayName)>>),
|
||||
SendMessage(OwnedRoomId, String, ClientReply<IambResult<EchoPair>>),
|
||||
SetRoom(OwnedRoomId, SetRoomField, ClientReply<IambResult<()>>),
|
||||
TypingNotice(OwnedRoomId),
|
||||
Verify(VerifyAction, SasVerification, ClientReply<IambResult<EditInfo>>),
|
||||
VerifyRequest(OwnedUserId, ClientReply<IambResult<EditInfo>>),
|
||||
}
|
||||
|
||||
impl Debug for WorkerTask {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
match self {
|
||||
WorkerTask::ActiveRooms(_) => {
|
||||
f.debug_tuple("WorkerTask::ActiveRooms").field(&format_args!("_")).finish()
|
||||
},
|
||||
WorkerTask::DirectMessages(_) => {
|
||||
f.debug_tuple("WorkerTask::DirectMessages")
|
||||
.field(&format_args!("_"))
|
||||
.finish()
|
||||
},
|
||||
WorkerTask::Init(_, _) => {
|
||||
f.debug_tuple("WorkerTask::Init")
|
||||
.field(&format_args!("_"))
|
||||
.field(&format_args!("_"))
|
||||
.finish()
|
||||
},
|
||||
WorkerTask::LoadOlder(room_id, from, n, _) => {
|
||||
f.debug_tuple("WorkerTask::LoadOlder")
|
||||
.field(room_id)
|
||||
.field(from)
|
||||
.field(n)
|
||||
.field(&format_args!("_"))
|
||||
.finish()
|
||||
},
|
||||
WorkerTask::Login(style, _) => {
|
||||
f.debug_tuple("WorkerTask::Login")
|
||||
.field(style)
|
||||
.field(&format_args!("_"))
|
||||
.finish()
|
||||
},
|
||||
WorkerTask::GetInviter(invite, _) => {
|
||||
f.debug_tuple("WorkerTask::GetInviter").field(invite).finish()
|
||||
},
|
||||
WorkerTask::GetRoom(room_id, _) => {
|
||||
f.debug_tuple("WorkerTask::GetRoom")
|
||||
.field(room_id)
|
||||
.field(&format_args!("_"))
|
||||
.finish()
|
||||
},
|
||||
WorkerTask::JoinRoom(s, _) => {
|
||||
f.debug_tuple("WorkerTask::JoinRoom")
|
||||
.field(s)
|
||||
.field(&format_args!("_"))
|
||||
.finish()
|
||||
},
|
||||
WorkerTask::Members(room_id, _) => {
|
||||
f.debug_tuple("WorkerTask::Members")
|
||||
.field(room_id)
|
||||
.field(&format_args!("_"))
|
||||
.finish()
|
||||
},
|
||||
WorkerTask::SpaceMembers(room_id, _) => {
|
||||
f.debug_tuple("WorkerTask::SpaceMembers")
|
||||
.field(room_id)
|
||||
.field(&format_args!("_"))
|
||||
.finish()
|
||||
},
|
||||
WorkerTask::Spaces(_) => {
|
||||
f.debug_tuple("WorkerTask::Spaces").field(&format_args!("_")).finish()
|
||||
},
|
||||
WorkerTask::SetRoom(room_id, field, _) => {
|
||||
f.debug_tuple("WorkerTask::SetRoom")
|
||||
.field(room_id)
|
||||
.field(field)
|
||||
.field(&format_args!("_"))
|
||||
.finish()
|
||||
},
|
||||
WorkerTask::TypingNotice(room_id) => {
|
||||
f.debug_tuple("WorkerTask::TypingNotice").field(room_id).finish()
|
||||
},
|
||||
WorkerTask::Verify(act, sasv1, _) => {
|
||||
f.debug_tuple("WorkerTask::Verify")
|
||||
.field(act)
|
||||
.field(sasv1)
|
||||
.field(&format_args!("_"))
|
||||
.finish()
|
||||
},
|
||||
WorkerTask::VerifyRequest(user_id, _) => {
|
||||
f.debug_tuple("WorkerTask::VerifyRequest")
|
||||
.field(user_id)
|
||||
.field(&format_args!("_"))
|
||||
.finish()
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Requester {
|
||||
pub tx: SyncSender<WorkerTask>,
|
||||
pub client: Client,
|
||||
pub tx: UnboundedSender<WorkerTask>,
|
||||
}
|
||||
|
||||
impl Requester {
|
||||
@@ -152,14 +243,6 @@ impl Requester {
|
||||
return response.recv();
|
||||
}
|
||||
|
||||
pub fn send_message(&self, room_id: OwnedRoomId, msg: String) -> IambResult<EchoPair> {
|
||||
let (reply, response) = oneshot();
|
||||
|
||||
self.tx.send(WorkerTask::SendMessage(room_id, msg, reply)).unwrap();
|
||||
|
||||
return response.recv();
|
||||
}
|
||||
|
||||
pub fn direct_messages(&self) -> Vec<(MatrixRoom, DisplayName)> {
|
||||
let (reply, response) = oneshot();
|
||||
|
||||
@@ -168,6 +251,14 @@ impl Requester {
|
||||
return response.recv();
|
||||
}
|
||||
|
||||
pub fn get_inviter(&self, invite: Invited) -> IambResult<Option<RoomMember>> {
|
||||
let (reply, response) = oneshot();
|
||||
|
||||
self.tx.send(WorkerTask::GetInviter(invite, reply)).unwrap();
|
||||
|
||||
return response.recv();
|
||||
}
|
||||
|
||||
pub fn get_room(&self, room_id: OwnedRoomId) -> IambResult<(MatrixRoom, DisplayName)> {
|
||||
let (reply, response) = oneshot();
|
||||
|
||||
@@ -184,10 +275,10 @@ impl Requester {
|
||||
return response.recv();
|
||||
}
|
||||
|
||||
pub fn joined_rooms(&self) -> Vec<(MatrixRoom, DisplayName)> {
|
||||
pub fn active_rooms(&self) -> Vec<(MatrixRoom, DisplayName)> {
|
||||
let (reply, response) = oneshot();
|
||||
|
||||
self.tx.send(WorkerTask::JoinedRooms(reply)).unwrap();
|
||||
self.tx.send(WorkerTask::ActiveRooms(reply)).unwrap();
|
||||
|
||||
return response.recv();
|
||||
}
|
||||
@@ -253,60 +344,57 @@ pub struct ClientWorker {
|
||||
}
|
||||
|
||||
impl ClientWorker {
|
||||
pub fn spawn(settings: ApplicationSettings) -> Requester {
|
||||
let (tx, rx) = sync_channel(5);
|
||||
pub async fn spawn(settings: ApplicationSettings) -> Requester {
|
||||
let (tx, rx) = unbounded_channel();
|
||||
let account = &settings.profile;
|
||||
|
||||
// Set up a custom client that only uses HTTP/1.
|
||||
//
|
||||
// During my testing, I kept stumbling across something weird with sync and HTTP/2 that
|
||||
// will need to be revisited in the future.
|
||||
let http = reqwest::Client::builder()
|
||||
.user_agent(IAMB_USER_AGENT)
|
||||
.timeout(Duration::from_secs(30))
|
||||
.pool_idle_timeout(Duration::from_secs(60))
|
||||
.pool_max_idle_per_host(10)
|
||||
.tcp_keepalive(Duration::from_secs(10))
|
||||
.http1_only()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
// Set up the Matrix client for the selected profile.
|
||||
let client = Client::builder()
|
||||
.http_client(Arc::new(http))
|
||||
.homeserver_url(account.url.clone())
|
||||
.store_config(StoreConfig::default())
|
||||
.sled_store(settings.matrix_dir.as_path(), None)
|
||||
.expect("Failed to setup up sled store for Matrix SDK")
|
||||
.request_config(RequestConfig::new().timeout(REQ_TIMEOUT).retry_timeout(REQ_TIMEOUT))
|
||||
.build()
|
||||
.await
|
||||
.expect("Failed to instantiate Matrix client");
|
||||
|
||||
let mut worker = ClientWorker {
|
||||
initialized: false,
|
||||
settings,
|
||||
client: client.clone(),
|
||||
sync_handle: None,
|
||||
};
|
||||
|
||||
let _ = tokio::spawn(async move {
|
||||
let account = &settings.profile;
|
||||
|
||||
// Set up a custom client that only uses HTTP/1.
|
||||
//
|
||||
// During my testing, I kept stumbling across something weird with sync and HTTP/2 that
|
||||
// will need to be revisited in the future.
|
||||
let http = reqwest::Client::builder()
|
||||
.user_agent(IAMB_USER_AGENT)
|
||||
.timeout(Duration::from_secs(60))
|
||||
.pool_idle_timeout(Duration::from_secs(120))
|
||||
.pool_max_idle_per_host(5)
|
||||
.http1_only()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
// Set up the Matrix client for the selected profile.
|
||||
let client = Client::builder()
|
||||
.http_client(Arc::new(http))
|
||||
.homeserver_url(account.url.clone())
|
||||
.store_config(StoreConfig::default())
|
||||
.sled_store(settings.matrix_dir.as_path(), None)
|
||||
.expect("Failed to setup up sled store for Matrix SDK")
|
||||
.request_config(
|
||||
RequestConfig::new().timeout(REQ_TIMEOUT).retry_timeout(REQ_TIMEOUT),
|
||||
)
|
||||
.build()
|
||||
.await
|
||||
.expect("Failed to instantiate Matrix client");
|
||||
|
||||
let mut worker = ClientWorker {
|
||||
initialized: false,
|
||||
settings,
|
||||
client,
|
||||
sync_handle: None,
|
||||
};
|
||||
|
||||
worker.work(rx).await;
|
||||
});
|
||||
|
||||
return Requester { tx };
|
||||
return Requester { client, tx };
|
||||
}
|
||||
|
||||
async fn work(&mut self, rx: Receiver<WorkerTask>) {
|
||||
async fn work(&mut self, mut rx: UnboundedReceiver<WorkerTask>) {
|
||||
loop {
|
||||
let t = rx.recv_timeout(Duration::from_secs(1));
|
||||
let t = rx.recv().await;
|
||||
|
||||
match t {
|
||||
Ok(task) => self.run(task).await,
|
||||
Err(RecvTimeoutError::Timeout) => {},
|
||||
Err(RecvTimeoutError::Disconnected) => {
|
||||
Some(task) => self.run(task).await,
|
||||
None => {
|
||||
break;
|
||||
},
|
||||
}
|
||||
@@ -332,13 +420,17 @@ impl ClientWorker {
|
||||
assert!(self.initialized);
|
||||
reply.send(self.join_room(room_id).await);
|
||||
},
|
||||
WorkerTask::GetInviter(invited, reply) => {
|
||||
assert!(self.initialized);
|
||||
reply.send(self.get_inviter(invited).await);
|
||||
},
|
||||
WorkerTask::GetRoom(room_id, reply) => {
|
||||
assert!(self.initialized);
|
||||
reply.send(self.get_room(room_id).await);
|
||||
},
|
||||
WorkerTask::JoinedRooms(reply) => {
|
||||
WorkerTask::ActiveRooms(reply) => {
|
||||
assert!(self.initialized);
|
||||
reply.send(self.joined_rooms().await);
|
||||
reply.send(self.active_rooms().await);
|
||||
},
|
||||
WorkerTask::LoadOlder(room_id, fetch_id, limit, reply) => {
|
||||
assert!(self.initialized);
|
||||
@@ -364,10 +456,6 @@ impl ClientWorker {
|
||||
assert!(self.initialized);
|
||||
reply.send(self.spaces().await);
|
||||
},
|
||||
WorkerTask::SendMessage(room_id, msg, reply) => {
|
||||
assert!(self.initialized);
|
||||
reply.send(self.send_message(room_id, msg).await);
|
||||
},
|
||||
WorkerTask::TypingNotice(room_id) => {
|
||||
assert!(self.initialized);
|
||||
self.typing_notice(room_id).await;
|
||||
@@ -461,6 +549,34 @@ impl ClientWorker {
|
||||
},
|
||||
);
|
||||
|
||||
let _ = self.client.add_event_handler(
|
||||
|ev: OriginalSyncRoomRedactionEvent,
|
||||
room: MatrixRoom,
|
||||
store: Ctx<AsyncProgramStore>| {
|
||||
async move {
|
||||
let room_id = room.room_id();
|
||||
let room_info = room.clone_info();
|
||||
let room_version = room_info.room_version().unwrap_or(&RoomVersionId::V1);
|
||||
|
||||
let mut locked = store.lock().await;
|
||||
let info = locked.application.get_room_info(room_id.to_owned());
|
||||
|
||||
// XXX: need to store a mapping of EventId -> MessageKey somewhere
|
||||
// to avoid having to iterate over the messages here.
|
||||
for ((_, id), msg) in info.messages.iter_mut().rev() {
|
||||
if id != &ev.redacts {
|
||||
continue;
|
||||
}
|
||||
|
||||
let ev = SyncRoomRedactionEvent::Original(ev);
|
||||
msg.event.redact(ev, room_version);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
let _ = self.client.add_event_handler(
|
||||
|ev: OriginalSyncKeyVerificationStartEvent,
|
||||
client: Client,
|
||||
@@ -615,33 +731,6 @@ impl ClientWorker {
|
||||
Ok(Some(InfoMessage::from("Successfully logged in!")))
|
||||
}
|
||||
|
||||
async fn send_message(&mut self, room_id: OwnedRoomId, msg: String) -> IambResult<EchoPair> {
|
||||
let room = if let r @ Some(_) = self.client.get_joined_room(&room_id) {
|
||||
r
|
||||
} else if self.client.join_room_by_id(&room_id).await.is_ok() {
|
||||
self.client.get_joined_room(&room_id)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
if let Some(room) = room {
|
||||
let msg = TextMessageEventContent::plain(msg);
|
||||
let msg = MessageType::Text(msg);
|
||||
let msg = RoomMessageEventContent::new(msg);
|
||||
|
||||
// XXX: second parameter can be a locally unique transaction id.
|
||||
// Useful for doing retries.
|
||||
let resp = room.send(msg.clone(), None).await.map_err(IambError::from)?;
|
||||
let event_id = resp.event_id;
|
||||
|
||||
// XXX: need to either give error messages and retry when needed!
|
||||
|
||||
return Ok((event_id, msg));
|
||||
} else {
|
||||
Err(IambError::UnknownRoom(room_id).into())
|
||||
}
|
||||
}
|
||||
|
||||
async fn direct_message(&mut self, user: OwnedUserId) -> IambResult<(MatrixRoom, DisplayName)> {
|
||||
for (room, name) in self.direct_messages().await {
|
||||
if room.get_member(user.as_ref()).await.map_err(IambError::from)?.is_some() {
|
||||
@@ -673,6 +762,12 @@ impl ClientWorker {
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_inviter(&mut self, invited: Invited) -> IambResult<Option<RoomMember>> {
|
||||
let details = invited.invite_details().await.map_err(IambError::from)?;
|
||||
|
||||
Ok(details.inviter)
|
||||
}
|
||||
|
||||
async fn get_room(&mut self, room_id: OwnedRoomId) -> IambResult<(MatrixRoom, DisplayName)> {
|
||||
if let Some(room) = self.client.get_room(&room_id) {
|
||||
let name = room.display_name().await.map_err(IambError::from)?;
|
||||
@@ -706,33 +801,53 @@ impl ClientWorker {
|
||||
}
|
||||
}
|
||||
|
||||
async fn direct_messages(&mut self) -> Vec<(MatrixRoom, DisplayName)> {
|
||||
async fn direct_messages(&self) -> Vec<(MatrixRoom, DisplayName)> {
|
||||
let mut rooms = vec![];
|
||||
|
||||
for room in self.client.joined_rooms().into_iter() {
|
||||
if room.is_space() || !room.is_direct() {
|
||||
for room in self.client.invited_rooms().into_iter() {
|
||||
if !room.is_direct() {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Ok(name) = room.display_name().await {
|
||||
rooms.push((MatrixRoom::from(room), name))
|
||||
let name = room.display_name().await.unwrap_or(DisplayName::Empty);
|
||||
|
||||
rooms.push((room.into(), name));
|
||||
}
|
||||
|
||||
for room in self.client.joined_rooms().into_iter() {
|
||||
if !room.is_direct() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let name = room.display_name().await.unwrap_or(DisplayName::Empty);
|
||||
|
||||
rooms.push((room.into(), name));
|
||||
}
|
||||
|
||||
return rooms;
|
||||
}
|
||||
|
||||
async fn joined_rooms(&mut self) -> Vec<(MatrixRoom, DisplayName)> {
|
||||
async fn active_rooms(&self) -> Vec<(MatrixRoom, DisplayName)> {
|
||||
let mut rooms = vec![];
|
||||
|
||||
for room in self.client.invited_rooms().into_iter() {
|
||||
if room.is_space() || room.is_direct() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let name = room.display_name().await.unwrap_or(DisplayName::Empty);
|
||||
|
||||
rooms.push((room.into(), name));
|
||||
}
|
||||
|
||||
for room in self.client.joined_rooms().into_iter() {
|
||||
if room.is_space() || room.is_direct() {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Ok(name) = room.display_name().await {
|
||||
rooms.push((MatrixRoom::from(room), name))
|
||||
}
|
||||
let name = room.display_name().await.unwrap_or(DisplayName::Empty);
|
||||
|
||||
rooms.push((room.into(), name));
|
||||
}
|
||||
|
||||
return rooms;
|
||||
@@ -814,17 +929,27 @@ impl ClientWorker {
|
||||
Ok(rooms)
|
||||
}
|
||||
|
||||
async fn spaces(&mut self) -> Vec<(MatrixRoom, DisplayName)> {
|
||||
async fn spaces(&self) -> Vec<(MatrixRoom, DisplayName)> {
|
||||
let mut spaces = vec![];
|
||||
|
||||
for room in self.client.invited_rooms().into_iter() {
|
||||
if !room.is_space() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let name = room.display_name().await.unwrap_or(DisplayName::Empty);
|
||||
|
||||
spaces.push((room.into(), name));
|
||||
}
|
||||
|
||||
for room in self.client.joined_rooms().into_iter() {
|
||||
if !room.is_space() {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Ok(name) = room.display_name().await {
|
||||
spaces.push((MatrixRoom::from(room), name));
|
||||
}
|
||||
let name = room.display_name().await.unwrap_or(DisplayName::Empty);
|
||||
|
||||
spaces.push((room.into(), name));
|
||||
}
|
||||
|
||||
return spaces;
|
||||
|
||||
Reference in New Issue
Block a user