Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3be8c16cb | ||
|
|
4c5c57e26c | ||
|
|
8eef8787cc | ||
|
|
c9c547acc1 | ||
|
|
3629f15e0d | ||
|
|
fd72cf5c4e | ||
|
|
1d93461183 | ||
|
|
a1574c6b8d | ||
|
|
e8205df21d |
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
@@ -13,7 +13,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v1
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: true
|
||||
- name: Install Rust
|
||||
@@ -35,7 +35,7 @@ jobs:
|
||||
runs-on: ${{ matrix.platform }}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: true
|
||||
- name: Install Rust
|
||||
@@ -45,7 +45,7 @@ jobs:
|
||||
override: true
|
||||
components: rustfmt, clippy
|
||||
- name: Cache cargo registry
|
||||
uses: actions/cache@v1
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ~/.cargo/registry
|
||||
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
|
||||
|
||||
368
Cargo.lock
generated
368
Cargo.lock
generated
@@ -2,6 +2,12 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "adler"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||
|
||||
[[package]]
|
||||
name = "aead"
|
||||
version = "0.4.3"
|
||||
@@ -64,6 +70,26 @@ version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d301b3b94cb4b2f23d7917810addbbaff90738e0ca2be692bd027e70d7e0330c"
|
||||
|
||||
[[package]]
|
||||
name = "arboard"
|
||||
version = "3.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d6041616acea41d67c4a984709ddab1587fd0b10efe5cc563fee954d2f011854"
|
||||
dependencies = [
|
||||
"clipboard-win",
|
||||
"core-graphics",
|
||||
"image",
|
||||
"log",
|
||||
"objc",
|
||||
"objc-foundation",
|
||||
"objc_id",
|
||||
"once_cell",
|
||||
"parking_lot 0.12.1",
|
||||
"thiserror",
|
||||
"winapi",
|
||||
"x11rb",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "arrayref"
|
||||
version = "0.3.6"
|
||||
@@ -200,6 +226,12 @@ dependencies = [
|
||||
"digest 0.10.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.9.0"
|
||||
@@ -233,6 +265,12 @@ version = "3.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535"
|
||||
|
||||
[[package]]
|
||||
name = "bytemuck"
|
||||
version = "1.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c041d3eab048880cb0b86b256447da3f18859a163c3b8d8893f4e6368abe6393"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.4.3"
|
||||
@@ -368,6 +406,17 @@ dependencies = [
|
||||
"os_str_bytes",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clipboard-win"
|
||||
version = "4.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7191c27c2357d9b7ef96baac1773290d4ca63b24205b82a3fd8a0637afcf0362"
|
||||
dependencies = [
|
||||
"error-code",
|
||||
"str-buf",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "codespan-reporting"
|
||||
version = "0.11.1"
|
||||
@@ -378,6 +427,12 @@ dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "color_quant"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
|
||||
|
||||
[[package]]
|
||||
name = "const-oid"
|
||||
version = "0.7.1"
|
||||
@@ -396,12 +451,47 @@ version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation"
|
||||
version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146"
|
||||
dependencies = [
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation-sys"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
|
||||
|
||||
[[package]]
|
||||
name = "core-graphics"
|
||||
version = "0.22.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"core-foundation",
|
||||
"core-graphics-types",
|
||||
"foreign-types",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-graphics-types"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"core-foundation",
|
||||
"foreign-types",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.2.5"
|
||||
@@ -439,7 +529,7 @@ dependencies = [
|
||||
"autocfg",
|
||||
"cfg-if",
|
||||
"crossbeam-utils",
|
||||
"memoffset",
|
||||
"memoffset 0.7.1",
|
||||
"scopeguard",
|
||||
]
|
||||
|
||||
@@ -752,6 +842,15 @@ version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797"
|
||||
|
||||
[[package]]
|
||||
name = "emojis"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44fe60b864b6544ad211d4053ced474a9b9d2c8d66b77f01d6c6bcfed10c6bf0"
|
||||
dependencies = [
|
||||
"phf 0.11.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encoding_rs"
|
||||
version = "0.8.31"
|
||||
@@ -782,6 +881,16 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "error-code"
|
||||
version = "2.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "64f18991e7bf11e7ffee451b5318b5c1a73c52d0d0ada6e5a3017c8c1ced6a21"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"str-buf",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "event-listener"
|
||||
version = "2.5.3"
|
||||
@@ -797,12 +906,37 @@ dependencies = [
|
||||
"instant",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.0.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"miniz_oxide",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "foreign-types"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
|
||||
dependencies = [
|
||||
"foreign-types-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "foreign-types-shared"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
version = "1.1.0"
|
||||
@@ -974,6 +1108,16 @@ dependencies = [
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gethostname"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c1ebd34e35c46e00bb73e81363248d627782724609fe1b6396f553f68fe3862e"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gethostname"
|
||||
version = "0.4.1"
|
||||
@@ -1160,11 +1304,13 @@ dependencies = [
|
||||
name = "iamb"
|
||||
version = "0.0.4"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"chrono",
|
||||
"clap",
|
||||
"css-color-parser",
|
||||
"dirs",
|
||||
"gethostname",
|
||||
"emojis",
|
||||
"gethostname 0.4.1",
|
||||
"html5ever",
|
||||
"lazy_static 1.4.0",
|
||||
"markup5ever_rcdom",
|
||||
@@ -1172,6 +1318,7 @@ dependencies = [
|
||||
"mime",
|
||||
"mime_guess",
|
||||
"modalkit",
|
||||
"open",
|
||||
"regex",
|
||||
"rpassword",
|
||||
"serde",
|
||||
@@ -1226,6 +1373,21 @@ dependencies = [
|
||||
"unicode-normalization",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "image"
|
||||
version = "0.24.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69b7ea949b537b0fd0af141fff8c77690f2ce96f4f41f042ccb6c69c6c965945"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"byteorder",
|
||||
"color_quant",
|
||||
"num-rational",
|
||||
"num-traits",
|
||||
"png",
|
||||
"tiff",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexed_db_futures"
|
||||
version = "0.2.3"
|
||||
@@ -1325,6 +1487,12 @@ version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440"
|
||||
|
||||
[[package]]
|
||||
name = "jpeg-decoder"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc0000e42512c92e31c2252315bda326620a4e034105e900c98ec492fa077b3e"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.60"
|
||||
@@ -1419,6 +1587,15 @@ version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4"
|
||||
|
||||
[[package]]
|
||||
name = "malloc_buf"
|
||||
version = "0.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "maplit"
|
||||
version = "1.0.2"
|
||||
@@ -1432,7 +1609,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a2629bb1404f3d34c2e921f21fd34ba00b206124c81f65c50b43b6aaefeb016"
|
||||
dependencies = [
|
||||
"log",
|
||||
"phf",
|
||||
"phf 0.10.1",
|
||||
"phf_codegen",
|
||||
"string_cache",
|
||||
"string_cache_codegen",
|
||||
@@ -1636,6 +1813,15 @@ version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||
|
||||
[[package]]
|
||||
name = "memoffset"
|
||||
version = "0.6.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memoffset"
|
||||
version = "0.7.1"
|
||||
@@ -1667,6 +1853,15 @@ version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa"
|
||||
dependencies = [
|
||||
"adler",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mio"
|
||||
version = "0.8.5"
|
||||
@@ -1681,11 +1876,12 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "modalkit"
|
||||
version = "0.0.10"
|
||||
version = "0.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4f57d0d53c9f3d8cad2508351f88656e4185cbb8b95d0c738b314fc8167bc90f"
|
||||
checksum = "bd7bd7d02d65842dab4cea53016cf29c16cde197131dd6d9eea95662deb77778"
|
||||
dependencies = [
|
||||
"anymap2",
|
||||
"arboard",
|
||||
"bitflags",
|
||||
"crossterm",
|
||||
"derive_more",
|
||||
@@ -1704,6 +1900,18 @@ version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54"
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.24.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"memoffset 0.6.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "7.1.3"
|
||||
@@ -1734,6 +1942,17 @@ dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-rational"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.15"
|
||||
@@ -1753,6 +1972,35 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1"
|
||||
dependencies = [
|
||||
"malloc_buf",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc-foundation"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9"
|
||||
dependencies = [
|
||||
"block",
|
||||
"objc",
|
||||
"objc_id",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc_id"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b"
|
||||
dependencies = [
|
||||
"objc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.17.0"
|
||||
@@ -1765,6 +2013,16 @@ version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
|
||||
|
||||
[[package]]
|
||||
name = "open"
|
||||
version = "3.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2078c0039e6a54a0c42c28faa984e115fb4c2d5bf2208f77d1961002df8576f8"
|
||||
dependencies = [
|
||||
"pathdiff",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "os_str_bytes"
|
||||
version = "6.4.1"
|
||||
@@ -1842,6 +2100,12 @@ dependencies = [
|
||||
"subtle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pathdiff"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd"
|
||||
|
||||
[[package]]
|
||||
name = "pbkdf2"
|
||||
version = "0.11.0"
|
||||
@@ -1866,7 +2130,16 @@ version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259"
|
||||
dependencies = [
|
||||
"phf_shared",
|
||||
"phf_shared 0.10.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "928c6535de93548188ef63bb7c4036bd415cd8f36ad25af44b9789b2ee72a48c"
|
||||
dependencies = [
|
||||
"phf_shared 0.11.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1876,7 +2149,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd"
|
||||
dependencies = [
|
||||
"phf_generator",
|
||||
"phf_shared",
|
||||
"phf_shared 0.10.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1885,7 +2158,7 @@ version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6"
|
||||
dependencies = [
|
||||
"phf_shared",
|
||||
"phf_shared 0.10.0",
|
||||
"rand 0.8.5",
|
||||
]
|
||||
|
||||
@@ -1898,6 +2171,15 @@ dependencies = [
|
||||
"siphasher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_shared"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e1fb5f6f826b772a8d4c0394209441e7d37cbbb967ae9c7e0e8134365c9ee676"
|
||||
dependencies = [
|
||||
"siphasher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pin-project"
|
||||
version = "1.0.12"
|
||||
@@ -1940,6 +2222,18 @@ dependencies = [
|
||||
"spki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "png"
|
||||
version = "0.17.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d708eaf860a19b19ce538740d2b4bdeeb8337fa53f7738455e706623ad5c638"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"crc32fast",
|
||||
"flate2",
|
||||
"miniz_oxide",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "poly1305"
|
||||
version = "0.7.2"
|
||||
@@ -2604,6 +2898,12 @@ dependencies = [
|
||||
"der",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "str-buf"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e08d8363704e6c71fc928674353e6b7c23dcea9d82d7012c8faf2a3a025f8d0"
|
||||
|
||||
[[package]]
|
||||
name = "str_indices"
|
||||
version = "0.4.1"
|
||||
@@ -2619,7 +2919,7 @@ dependencies = [
|
||||
"new_debug_unreachable",
|
||||
"once_cell",
|
||||
"parking_lot 0.12.1",
|
||||
"phf_shared",
|
||||
"phf_shared 0.10.0",
|
||||
"precomputed-hash",
|
||||
"serde",
|
||||
]
|
||||
@@ -2631,7 +2931,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988"
|
||||
dependencies = [
|
||||
"phf_generator",
|
||||
"phf_shared",
|
||||
"phf_shared 0.10.0",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
]
|
||||
@@ -2720,6 +3020,17 @@ dependencies = [
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tiff"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7449334f9ff2baf290d55d73983a7d6fa15e01198faef72af07e2a8db851e471"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"jpeg-decoder",
|
||||
"weezl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.45"
|
||||
@@ -3220,6 +3531,12 @@ dependencies = [
|
||||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "weezl"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb"
|
||||
|
||||
[[package]]
|
||||
name = "wildmatch"
|
||||
version = "2.1.1"
|
||||
@@ -3251,6 +3568,15 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-wsapoll"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44c17110f57155602a80dca10be03852116403c9ff3cd25b079d666f2aa3df6e"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
@@ -3338,6 +3664,28 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "x11rb"
|
||||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "592b4883219f345e712b3209c62654ebda0bb50887f330cbd018d0f654bfd507"
|
||||
dependencies = [
|
||||
"gethostname 0.2.3",
|
||||
"nix",
|
||||
"winapi",
|
||||
"winapi-wsapoll",
|
||||
"x11rb-protocol",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "x11rb-protocol"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56b245751c0ac9db0e006dc812031482784e434630205a93c73cfefcaabeac67"
|
||||
dependencies = [
|
||||
"nix",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "x25519-dalek"
|
||||
version = "1.2.0"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "iamb"
|
||||
version = "0.0.4"
|
||||
version = "0.0.5"
|
||||
edition = "2018"
|
||||
authors = ["Ulyssa <git@ulyssa.dev>"]
|
||||
repository = "https://github.com/ulyssa/iamb"
|
||||
@@ -14,15 +14,18 @@ categories = ["command-line-utilities"]
|
||||
rust-version = "1.66"
|
||||
|
||||
[dependencies]
|
||||
bitflags = "1.3.2"
|
||||
chrono = "0.4"
|
||||
clap = {version = "4.0", features = ["derive"]}
|
||||
css-color-parser = "0.1.2"
|
||||
dirs = "4.0.0"
|
||||
emojis = "~0.5.2"
|
||||
gethostname = "0.4.1"
|
||||
html5ever = "0.26.0"
|
||||
markup5ever_rcdom = "0.2.0"
|
||||
mime = "^0.3.16"
|
||||
mime_guess = "^2.0.4"
|
||||
open = "3.2.0"
|
||||
regex = "^1.5"
|
||||
rpassword = "^7.2"
|
||||
serde = "^1.0"
|
||||
@@ -36,7 +39,7 @@ unicode-width = "0.1.10"
|
||||
url = {version = "^2.2.2", features = ["serde"]}
|
||||
|
||||
[dependencies.modalkit]
|
||||
version = "0.0.10"
|
||||
version = "0.0.11"
|
||||
|
||||
[dependencies.matrix-sdk]
|
||||
version = "0.6"
|
||||
|
||||
@@ -73,7 +73,7 @@ two other TUI clients and Element Web:
|
||||
| Multiple Matrix Accounts | ✔️ | ❌ | ✔️ | ❌ |
|
||||
| New user registration | ❌ | ❌ | ❌ | ✔️ |
|
||||
| VOIP | ❌ | ❌ | ❌ | ✔️ |
|
||||
| Reactions | ❌ ([#2]) | ✔️ | ❌ | ✔️ |
|
||||
| Reactions | ✔️ | ✔️ | ❌ | ✔️ |
|
||||
| Message editing | ✔️ | ✔️ | ❌ | ✔️ |
|
||||
| Room upgrades | ❌ | ✔️ | ❌ | ✔️ |
|
||||
| Localisations | ❌ | 1 | ❌ | 44 |
|
||||
|
||||
143
src/base.rs
143
src/base.rs
@@ -10,14 +10,19 @@ use matrix_sdk::{
|
||||
encryption::verification::SasVerification,
|
||||
room::Joined,
|
||||
ruma::{
|
||||
events::room::message::{
|
||||
OriginalRoomMessageEvent,
|
||||
Relation,
|
||||
Replacement,
|
||||
RoomMessageEvent,
|
||||
RoomMessageEventContent,
|
||||
events::{
|
||||
reaction::ReactionEvent,
|
||||
room::message::{
|
||||
OriginalRoomMessageEvent,
|
||||
Relation,
|
||||
Replacement,
|
||||
RoomMessageEvent,
|
||||
RoomMessageEventContent,
|
||||
},
|
||||
tag::{TagName, Tags},
|
||||
AnyMessageLikeEvent,
|
||||
MessageLikeEvent,
|
||||
},
|
||||
events::tag::{TagName, Tags},
|
||||
EventId,
|
||||
OwnedEventId,
|
||||
OwnedRoomId,
|
||||
@@ -81,18 +86,39 @@ pub enum MessageAction {
|
||||
|
||||
/// Download an attachment to the given path.
|
||||
///
|
||||
/// The [bool] argument controls whether to overwrite any already existing file at the
|
||||
/// destination path.
|
||||
Download(Option<String>, bool),
|
||||
/// The second argument controls whether to overwrite any already existing file at the
|
||||
/// destination path, or to open the attachment after downloading.
|
||||
Download(Option<String>, DownloadFlags),
|
||||
|
||||
/// Edit a sent message.
|
||||
Edit,
|
||||
|
||||
/// Redact a message.
|
||||
/// React to a message with an Emoji.
|
||||
React(String),
|
||||
|
||||
/// Redact a message, with an optional reason.
|
||||
Redact(Option<String>),
|
||||
|
||||
/// Reply to a message.
|
||||
Reply,
|
||||
|
||||
/// Unreact to a message.
|
||||
///
|
||||
/// If no specific Emoji to remove to is specified, then all reactions from the user on the
|
||||
/// message are removed.
|
||||
Unreact(Option<String>),
|
||||
}
|
||||
|
||||
bitflags::bitflags! {
|
||||
pub struct DownloadFlags: u32 {
|
||||
const NONE = 0b00000000;
|
||||
|
||||
/// Overwrite file if it already exists.
|
||||
const FORCE = 0b00000001;
|
||||
|
||||
/// Open file after downloading.
|
||||
const OPEN = 0b00000010;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
@@ -214,6 +240,12 @@ pub type AsyncProgramStore = Arc<AsyncMutex<ProgramStore>>;
|
||||
|
||||
pub type IambResult<T> = UIResult<T, IambInfo>;
|
||||
|
||||
/// Reaction events for some message.
|
||||
///
|
||||
/// The event identifier used as a key here is the ID for the reaction, and not for the message
|
||||
/// it's reacting to.
|
||||
pub type MessageReactions = HashMap<OwnedEventId, (String, OwnedUserId)>;
|
||||
|
||||
pub type Receipts = HashMap<OwnedEventId, Vec<OwnedUserId>>;
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
@@ -280,32 +312,103 @@ pub enum RoomFetchStatus {
|
||||
NotStarted,
|
||||
}
|
||||
|
||||
pub enum EventLocation {
|
||||
Message(MessageKey),
|
||||
Reaction(OwnedEventId),
|
||||
}
|
||||
|
||||
impl EventLocation {
|
||||
fn to_message_key(&self) -> Option<&MessageKey> {
|
||||
if let EventLocation::Message(key) = self {
|
||||
Some(key)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct RoomInfo {
|
||||
/// The display name for this room.
|
||||
pub name: Option<String>,
|
||||
|
||||
/// The tags placed on this room.
|
||||
pub tags: Option<Tags>,
|
||||
|
||||
pub keys: HashMap<OwnedEventId, MessageKey>,
|
||||
/// A map of event IDs to where they are stored in this struct.
|
||||
pub keys: HashMap<OwnedEventId, EventLocation>,
|
||||
|
||||
/// The messages loaded for this room.
|
||||
pub messages: Messages,
|
||||
|
||||
/// A map of read markers to display on different events.
|
||||
pub receipts: HashMap<OwnedEventId, Vec<OwnedUserId>>,
|
||||
|
||||
/// An event ID for where we should indicate we've read up to.
|
||||
pub read_till: Option<OwnedEventId>,
|
||||
|
||||
/// A map of message identifiers to a map of reaction events.
|
||||
pub reactions: HashMap<OwnedEventId, MessageReactions>,
|
||||
|
||||
/// Where to continue fetching from when we continue loading scrollback history.
|
||||
pub fetch_id: RoomFetchStatus,
|
||||
|
||||
/// The time that we last fetched scrollback for this room.
|
||||
pub fetch_last: Option<Instant>,
|
||||
|
||||
/// Users currently typing in this room, and when we received notification of them doing so.
|
||||
pub users_typing: Option<(Instant, Vec<OwnedUserId>)>,
|
||||
}
|
||||
|
||||
impl RoomInfo {
|
||||
pub fn get_reactions(&self, event_id: &EventId) -> Vec<(&str, usize)> {
|
||||
if let Some(reacts) = self.reactions.get(event_id) {
|
||||
let mut counts = HashMap::new();
|
||||
|
||||
for (key, _) in reacts.values() {
|
||||
let count = counts.entry(key.as_str()).or_default();
|
||||
*count += 1;
|
||||
}
|
||||
|
||||
let mut reactions = counts.into_iter().collect::<Vec<_>>();
|
||||
reactions.sort();
|
||||
|
||||
reactions
|
||||
} else {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_event(&self, event_id: &EventId) -> Option<&Message> {
|
||||
self.messages.get(self.keys.get(event_id)?)
|
||||
self.messages.get(self.keys.get(event_id)?.to_message_key()?)
|
||||
}
|
||||
|
||||
pub fn insert_reaction(&mut self, react: ReactionEvent) {
|
||||
match react {
|
||||
MessageLikeEvent::Original(react) => {
|
||||
let rel_id = react.content.relates_to.event_id;
|
||||
let key = react.content.relates_to.key;
|
||||
|
||||
let message = self.reactions.entry(rel_id.clone()).or_default();
|
||||
let event_id = react.event_id;
|
||||
let user_id = react.sender;
|
||||
|
||||
message.insert(event_id.clone(), (key, user_id));
|
||||
|
||||
let loc = EventLocation::Reaction(rel_id);
|
||||
self.keys.insert(event_id, loc);
|
||||
},
|
||||
MessageLikeEvent::Redacted(_) => {
|
||||
return;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insert_edit(&mut self, msg: Replacement) {
|
||||
let event_id = msg.event_id;
|
||||
let new_content = msg.new_content;
|
||||
|
||||
let key = if let Some(k) = self.keys.get(&event_id) {
|
||||
let key = if let Some(EventLocation::Message(k)) = self.keys.get(&event_id) {
|
||||
k
|
||||
} else {
|
||||
return;
|
||||
@@ -334,7 +437,7 @@ impl RoomInfo {
|
||||
let event_id = msg.event_id().to_owned();
|
||||
let key = (msg.origin_server_ts().into(), event_id.clone());
|
||||
|
||||
self.keys.insert(event_id.clone(), key.clone());
|
||||
self.keys.insert(event_id.clone(), EventLocation::Message(key.clone()));
|
||||
self.messages.insert(key, msg.into());
|
||||
|
||||
// Remove any echo.
|
||||
@@ -507,7 +610,15 @@ impl ChatStore {
|
||||
match res {
|
||||
Ok((fetch_id, msgs)) => {
|
||||
for msg in msgs.into_iter() {
|
||||
info.insert(msg);
|
||||
match msg {
|
||||
AnyMessageLikeEvent::RoomMessage(msg) => {
|
||||
info.insert(msg);
|
||||
},
|
||||
AnyMessageLikeEvent::Reaction(ev) => {
|
||||
info.insert_reaction(ev);
|
||||
},
|
||||
_ => continue,
|
||||
}
|
||||
}
|
||||
|
||||
info.fetch_id =
|
||||
|
||||
@@ -10,6 +10,7 @@ use modalkit::{
|
||||
};
|
||||
|
||||
use crate::base::{
|
||||
DownloadFlags,
|
||||
IambAction,
|
||||
IambId,
|
||||
MessageAction,
|
||||
@@ -39,7 +40,7 @@ fn tag_name(name: String) -> Result<TagName, CommandError> {
|
||||
if let Ok(tag) = name.parse() {
|
||||
TagName::User(tag)
|
||||
} else {
|
||||
let msg = format!("Invalid user tag name: {}", name);
|
||||
let msg = format!("Invalid user tag name: {name}");
|
||||
|
||||
return Err(CommandError::Error(msg));
|
||||
}
|
||||
@@ -162,8 +163,8 @@ fn iamb_cancel(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
|
||||
return Result::Err(CommandError::InvalidArgument);
|
||||
}
|
||||
|
||||
let ract = IambAction::from(MessageAction::Cancel);
|
||||
let step = CommandStep::Continue(ract.into(), ctx.context.take());
|
||||
let mact = IambAction::from(MessageAction::Cancel);
|
||||
let step = CommandStep::Continue(mact.into(), ctx.context.take());
|
||||
|
||||
return Ok(step);
|
||||
}
|
||||
@@ -173,8 +174,55 @@ fn iamb_edit(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
|
||||
return Result::Err(CommandError::InvalidArgument);
|
||||
}
|
||||
|
||||
let ract = IambAction::from(MessageAction::Edit);
|
||||
let step = CommandStep::Continue(ract.into(), ctx.context.take());
|
||||
let mact = IambAction::from(MessageAction::Edit);
|
||||
let step = CommandStep::Continue(mact.into(), ctx.context.take());
|
||||
|
||||
return Ok(step);
|
||||
}
|
||||
|
||||
fn iamb_react(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
|
||||
let args = desc.arg.strings()?;
|
||||
|
||||
if args.len() != 1 {
|
||||
return Result::Err(CommandError::InvalidArgument);
|
||||
}
|
||||
|
||||
let k = args[0].as_str();
|
||||
|
||||
if let Some(emoji) = emojis::get(k).or_else(|| emojis::get_by_shortcode(k)) {
|
||||
let mact = IambAction::from(MessageAction::React(emoji.to_string()));
|
||||
let step = CommandStep::Continue(mact.into(), ctx.context.take());
|
||||
|
||||
return Ok(step);
|
||||
} else {
|
||||
let msg = format!("Invalid Emoji or shortcode: {k}");
|
||||
|
||||
return Result::Err(CommandError::Error(msg));
|
||||
}
|
||||
}
|
||||
|
||||
fn iamb_unreact(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
|
||||
let mut args = desc.arg.strings()?;
|
||||
|
||||
if args.len() > 1 {
|
||||
return Result::Err(CommandError::InvalidArgument);
|
||||
}
|
||||
|
||||
let mact = if let Some(k) = args.pop() {
|
||||
let k = k.as_str();
|
||||
|
||||
if let Some(emoji) = emojis::get(k).or_else(|| emojis::get_by_shortcode(k)) {
|
||||
IambAction::from(MessageAction::Unreact(Some(emoji.to_string())))
|
||||
} else {
|
||||
let msg = format!("Invalid Emoji or shortcode: {k}");
|
||||
|
||||
return Result::Err(CommandError::Error(msg));
|
||||
}
|
||||
} else {
|
||||
IambAction::from(MessageAction::Unreact(None))
|
||||
};
|
||||
|
||||
let step = CommandStep::Continue(mact.into(), ctx.context.take());
|
||||
|
||||
return Ok(step);
|
||||
}
|
||||
@@ -317,7 +365,29 @@ fn iamb_download(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult
|
||||
return Result::Err(CommandError::InvalidArgument);
|
||||
}
|
||||
|
||||
let mact = MessageAction::Download(args.pop(), desc.bang);
|
||||
let mut flags = DownloadFlags::NONE;
|
||||
if desc.bang {
|
||||
flags |= DownloadFlags::FORCE;
|
||||
};
|
||||
let mact = MessageAction::Download(args.pop(), flags);
|
||||
let iact = IambAction::from(mact);
|
||||
let step = CommandStep::Continue(iact.into(), ctx.context.take());
|
||||
|
||||
return Ok(step);
|
||||
}
|
||||
|
||||
fn iamb_open(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
|
||||
let mut args = desc.arg.strings()?;
|
||||
|
||||
if args.len() > 1 {
|
||||
return Result::Err(CommandError::InvalidArgument);
|
||||
}
|
||||
|
||||
let mut flags = DownloadFlags::OPEN;
|
||||
if desc.bang {
|
||||
flags |= DownloadFlags::FORCE;
|
||||
};
|
||||
let mact = MessageAction::Download(args.pop(), flags);
|
||||
let iact = IambAction::from(mact);
|
||||
let step = CommandStep::Continue(iact.into(), ctx.context.take());
|
||||
|
||||
@@ -328,15 +398,18 @@ 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!["open".into()], f: iamb_open });
|
||||
cmds.add_command(ProgramCommand { names: vec!["edit".into()], f: iamb_edit });
|
||||
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!["react".into()], f: iamb_react });
|
||||
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!["room".into()], f: iamb_room });
|
||||
cmds.add_command(ProgramCommand { names: vec!["spaces".into()], f: iamb_spaces });
|
||||
cmds.add_command(ProgramCommand { names: vec!["unreact".into()], f: iamb_unreact });
|
||||
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 });
|
||||
|
||||
@@ -178,6 +178,8 @@ fn merge_users(a: Option<UserOverrides>, b: Option<UserOverrides>) -> Option<Use
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TunableValues {
|
||||
pub reaction_display: bool,
|
||||
pub reaction_shortcode_display: bool,
|
||||
pub read_receipt_send: bool,
|
||||
pub read_receipt_display: bool,
|
||||
pub typing_notice_send: bool,
|
||||
@@ -188,6 +190,8 @@ pub struct TunableValues {
|
||||
|
||||
#[derive(Clone, Default, Deserialize)]
|
||||
pub struct Tunables {
|
||||
pub reaction_display: Option<bool>,
|
||||
pub reaction_shortcode_display: Option<bool>,
|
||||
pub read_receipt_send: Option<bool>,
|
||||
pub read_receipt_display: Option<bool>,
|
||||
pub typing_notice_send: Option<bool>,
|
||||
@@ -199,6 +203,10 @@ pub struct Tunables {
|
||||
impl Tunables {
|
||||
fn merge(self, other: Self) -> Self {
|
||||
Tunables {
|
||||
reaction_display: self.reaction_display.or(other.reaction_display),
|
||||
reaction_shortcode_display: self
|
||||
.reaction_shortcode_display
|
||||
.or(other.reaction_shortcode_display),
|
||||
read_receipt_send: self.read_receipt_send.or(other.read_receipt_send),
|
||||
read_receipt_display: self.read_receipt_display.or(other.read_receipt_display),
|
||||
typing_notice_send: self.typing_notice_send.or(other.typing_notice_send),
|
||||
@@ -210,6 +218,8 @@ impl Tunables {
|
||||
|
||||
fn values(self) -> TunableValues {
|
||||
TunableValues {
|
||||
reaction_display: self.reaction_display.unwrap_or(true),
|
||||
reaction_shortcode_display: self.reaction_shortcode_display.unwrap_or(false),
|
||||
read_receipt_send: self.read_receipt_send.unwrap_or(true),
|
||||
read_receipt_display: self.read_receipt_display.unwrap_or(true),
|
||||
typing_notice_send: self.typing_notice_send.unwrap_or(true),
|
||||
|
||||
@@ -7,7 +7,9 @@ use modalkit::{
|
||||
input::key::TerminalKey,
|
||||
};
|
||||
|
||||
use crate::base::{IambAction, Keybindings};
|
||||
use crate::base::{IambAction, IambInfo, Keybindings};
|
||||
|
||||
type IambStep = InputStep<IambInfo>;
|
||||
|
||||
/// Find the boundaries for a Matrix username, room alias, or room ID.
|
||||
///
|
||||
@@ -44,19 +46,27 @@ pub fn setup_keybindings() -> Keybindings {
|
||||
(EdgeRepeat::Once, ctrl_w.clone()),
|
||||
(EdgeRepeat::Once, ctrl_z),
|
||||
];
|
||||
let zoom = InputStep::new().actions(vec![WindowAction::ZoomToggle.into()]);
|
||||
let zoom = IambStep::new()
|
||||
.actions(vec![WindowAction::ZoomToggle.into()])
|
||||
.goto(VimMode::Normal);
|
||||
|
||||
ism.add_mapping(VimMode::Normal, &cwz, &zoom);
|
||||
ism.add_mapping(VimMode::Visual, &cwz, &zoom);
|
||||
ism.add_mapping(VimMode::Normal, &cwcz, &zoom);
|
||||
ism.add_mapping(VimMode::Visual, &cwcz, &zoom);
|
||||
|
||||
let cwm = vec![
|
||||
(EdgeRepeat::Once, ctrl_w.clone()),
|
||||
(EdgeRepeat::Once, key_m_lc),
|
||||
];
|
||||
let cwcm = vec![(EdgeRepeat::Once, ctrl_w), (EdgeRepeat::Once, ctrl_m)];
|
||||
let stoggle = InputStep::new().actions(vec![IambAction::ToggleScrollbackFocus.into()]);
|
||||
let stoggle = IambStep::new()
|
||||
.actions(vec![IambAction::ToggleScrollbackFocus.into()])
|
||||
.goto(VimMode::Normal);
|
||||
ism.add_mapping(VimMode::Normal, &cwm, &stoggle);
|
||||
ism.add_mapping(VimMode::Visual, &cwm, &stoggle);
|
||||
ism.add_mapping(VimMode::Normal, &cwcm, &stoggle);
|
||||
ism.add_mapping(VimMode::Visual, &cwcm, &stoggle);
|
||||
|
||||
return ism;
|
||||
}
|
||||
|
||||
33
src/main.rs
33
src/main.rs
@@ -23,7 +23,7 @@ use matrix_sdk::ruma::OwnedUserId;
|
||||
use modalkit::crossterm::{
|
||||
self,
|
||||
cursor::Show as CursorShow,
|
||||
event::{poll, read, Event},
|
||||
event::{poll, read, DisableBracketedPaste, EnableBracketedPaste, Event},
|
||||
execute,
|
||||
terminal::{EnterAlternateScreen, LeaveAlternateScreen, SetTitle},
|
||||
};
|
||||
@@ -77,6 +77,8 @@ use modalkit::{
|
||||
EditError,
|
||||
EditInfo,
|
||||
Editable,
|
||||
EditorAction,
|
||||
InsertTextAction,
|
||||
Jumpable,
|
||||
Promptable,
|
||||
Scrollable,
|
||||
@@ -85,7 +87,7 @@ use modalkit::{
|
||||
WindowAction,
|
||||
WindowContainer,
|
||||
},
|
||||
base::{OpenTarget, RepeatType},
|
||||
base::{MoveDir1D, OpenTarget, RepeatType},
|
||||
context::Resolve,
|
||||
key::KeyManager,
|
||||
store::Store,
|
||||
@@ -126,6 +128,7 @@ impl Application {
|
||||
let mut stdout = stdout();
|
||||
crossterm::terminal::enable_raw_mode()?;
|
||||
crossterm::execute!(stdout, EnterAlternateScreen)?;
|
||||
crossterm::execute!(stdout, EnableBracketedPaste)?;
|
||||
|
||||
let title = format!("iamb ({})", settings.profile.user_id);
|
||||
crossterm::execute!(stdout, SetTitle(title))?;
|
||||
@@ -218,8 +221,21 @@ impl Application {
|
||||
Event::Resize(_, _) => {
|
||||
// We'll redraw for the new size next time step() is called.
|
||||
},
|
||||
Event::Paste(_) => {
|
||||
// Do nothing for now.
|
||||
Event::Paste(s) => {
|
||||
let act = InsertTextAction::Transcribe(s, MoveDir1D::Previous, 1.into());
|
||||
let act = EditorAction::from(act);
|
||||
let ctx = ProgramContext::default();
|
||||
let mut store = self.store.lock().await;
|
||||
|
||||
match self.screen.editor_command(&act, &ctx, store.deref_mut()) {
|
||||
Ok(None) => {},
|
||||
Ok(Some(info)) => {
|
||||
self.screen.push_info(info);
|
||||
},
|
||||
Err(e) => {
|
||||
self.screen.push_error(e);
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -439,13 +455,13 @@ async fn login(worker: Requester, settings: &ApplicationSettings) -> IambResult<
|
||||
match worker.login(LoginStyle::Password(password)) {
|
||||
Ok(info) => {
|
||||
if let Some(msg) = info {
|
||||
println!("{}", msg);
|
||||
println!("{msg}");
|
||||
}
|
||||
|
||||
break;
|
||||
},
|
||||
Err(err) => {
|
||||
println!("Failed to login: {}", err);
|
||||
println!("Failed to login: {err}");
|
||||
continue;
|
||||
},
|
||||
}
|
||||
@@ -455,7 +471,7 @@ async fn login(worker: Requester, settings: &ApplicationSettings) -> IambResult<
|
||||
}
|
||||
|
||||
fn print_exit<T: Display, N>(v: T) -> N {
|
||||
println!("{}", v);
|
||||
println!("{v}");
|
||||
process::exit(2);
|
||||
}
|
||||
|
||||
@@ -473,6 +489,7 @@ async fn run(settings: ApplicationSettings) -> IambResult<()> {
|
||||
let orig_hook = std::panic::take_hook();
|
||||
std::panic::set_hook(Box::new(move |panic_info| {
|
||||
let _ = crossterm::terminal::disable_raw_mode();
|
||||
let _ = crossterm::execute!(stdout(), DisableBracketedPaste);
|
||||
let _ = crossterm::execute!(stdout(), LeaveAlternateScreen);
|
||||
let _ = crossterm::execute!(stdout(), CursorShow);
|
||||
orig_hook(panic_info);
|
||||
@@ -515,7 +532,7 @@ fn main() -> IambResult<()> {
|
||||
.thread_name_fn(|| {
|
||||
static ATOMIC_ID: AtomicUsize = AtomicUsize::new(0);
|
||||
let id = ATOMIC_ID.fetch_add(1, Ordering::SeqCst);
|
||||
format!("iamb-worker-{}", id)
|
||||
format!("iamb-worker-{id}")
|
||||
})
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
@@ -6,7 +6,7 @@ use std::convert::TryFrom;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::slice::Iter;
|
||||
|
||||
use chrono::{DateTime, NaiveDateTime, Utc};
|
||||
use chrono::{DateTime, Local as LocalTz, NaiveDateTime, TimeZone};
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
use matrix_sdk::ruma::{
|
||||
@@ -24,6 +24,7 @@ use matrix_sdk::ruma::{
|
||||
},
|
||||
redaction::SyncRoomRedactionEvent,
|
||||
},
|
||||
AnyMessageLikeEvent,
|
||||
Redact,
|
||||
},
|
||||
EventId,
|
||||
@@ -52,7 +53,7 @@ use crate::{
|
||||
mod html;
|
||||
mod printer;
|
||||
|
||||
pub type MessageFetchResult = IambResult<(Option<String>, Vec<RoomMessageEvent>)>;
|
||||
pub type MessageFetchResult = IambResult<(Option<String>, Vec<AnyMessageLikeEvent>)>;
|
||||
pub type MessageKey = (MessageTimeStamp, OwnedEventId);
|
||||
pub type Messages = BTreeMap<MessageKey, Message>;
|
||||
|
||||
@@ -68,6 +69,13 @@ const fn span_static(s: &'static str) -> Span<'static> {
|
||||
}
|
||||
}
|
||||
|
||||
const BOLD_STYLE: Style = Style {
|
||||
fg: None,
|
||||
bg: None,
|
||||
add_modifier: StyleModifier::BOLD,
|
||||
sub_modifier: StyleModifier::empty(),
|
||||
};
|
||||
|
||||
const USER_GUTTER: usize = 30;
|
||||
const TIME_GUTTER: usize = 12;
|
||||
const READ_GUTTER: usize = 5;
|
||||
@@ -79,6 +87,14 @@ const USER_GUTTER_EMPTY_SPAN: Span<'static> = span_static(USER_GUTTER_EMPTY);
|
||||
const TIME_GUTTER_EMPTY: &str = " ";
|
||||
const TIME_GUTTER_EMPTY_SPAN: Span<'static> = span_static(TIME_GUTTER_EMPTY);
|
||||
|
||||
#[inline]
|
||||
fn millis_to_datetime(ms: UInt) -> DateTime<LocalTz> {
|
||||
let time = i64::from(ms) / 1000;
|
||||
let time = NaiveDateTime::from_timestamp_opt(time, 0).unwrap_or_default();
|
||||
|
||||
LocalTz.from_utc_datetime(&time)
|
||||
}
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum TimeStampIntError {
|
||||
#[error("Integer conversion error: {0}")]
|
||||
@@ -95,14 +111,31 @@ pub enum MessageTimeStamp {
|
||||
}
|
||||
|
||||
impl MessageTimeStamp {
|
||||
fn show(&self) -> Option<Span> {
|
||||
fn as_datetime(&self) -> DateTime<LocalTz> {
|
||||
match self {
|
||||
MessageTimeStamp::OriginServer(ts) => {
|
||||
let time = i64::from(*ts) / 1000;
|
||||
let time = NaiveDateTime::from_timestamp_opt(time, 0)?;
|
||||
let time = DateTime::<Utc>::from_utc(time, Utc);
|
||||
let time = time.format("%T");
|
||||
let time = format!(" [{}]", time);
|
||||
MessageTimeStamp::OriginServer(ms) => millis_to_datetime(*ms),
|
||||
MessageTimeStamp::LocalEcho => LocalTz::now(),
|
||||
}
|
||||
}
|
||||
|
||||
fn same_day(&self, other: &Self) -> bool {
|
||||
let dt1 = self.as_datetime();
|
||||
let dt2 = other.as_datetime();
|
||||
|
||||
dt1.date_naive() == dt2.date_naive()
|
||||
}
|
||||
|
||||
fn show_date(&self) -> Option<Span> {
|
||||
let time = self.as_datetime().format("%A, %B %d %Y").to_string();
|
||||
|
||||
Span::styled(time, BOLD_STYLE).into()
|
||||
}
|
||||
|
||||
fn show_time(&self) -> Option<Span> {
|
||||
match self {
|
||||
MessageTimeStamp::OriginServer(ms) => {
|
||||
let time = millis_to_datetime(*ms).format("%T");
|
||||
let time = format!(" [{time}]");
|
||||
|
||||
Span::raw(time).into()
|
||||
},
|
||||
@@ -139,6 +172,12 @@ impl PartialOrd for MessageTimeStamp {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<UInt> for MessageTimeStamp {
|
||||
fn from(millis: UInt) -> Self {
|
||||
MessageTimeStamp::OriginServer(millis)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MilliSecondsSinceUnixEpoch> for MessageTimeStamp {
|
||||
fn from(millis: MilliSecondsSinceUnixEpoch) -> Self {
|
||||
MessageTimeStamp::OriginServer(millis.0)
|
||||
@@ -168,7 +207,7 @@ impl TryFrom<usize> for MessageTimeStamp {
|
||||
let n = u64::try_from(u)?;
|
||||
let n = UInt::try_from(n).map_err(TimeStampIntError::UIntError)?;
|
||||
|
||||
Ok(MessageTimeStamp::OriginServer(n))
|
||||
Ok(MessageTimeStamp::from(n))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -305,7 +344,7 @@ impl MessageEvent {
|
||||
.and_then(|r| r.content.reason.as_ref());
|
||||
|
||||
if let Some(r) = reason {
|
||||
Cow::Owned(format!("[Redacted: {:?}]", r))
|
||||
Cow::Owned(format!("[Redacted: {r:?}]"))
|
||||
} else {
|
||||
Cow::Borrowed("[Redacted]")
|
||||
}
|
||||
@@ -388,10 +427,26 @@ enum MessageColumns {
|
||||
|
||||
struct MessageFormatter<'a> {
|
||||
settings: &'a ApplicationSettings,
|
||||
|
||||
/// How many columns to print.
|
||||
cols: MessageColumns,
|
||||
|
||||
/// The full, original width.
|
||||
orig: usize,
|
||||
|
||||
/// The width that the message contents need to fill.
|
||||
fill: usize,
|
||||
|
||||
/// The formatted Span for the message sender.
|
||||
user: Option<Span<'a>>,
|
||||
|
||||
/// The time the message was sent.
|
||||
time: Option<Span<'a>>,
|
||||
|
||||
/// The date the message was sent.
|
||||
date: Option<Span<'a>>,
|
||||
|
||||
/// Iterator over the users who have read up to this message.
|
||||
read: Iter<'a, OwnedUserId>,
|
||||
}
|
||||
|
||||
@@ -402,6 +457,15 @@ impl<'a> MessageFormatter<'a> {
|
||||
|
||||
#[inline]
|
||||
fn push_spans(&mut self, spans: Spans<'a>, style: Style, text: &mut Text<'a>) {
|
||||
if let Some(date) = self.date.take() {
|
||||
let len = date.content.as_ref().len();
|
||||
let padding = self.orig.saturating_sub(len);
|
||||
let leading = space_span(padding / 2, Style::default());
|
||||
let trailing = space_span(padding.saturating_sub(padding / 2), Style::default());
|
||||
|
||||
text.lines.push(Spans(vec![leading, date, trailing]));
|
||||
}
|
||||
|
||||
match self.cols {
|
||||
MessageColumns::Four => {
|
||||
let settings = self.settings;
|
||||
@@ -517,27 +581,33 @@ impl Message {
|
||||
info: &'a RoomInfo,
|
||||
settings: &'a ApplicationSettings,
|
||||
) -> MessageFormatter<'a> {
|
||||
let orig = width;
|
||||
let date = match &prev {
|
||||
Some(prev) if prev.timestamp.same_day(&self.timestamp) => None,
|
||||
_ => self.timestamp.show_date(),
|
||||
};
|
||||
|
||||
if USER_GUTTER + TIME_GUTTER + READ_GUTTER + MIN_MSG_LEN <= width &&
|
||||
settings.tunables.read_receipt_display
|
||||
{
|
||||
let cols = MessageColumns::Four;
|
||||
let fill = width - USER_GUTTER - TIME_GUTTER - READ_GUTTER;
|
||||
let user = self.show_sender(prev, true, settings);
|
||||
let time = self.timestamp.show();
|
||||
let time = self.timestamp.show_time();
|
||||
let read = match info.receipts.get(self.event.event_id()) {
|
||||
Some(read) => read.iter(),
|
||||
None => [].iter(),
|
||||
};
|
||||
|
||||
MessageFormatter { settings, cols, fill, user, time, read }
|
||||
MessageFormatter { settings, cols, orig, fill, user, date, time, read }
|
||||
} else if USER_GUTTER + TIME_GUTTER + MIN_MSG_LEN <= width {
|
||||
let cols = MessageColumns::Three;
|
||||
let fill = width - USER_GUTTER - TIME_GUTTER;
|
||||
let user = self.show_sender(prev, true, settings);
|
||||
let time = self.timestamp.show();
|
||||
let time = self.timestamp.show_time();
|
||||
let read = [].iter();
|
||||
|
||||
MessageFormatter { settings, cols, fill, user, time, read }
|
||||
MessageFormatter { settings, cols, orig, fill, user, date, time, read }
|
||||
} else if USER_GUTTER + MIN_MSG_LEN <= width {
|
||||
let cols = MessageColumns::Two;
|
||||
let fill = width - USER_GUTTER;
|
||||
@@ -545,7 +615,7 @@ impl Message {
|
||||
let time = None;
|
||||
let read = [].iter();
|
||||
|
||||
MessageFormatter { settings, cols, fill, user, time, read }
|
||||
MessageFormatter { settings, cols, orig, fill, user, date, time, read }
|
||||
} else {
|
||||
let cols = MessageColumns::One;
|
||||
let fill = width.saturating_sub(2);
|
||||
@@ -553,7 +623,7 @@ impl Message {
|
||||
let time = None;
|
||||
let read = [].iter();
|
||||
|
||||
MessageFormatter { settings, cols, fill, user, time, read }
|
||||
MessageFormatter { settings, cols, orig, fill, user, date, time, read }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -613,6 +683,43 @@ impl Message {
|
||||
fmt.push_spans(space_span(width, style).into(), style, &mut text);
|
||||
}
|
||||
|
||||
if settings.tunables.reaction_display {
|
||||
let mut emojis = printer::TextPrinter::new(width, style, false);
|
||||
let mut reactions = 0;
|
||||
|
||||
for (key, count) in info.get_reactions(self.event.event_id()).into_iter() {
|
||||
if reactions != 0 {
|
||||
emojis.push_str(" ", style);
|
||||
}
|
||||
|
||||
let name = if settings.tunables.reaction_shortcode_display {
|
||||
if let Some(emoji) = emojis::get(key) {
|
||||
if let Some(short) = emoji.shortcode() {
|
||||
short
|
||||
} else {
|
||||
// No ASCII shortcode name to show.
|
||||
continue;
|
||||
}
|
||||
} else if key.chars().all(|c| c.is_ascii_alphanumeric()) {
|
||||
key
|
||||
} else {
|
||||
// Not an Emoji or a printable ASCII string.
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
key
|
||||
};
|
||||
|
||||
emojis.push_str(format!("[{name} {count}]"), style);
|
||||
|
||||
reactions += 1;
|
||||
}
|
||||
|
||||
if reactions > 0 {
|
||||
fmt.push_text(emojis.finish(), style, &mut text);
|
||||
}
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
@@ -640,13 +747,13 @@ impl Message {
|
||||
align_right: bool,
|
||||
settings: &ApplicationSettings,
|
||||
) -> Option<Span> {
|
||||
let user = if matches!(prev, Some(prev) if self.sender == prev.sender) {
|
||||
return None;
|
||||
} else {
|
||||
self.sender_span(settings)
|
||||
};
|
||||
if let Some(prev) = prev {
|
||||
if self.sender == prev.sender && self.timestamp.same_day(&prev.timestamp) {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
let Span { content, style } = user;
|
||||
let Span { content, style } = self.sender_span(settings);
|
||||
let stop = content.len().min(28);
|
||||
let s = &content[..stop];
|
||||
|
||||
|
||||
17
src/tests.rs
17
src/tests.rs
@@ -20,7 +20,7 @@ use tokio::sync::mpsc::unbounded_channel;
|
||||
use url::Url;
|
||||
|
||||
use crate::{
|
||||
base::{ChatStore, ProgramStore, RoomFetchStatus, RoomInfo},
|
||||
base::{ChatStore, EventLocation, ProgramStore, RoomFetchStatus, RoomInfo},
|
||||
config::{
|
||||
user_color,
|
||||
user_style_from_color,
|
||||
@@ -117,14 +117,14 @@ pub fn mock_message5() -> Message {
|
||||
mock_room1_message(content, TEST_USER2.clone(), MSG4_KEY.clone())
|
||||
}
|
||||
|
||||
pub fn mock_keys() -> HashMap<OwnedEventId, MessageKey> {
|
||||
pub fn mock_keys() -> HashMap<OwnedEventId, EventLocation> {
|
||||
let mut keys = HashMap::new();
|
||||
|
||||
keys.insert(MSG1_EVID.clone(), MSG1_KEY.clone());
|
||||
keys.insert(MSG2_EVID.clone(), MSG2_KEY.clone());
|
||||
keys.insert(MSG3_EVID.clone(), MSG3_KEY.clone());
|
||||
keys.insert(MSG4_EVID.clone(), MSG4_KEY.clone());
|
||||
keys.insert(MSG5_EVID.clone(), MSG5_KEY.clone());
|
||||
keys.insert(MSG1_EVID.clone(), EventLocation::Message(MSG1_KEY.clone()));
|
||||
keys.insert(MSG2_EVID.clone(), EventLocation::Message(MSG2_KEY.clone()));
|
||||
keys.insert(MSG3_EVID.clone(), EventLocation::Message(MSG3_KEY.clone()));
|
||||
keys.insert(MSG4_EVID.clone(), EventLocation::Message(MSG4_KEY.clone()));
|
||||
keys.insert(MSG5_EVID.clone(), EventLocation::Message(MSG5_KEY.clone()));
|
||||
|
||||
keys
|
||||
}
|
||||
@@ -151,6 +151,7 @@ pub fn mock_room() -> RoomInfo {
|
||||
|
||||
receipts: HashMap::new(),
|
||||
read_till: None,
|
||||
reactions: HashMap::new(),
|
||||
|
||||
fetch_id: RoomFetchStatus::NotStarted,
|
||||
fetch_last: None,
|
||||
@@ -169,6 +170,8 @@ pub fn mock_dirs() -> DirectoryValues {
|
||||
pub fn mock_tunables() -> TunableValues {
|
||||
TunableValues {
|
||||
default_room: None,
|
||||
reaction_display: true,
|
||||
reaction_shortcode_display: false,
|
||||
read_receipt_send: true,
|
||||
read_receipt_display: true,
|
||||
typing_notice_send: true,
|
||||
|
||||
@@ -168,7 +168,7 @@ fn append_tags<'a>(tags: &'a Tags, spans: &mut Vec<Span<'a>>, style: Style) {
|
||||
spans.push(Span::styled("User Tag: ", style));
|
||||
spans.push(Span::styled(tag.as_ref(), style));
|
||||
},
|
||||
tag => spans.push(Span::styled(format!("{:?}", tag), style)),
|
||||
tag => spans.push(Span::styled(format!("{tag:?}"), style)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -594,7 +594,7 @@ impl Window<IambInfo> for IambWindow {
|
||||
}
|
||||
|
||||
fn posn(index: usize, _: &mut ProgramStore) -> IambResult<Self> {
|
||||
let msg = format!("Cannot find indexed buffer (index = {})", index);
|
||||
let msg = format!("Cannot find indexed buffer (index = {index})");
|
||||
let err = UIError::Unimplemented(msg);
|
||||
|
||||
Err(err)
|
||||
@@ -852,7 +852,7 @@ impl VerifyItem {
|
||||
let device = self.sasv1.other_device();
|
||||
|
||||
if let Some(display_name) = device.display_name() {
|
||||
format!("Device verification with {} ({})", display_name, state)
|
||||
format!("Device verification with {display_name} ({state})")
|
||||
} else {
|
||||
format!("Device verification with device {} ({})", device.device_id(), state)
|
||||
}
|
||||
@@ -958,7 +958,7 @@ impl ListItem<IambInfo> for VerifyItem {
|
||||
lines.push(Spans::from(""));
|
||||
|
||||
for line in format_emojis(emoji).lines() {
|
||||
lines.push(Spans::from(format!(" {}", line)));
|
||||
lines.push(Spans::from(format!(" {line}")));
|
||||
}
|
||||
|
||||
lines.push(Spans::from(""));
|
||||
|
||||
@@ -4,11 +4,14 @@ use std::fs;
|
||||
use std::ops::Deref;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use tokio;
|
||||
|
||||
use matrix_sdk::{
|
||||
attachment::AttachmentConfig,
|
||||
media::{MediaFormat, MediaRequest},
|
||||
room::Room as MatrixRoom,
|
||||
room::{Joined, Room as MatrixRoom},
|
||||
ruma::{
|
||||
events::reaction::{ReactionEventContent, Relation as Reaction},
|
||||
events::room::message::{
|
||||
MessageType,
|
||||
OriginalRoomMessageEvent,
|
||||
@@ -17,6 +20,7 @@ use matrix_sdk::{
|
||||
RoomMessageEventContent,
|
||||
TextMessageEventContent,
|
||||
},
|
||||
EventId,
|
||||
OwnedRoomId,
|
||||
RoomId,
|
||||
},
|
||||
@@ -55,6 +59,7 @@ use modalkit::editing::{
|
||||
};
|
||||
|
||||
use crate::base::{
|
||||
DownloadFlags,
|
||||
IambAction,
|
||||
IambBufferId,
|
||||
IambError,
|
||||
@@ -70,6 +75,7 @@ use crate::base::{
|
||||
};
|
||||
|
||||
use crate::message::{Message, MessageEvent, MessageKey, MessageTimeStamp};
|
||||
use crate::worker::Requester;
|
||||
|
||||
use super::scrollback::{Scrollback, ScrollbackState};
|
||||
|
||||
@@ -112,6 +118,10 @@ impl ChatState {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_joined(&self, worker: &Requester) -> Result<Joined, IambError> {
|
||||
worker.client.get_joined_room(self.id()).ok_or(IambError::NotJoined)
|
||||
}
|
||||
|
||||
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)?;
|
||||
@@ -146,7 +156,10 @@ impl ChatState {
|
||||
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)?;
|
||||
let msg = self
|
||||
.scrollback
|
||||
.get_mut(&mut info.messages)
|
||||
.ok_or(IambError::NoSelectedMessage)?;
|
||||
|
||||
match act {
|
||||
MessageAction::Cancel => {
|
||||
@@ -155,7 +168,7 @@ impl ChatState {
|
||||
|
||||
Ok(None)
|
||||
},
|
||||
MessageAction::Download(filename, force) => {
|
||||
MessageAction::Download(filename, flags) => {
|
||||
if let MessageEvent::Original(ev) = &msg.event {
|
||||
let media = client.media();
|
||||
|
||||
@@ -202,9 +215,18 @@ impl ChatState {
|
||||
},
|
||||
};
|
||||
|
||||
if !force && filename.exists() {
|
||||
if !filename.exists() || flags.contains(DownloadFlags::FORCE) {
|
||||
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;
|
||||
} else if !flags.contains(DownloadFlags::OPEN) {
|
||||
let msg = format!(
|
||||
"The file {} already exists; use :download! to overwrite it.",
|
||||
"The file {} already exists; add ! to end of command to overwrite it.",
|
||||
filename.display()
|
||||
);
|
||||
let err = UIError::Failure(msg);
|
||||
@@ -212,19 +234,21 @@ impl ChatState {
|
||||
return Err(err);
|
||||
}
|
||||
|
||||
let req = MediaRequest { source, format: MediaFormat::File };
|
||||
let info = if flags.contains(DownloadFlags::OPEN) {
|
||||
// open::that may not return until the spawned program closes.
|
||||
let target = filename.clone().into_os_string();
|
||||
tokio::task::spawn_blocking(move || open::that(target));
|
||||
|
||||
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()
|
||||
));
|
||||
InfoMessage::from(format!(
|
||||
"Attachment downloaded to {} and opened",
|
||||
filename.display()
|
||||
))
|
||||
} else {
|
||||
InfoMessage::from(format!(
|
||||
"Attachment downloaded to {}",
|
||||
filename.display()
|
||||
))
|
||||
};
|
||||
|
||||
return Ok(info.into());
|
||||
}
|
||||
@@ -266,19 +290,32 @@ impl ChatState {
|
||||
|
||||
Ok(None)
|
||||
},
|
||||
MessageAction::Redact(reason) => {
|
||||
let room = store
|
||||
.application
|
||||
.worker
|
||||
.client
|
||||
.get_joined_room(self.id())
|
||||
.ok_or(IambError::NotJoined)?;
|
||||
|
||||
MessageAction::React(emoji) => {
|
||||
let room = self.get_joined(&store.application.worker)?;
|
||||
let event_id = match &msg.event {
|
||||
MessageEvent::Original(ev) => ev.event_id.clone(),
|
||||
MessageEvent::Local(event_id, _) => event_id.clone(),
|
||||
MessageEvent::Redacted(_) => {
|
||||
let msg = "";
|
||||
let msg = "Cannot react to a redacted message";
|
||||
let err = UIError::Failure(msg.into());
|
||||
|
||||
return Err(err);
|
||||
},
|
||||
};
|
||||
|
||||
let reaction = Reaction::new(event_id, emoji);
|
||||
let msg = ReactionEventContent::new(reaction);
|
||||
let _ = room.send(msg, None).await.map_err(IambError::from)?;
|
||||
|
||||
Ok(None)
|
||||
},
|
||||
MessageAction::Redact(reason) => {
|
||||
let room = self.get_joined(&store.application.worker)?;
|
||||
let event_id = match &msg.event {
|
||||
MessageEvent::Original(ev) => ev.event_id.clone(),
|
||||
MessageEvent::Local(event_id, _) => event_id.clone(),
|
||||
MessageEvent::Redacted(_) => {
|
||||
let msg = "Cannot redact already redacted message";
|
||||
let err = UIError::Failure(msg.into());
|
||||
|
||||
return Err(err);
|
||||
@@ -295,6 +332,46 @@ impl ChatState {
|
||||
self.reply_to = self.scrollback.get_key(info);
|
||||
self.focus = RoomFocus::MessageBar;
|
||||
|
||||
Ok(None)
|
||||
},
|
||||
MessageAction::Unreact(emoji) => {
|
||||
let room = self.get_joined(&store.application.worker)?;
|
||||
let event_id: &EventId = match &msg.event {
|
||||
MessageEvent::Original(ev) => ev.event_id.as_ref(),
|
||||
MessageEvent::Local(event_id, _) => event_id.as_ref(),
|
||||
MessageEvent::Redacted(_) => {
|
||||
let msg = "Cannot unreact to a redacted message";
|
||||
let err = UIError::Failure(msg.into());
|
||||
|
||||
return Err(err);
|
||||
},
|
||||
};
|
||||
|
||||
let reactions = match info.reactions.get(event_id) {
|
||||
Some(r) => r,
|
||||
None => return Ok(None),
|
||||
};
|
||||
|
||||
let reactions = reactions.iter().filter_map(|(event_id, (reaction, user_id))| {
|
||||
if user_id != &settings.profile.user_id {
|
||||
return None;
|
||||
}
|
||||
|
||||
if let Some(emoji) = &emoji {
|
||||
if emoji == reaction {
|
||||
return Some(event_id);
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
} else {
|
||||
return Some(event_id);
|
||||
}
|
||||
});
|
||||
|
||||
for reaction in reactions {
|
||||
let _ = room.redact(reaction, None, None).await.map_err(IambError::from)?;
|
||||
}
|
||||
|
||||
Ok(None)
|
||||
},
|
||||
}
|
||||
@@ -367,7 +444,7 @@ impl ChatState {
|
||||
.map_err(IambError::from)?;
|
||||
|
||||
// Mock up the local echo message for the scrollback.
|
||||
let msg = TextMessageEventContent::plain(format!("[Attached File: {}]", name));
|
||||
let msg = TextMessageEventContent::plain(format!("[Attached File: {name}]"));
|
||||
let msg = MessageType::Text(msg);
|
||||
let msg = RoomMessageEventContent::new(msg);
|
||||
|
||||
|
||||
@@ -132,10 +132,7 @@ impl RoomState {
|
||||
None => format!("{:?}", store.application.get_room_title(self.id())),
|
||||
};
|
||||
|
||||
let mut invited = vec![Span::from(format!(
|
||||
"You have been invited to join {}",
|
||||
name
|
||||
))];
|
||||
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 "));
|
||||
|
||||
@@ -62,7 +62,7 @@ use modalkit::editing::{
|
||||
use crate::{
|
||||
base::{IambBufferId, IambInfo, ProgramContext, ProgramStore, RoomFocus, RoomInfo},
|
||||
config::ApplicationSettings,
|
||||
message::{Message, MessageCursor, MessageKey},
|
||||
message::{Message, MessageCursor, MessageKey, Messages},
|
||||
};
|
||||
|
||||
fn nth_key_before(pos: MessageKey, n: usize, info: &RoomInfo) -> MessageKey {
|
||||
@@ -103,6 +103,10 @@ fn nth_after(pos: MessageKey, n: usize, info: &RoomInfo) -> MessageCursor {
|
||||
nth_key_after(pos, n, info).into()
|
||||
}
|
||||
|
||||
fn prevmsg<'a>(key: &MessageKey, info: &'a RoomInfo) -> Option<&'a Message> {
|
||||
info.messages.range(..key).next_back().map(|(_, v)| v)
|
||||
}
|
||||
|
||||
pub struct ScrollbackState {
|
||||
/// The room identifier.
|
||||
room_id: OwnedRoomId,
|
||||
@@ -160,11 +164,11 @@ impl ScrollbackState {
|
||||
.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> {
|
||||
pub fn get_mut<'a>(&mut self, messages: &'a mut Messages) -> Option<&'a mut Message> {
|
||||
if let Some(k) = &self.cursor.timestamp {
|
||||
info.messages.get_mut(k)
|
||||
messages.get_mut(k)
|
||||
} else {
|
||||
info.messages.last_entry().map(|o| o.into_mut())
|
||||
messages.last_entry().map(|o| o.into_mut())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,7 +218,8 @@ impl ScrollbackState {
|
||||
|
||||
for (key, item) in info.messages.range(..=&idx).rev() {
|
||||
let sel = selidx == key;
|
||||
let len = item.show(None, sel, &self.viewctx, info, settings).lines.len();
|
||||
let prev = prevmsg(key, info);
|
||||
let len = item.show(prev, sel, &self.viewctx, info, settings).lines.len();
|
||||
|
||||
if key == &idx {
|
||||
lines += len / 2;
|
||||
@@ -236,7 +241,8 @@ impl ScrollbackState {
|
||||
|
||||
for (key, item) in info.messages.range(..=&idx).rev() {
|
||||
let sel = key == selidx;
|
||||
let len = item.show(None, sel, &self.viewctx, info, settings).lines.len();
|
||||
let prev = prevmsg(key, info);
|
||||
let len = item.show(prev, sel, &self.viewctx, info, settings).lines.len();
|
||||
|
||||
lines += len;
|
||||
|
||||
@@ -269,6 +275,7 @@ impl ScrollbackState {
|
||||
let mut lines = 0;
|
||||
|
||||
let cursor_key = self.cursor.timestamp.as_ref().unwrap_or(last_key);
|
||||
let mut prev = prevmsg(cursor_key, info);
|
||||
|
||||
for (idx, item) in info.messages.range(corner_key.clone()..) {
|
||||
if idx == cursor_key {
|
||||
@@ -276,13 +283,15 @@ impl ScrollbackState {
|
||||
break;
|
||||
}
|
||||
|
||||
lines += item.show(None, false, &self.viewctx, info, settings).height().max(1);
|
||||
lines += item.show(prev, false, &self.viewctx, info, settings).height().max(1);
|
||||
|
||||
if lines >= self.viewctx.get_height() {
|
||||
// We've reached the end of the viewport; move cursor into it.
|
||||
self.cursor = idx.clone().into();
|
||||
break;
|
||||
}
|
||||
|
||||
prev = Some(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -582,7 +591,7 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
|
||||
let needle = match ctx.get_search_regex() {
|
||||
Some(re) => re,
|
||||
None => {
|
||||
let lsearch = store.registers.get(&Register::LastSearch);
|
||||
let lsearch = store.registers.get(&Register::LastSearch)?;
|
||||
let lsearch = lsearch.value.to_string();
|
||||
|
||||
Regex::new(lsearch.as_ref())?
|
||||
@@ -606,7 +615,7 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
|
||||
},
|
||||
|
||||
_ => {
|
||||
let msg = format!("Unknown editing target: {:?}", motion);
|
||||
let msg = format!("Unknown editing target: {motion:?}");
|
||||
let err = EditError::Unimplemented(msg);
|
||||
|
||||
return Err(err);
|
||||
@@ -668,7 +677,7 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
|
||||
let needle = match ctx.get_search_regex() {
|
||||
Some(re) => re,
|
||||
None => {
|
||||
let lsearch = store.registers.get(&Register::LastSearch);
|
||||
let lsearch = store.registers.get(&Register::LastSearch)?;
|
||||
let lsearch = lsearch.value.to_string();
|
||||
|
||||
Regex::new(lsearch.as_ref())?
|
||||
@@ -693,7 +702,7 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
|
||||
},
|
||||
|
||||
_ => {
|
||||
let msg = format!("Unknown motion: {:?}", motion);
|
||||
let msg = format!("Unknown motion: {motion:?}");
|
||||
let err = EditError::Unimplemented(msg);
|
||||
|
||||
return Err(err);
|
||||
@@ -716,7 +725,7 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
|
||||
flags |= RegisterPutFlags::APPEND;
|
||||
}
|
||||
|
||||
store.registers.put(®ister, cell, flags);
|
||||
store.registers.put(®ister, cell, flags)?;
|
||||
}
|
||||
|
||||
return Ok(None);
|
||||
@@ -724,7 +733,7 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
|
||||
|
||||
// Everything else is a modifying action.
|
||||
EditAction::ChangeCase(_) => Err(EditError::ReadOnly),
|
||||
EditAction::ChangeNumber(_) => Err(EditError::ReadOnly),
|
||||
EditAction::ChangeNumber(_, _) => Err(EditError::ReadOnly),
|
||||
EditAction::Delete => Err(EditError::ReadOnly),
|
||||
EditAction::Format => Err(EditError::ReadOnly),
|
||||
EditAction::Indent(_) => Err(EditError::ReadOnly),
|
||||
@@ -781,7 +790,7 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
|
||||
HistoryAction::Checkpoint => Ok(None),
|
||||
HistoryAction::Undo(_) => Err(EditError::Failure("Nothing to undo".into())),
|
||||
HistoryAction::Redo(_) => Err(EditError::Failure("Nothing to redo".into())),
|
||||
_ => Err(EditError::Unimplemented(format!("Unknown action: {:?}", act))),
|
||||
_ => Err(EditError::Unimplemented(format!("Unknown action: {act:?}"))),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -838,7 +847,7 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
|
||||
|
||||
Ok(None)
|
||||
},
|
||||
_ => Err(EditError::Unimplemented(format!("Unknown action: {:?}", act))),
|
||||
_ => Err(EditError::Unimplemented(format!("Unknown action: {act:?}"))),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -865,7 +874,7 @@ impl Editable<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
|
||||
Err(err)
|
||||
},
|
||||
|
||||
_ => Err(EditError::Unimplemented(format!("Unknown action: {:?}", act))),
|
||||
_ => Err(EditError::Unimplemented(format!("Unknown action: {act:?}"))),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -964,7 +973,7 @@ impl Promptable<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
|
||||
return Err(err);
|
||||
},
|
||||
_ => {
|
||||
let msg = format!("Messages scrollback doesn't support {:?}", act);
|
||||
let msg = format!("Messages scrollback doesn't support {act:?}");
|
||||
let err = EditError::Unimplemented(msg);
|
||||
|
||||
return Err(err);
|
||||
@@ -1009,7 +1018,8 @@ 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(None, sel, &self.viewctx, info, settings);
|
||||
let prev = prevmsg(key, info);
|
||||
let txt = item.show(prev, sel, &self.viewctx, info, settings);
|
||||
let len = txt.height().max(1);
|
||||
let max = len.saturating_sub(1);
|
||||
|
||||
@@ -1033,12 +1043,16 @@ impl ScrollActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
|
||||
}
|
||||
},
|
||||
MoveDir2D::Down => {
|
||||
let mut prev = prevmsg(&corner_key, info);
|
||||
|
||||
for (key, item) in info.messages.range(&corner_key..) {
|
||||
let sel = key == cursor_key;
|
||||
let txt = item.show(None, sel, &self.viewctx, info, settings);
|
||||
let txt = item.show(prev, sel, &self.viewctx, info, settings);
|
||||
let len = txt.height().max(1);
|
||||
let max = len.saturating_sub(1);
|
||||
|
||||
prev = Some(item);
|
||||
|
||||
if key != &corner_key {
|
||||
corner.text_row = 0;
|
||||
}
|
||||
@@ -1214,7 +1228,7 @@ impl<'a> StatefulWidget for Scrollback<'a> {
|
||||
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;
|
||||
let mut prev = prevmsg(&corner_key, info);
|
||||
|
||||
for (key, item) in info.messages.range(&corner_key..) {
|
||||
let sel = key == cursor_key;
|
||||
@@ -1373,10 +1387,11 @@ mod tests {
|
||||
assert_eq!(scrollback.viewctx.dimensions, (0, 0));
|
||||
assert_eq!(scrollback.viewctx.corner, MessageCursor::latest());
|
||||
|
||||
// Set a terminal width of 60, and height of 3, rendering in scrollback as:
|
||||
// Set a terminal width of 60, and height of 4, rendering in scrollback as:
|
||||
//
|
||||
// |------------------------------------------------------------|
|
||||
// MSG2: | @user2:example.com helium |
|
||||
// MSG2: | Wednesday, December 31 1969 |
|
||||
// | @user2:example.com helium |
|
||||
// MSG3: | @user2:example.com this |
|
||||
// | is |
|
||||
// | a |
|
||||
@@ -1384,14 +1399,15 @@ mod tests {
|
||||
// | message |
|
||||
// MSG4: | @user1:example.com help |
|
||||
// MSG5: | @user2:example.com character |
|
||||
// MSG1: | @user1:example.com writhe |
|
||||
// MSG1: | XXXday, Month NN 20XX |
|
||||
// | @user1:example.com writhe |
|
||||
// |------------------------------------------------------------|
|
||||
let area = Rect::new(0, 0, 60, 3);
|
||||
let area = Rect::new(0, 0, 60, 4);
|
||||
let mut buffer = Buffer::empty(area);
|
||||
scrollback.draw(area, &mut buffer, true, &mut store);
|
||||
|
||||
assert_eq!(scrollback.cursor, MessageCursor::latest());
|
||||
assert_eq!(scrollback.viewctx.dimensions, (60, 3));
|
||||
assert_eq!(scrollback.viewctx.dimensions, (60, 4));
|
||||
assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG4_KEY.clone(), 0));
|
||||
|
||||
// Scroll up a line at a time until we hit the first message.
|
||||
@@ -1420,6 +1436,11 @@ mod tests {
|
||||
.unwrap();
|
||||
assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG3_KEY.clone(), 0));
|
||||
|
||||
scrollback
|
||||
.dirscroll(prev, ScrollSize::Cell, &1.into(), &ctx, &mut store)
|
||||
.unwrap();
|
||||
assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG2_KEY.clone(), 1));
|
||||
|
||||
scrollback
|
||||
.dirscroll(prev, ScrollSize::Cell, &1.into(), &ctx, &mut store)
|
||||
.unwrap();
|
||||
@@ -1432,6 +1453,11 @@ mod tests {
|
||||
assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG2_KEY.clone(), 0));
|
||||
|
||||
// Now scroll back down one line at a time.
|
||||
scrollback
|
||||
.dirscroll(next, ScrollSize::Cell, &1.into(), &ctx, &mut store)
|
||||
.unwrap();
|
||||
assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG2_KEY.clone(), 1));
|
||||
|
||||
scrollback
|
||||
.dirscroll(next, ScrollSize::Cell, &1.into(), &ctx, &mut store)
|
||||
.unwrap();
|
||||
@@ -1472,19 +1498,24 @@ mod tests {
|
||||
.unwrap();
|
||||
assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG1_KEY.clone(), 0));
|
||||
|
||||
scrollback
|
||||
.dirscroll(next, ScrollSize::Cell, &1.into(), &ctx, &mut store)
|
||||
.unwrap();
|
||||
assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG1_KEY.clone(), 1));
|
||||
|
||||
// Cannot scroll down any further.
|
||||
scrollback
|
||||
.dirscroll(next, ScrollSize::Cell, &1.into(), &ctx, &mut store)
|
||||
.unwrap();
|
||||
assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG1_KEY.clone(), 0));
|
||||
assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG1_KEY.clone(), 1));
|
||||
|
||||
// Scroll up two Pages (six lines).
|
||||
// Scroll up two Pages (eight lines).
|
||||
scrollback
|
||||
.dirscroll(prev, ScrollSize::Page, &2.into(), &ctx, &mut store)
|
||||
.unwrap();
|
||||
assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG3_KEY.clone(), 1));
|
||||
assert_eq!(scrollback.viewctx.corner, MessageCursor::new(MSG3_KEY.clone(), 0));
|
||||
|
||||
// Scroll down two HalfPages (three lines).
|
||||
// Scroll down two HalfPages (four lines).
|
||||
scrollback
|
||||
.dirscroll(next, ScrollSize::HalfPage, &2.into(), &ctx, &mut store)
|
||||
.unwrap();
|
||||
@@ -1503,7 +1534,8 @@ mod tests {
|
||||
// Set a terminal width of 60, and height of 3, rendering in scrollback as:
|
||||
//
|
||||
// |------------------------------------------------------------|
|
||||
// MSG2: | @user2:example.com helium |
|
||||
// MSG2: | Wednesday, December 31 1969 |
|
||||
// | @user2:example.com helium |
|
||||
// MSG3: | @user2:example.com this |
|
||||
// | is |
|
||||
// | a |
|
||||
@@ -1511,7 +1543,8 @@ mod tests {
|
||||
// | message |
|
||||
// MSG4: | @user1:example.com help |
|
||||
// MSG5: | @user2:example.com character |
|
||||
// MSG1: | @user1:example.com writhe |
|
||||
// MSG1: | XXXday, Month NN 20XX |
|
||||
// | @user1:example.com writhe |
|
||||
// |------------------------------------------------------------|
|
||||
let area = Rect::new(0, 0, 60, 3);
|
||||
let mut buffer = Buffer::empty(area);
|
||||
|
||||
@@ -32,6 +32,7 @@ use matrix_sdk::{
|
||||
start::{OriginalSyncKeyVerificationStartEvent, ToDeviceKeyVerificationStartEvent},
|
||||
VerificationMethod,
|
||||
},
|
||||
reaction::ReactionEventContent,
|
||||
room::{
|
||||
message::{MessageType, RoomMessageEventContent},
|
||||
name::RoomNameEventContent,
|
||||
@@ -39,7 +40,6 @@ use matrix_sdk::{
|
||||
},
|
||||
tag::Tags,
|
||||
typing::SyncTypingEvent,
|
||||
AnyMessageLikeEvent,
|
||||
AnyTimelineEvent,
|
||||
SyncMessageLikeEvent,
|
||||
SyncStateEvent,
|
||||
@@ -57,7 +57,7 @@ use matrix_sdk::{
|
||||
use modalkit::editing::action::{EditInfo, InfoMessage, UIError};
|
||||
|
||||
use crate::{
|
||||
base::{AsyncProgramStore, IambError, IambResult, Receipts, VerifyAction},
|
||||
base::{AsyncProgramStore, EventLocation, IambError, IambResult, Receipts, VerifyAction},
|
||||
message::MessageFetchResult,
|
||||
ApplicationSettings,
|
||||
};
|
||||
@@ -350,6 +350,7 @@ pub struct ClientWorker {
|
||||
settings: ApplicationSettings,
|
||||
client: Client,
|
||||
sync_handle: Option<JoinHandle<()>>,
|
||||
rcpt_handle: Option<JoinHandle<()>>,
|
||||
}
|
||||
|
||||
impl ClientWorker {
|
||||
@@ -388,9 +389,10 @@ impl ClientWorker {
|
||||
settings,
|
||||
client: client.clone(),
|
||||
sync_handle: None,
|
||||
rcpt_handle: None,
|
||||
};
|
||||
|
||||
let _ = tokio::spawn(async move {
|
||||
tokio::spawn(async move {
|
||||
worker.work(rx).await;
|
||||
});
|
||||
|
||||
@@ -412,6 +414,10 @@ impl ClientWorker {
|
||||
if let Some(handle) = self.sync_handle.take() {
|
||||
handle.abort();
|
||||
}
|
||||
|
||||
if let Some(handle) = self.rcpt_handle.take() {
|
||||
handle.abort();
|
||||
}
|
||||
}
|
||||
|
||||
async fn run(&mut self, task: WorkerTask) {
|
||||
@@ -546,6 +552,20 @@ impl ClientWorker {
|
||||
},
|
||||
);
|
||||
|
||||
let _ = self.client.add_event_handler(
|
||||
|ev: SyncMessageLikeEvent<ReactionEventContent>,
|
||||
room: MatrixRoom,
|
||||
store: Ctx<AsyncProgramStore>| {
|
||||
async move {
|
||||
let room_id = room.room_id();
|
||||
|
||||
let mut locked = store.lock().await;
|
||||
let info = locked.application.get_room_info(room_id.to_owned());
|
||||
info.insert_reaction(ev.into_full_event(room_id.to_owned()));
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
let _ = self.client.add_event_handler(
|
||||
|ev: OriginalSyncRoomRedactionEvent,
|
||||
room: MatrixRoom,
|
||||
@@ -558,15 +578,21 @@ impl ClientWorker {
|
||||
let mut locked = store.lock().await;
|
||||
let info = locked.application.get_room_info(room_id.to_owned());
|
||||
|
||||
let key = if let Some(k) = info.keys.get(&ev.redacts) {
|
||||
k
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
match info.keys.get(&ev.redacts) {
|
||||
None => return,
|
||||
Some(EventLocation::Message(key)) => {
|
||||
if let Some(msg) = info.messages.get_mut(key) {
|
||||
let ev = SyncRoomRedactionEvent::Original(ev);
|
||||
msg.event.redact(ev, room_version);
|
||||
}
|
||||
},
|
||||
Some(EventLocation::Reaction(event_id)) => {
|
||||
if let Some(reactions) = info.reactions.get_mut(event_id) {
|
||||
reactions.remove(&ev.redacts);
|
||||
}
|
||||
|
||||
if let Some(msg) = info.messages.get_mut(key) {
|
||||
let ev = SyncRoomRedactionEvent::Original(ev);
|
||||
msg.event.redact(ev, room_version);
|
||||
info.keys.remove(&ev.redacts);
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -685,7 +711,8 @@ impl ClientWorker {
|
||||
);
|
||||
|
||||
let client = self.client.clone();
|
||||
let _ = tokio::spawn(async move {
|
||||
|
||||
self.rcpt_handle = tokio::spawn(async move {
|
||||
// Update the displayed read receipts ever 5 seconds.
|
||||
let mut interval = tokio::time::interval(Duration::from_secs(5));
|
||||
|
||||
@@ -695,7 +722,8 @@ impl ClientWorker {
|
||||
let receipts = update_receipts(&client).await;
|
||||
store.lock().await.application.set_receipts(receipts).await;
|
||||
}
|
||||
});
|
||||
})
|
||||
.into();
|
||||
|
||||
self.initialized = true;
|
||||
}
|
||||
@@ -762,7 +790,7 @@ impl ClientWorker {
|
||||
"Failed to create direct message room"
|
||||
);
|
||||
|
||||
let msg = format!("Could not open a room with {}", user);
|
||||
let msg = format!("Could not open a room with {user}");
|
||||
let err = UIError::Failure(msg);
|
||||
|
||||
Err(err)
|
||||
@@ -883,13 +911,7 @@ impl ClientWorker {
|
||||
|
||||
let msgs = chunk.into_iter().filter_map(|ev| {
|
||||
match ev.event.deserialize() {
|
||||
Ok(AnyTimelineEvent::MessageLike(msg)) => {
|
||||
if let AnyMessageLikeEvent::RoomMessage(msg) = msg {
|
||||
Some(msg)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
Ok(AnyTimelineEvent::MessageLike(msg)) => Some(msg),
|
||||
Ok(AnyTimelineEvent::State(_)) => None,
|
||||
Err(_) => None,
|
||||
}
|
||||
@@ -1007,12 +1029,12 @@ impl ClientWorker {
|
||||
let methods = vec![VerificationMethod::SasV1];
|
||||
let request = identity.request_verification_with_methods(methods);
|
||||
let _req = request.await.map_err(IambError::from)?;
|
||||
let info = format!("Sent verification request to {}", user_id);
|
||||
let info = format!("Sent verification request to {user_id}");
|
||||
|
||||
Ok(InfoMessage::from(info).into())
|
||||
},
|
||||
None => {
|
||||
let msg = format!("Could not find identity information for {}", user_id);
|
||||
let msg = format!("Could not find identity information for {user_id}");
|
||||
let err = UIError::Failure(msg);
|
||||
|
||||
Err(err)
|
||||
|
||||
Reference in New Issue
Block a user