Compare commits
142 Commits
letterbox-
...
letterbox-
| Author | SHA1 | Date | |
|---|---|---|---|
| 29de7c0727 | |||
| 5f6580fa2f | |||
| 5d4732d75d | |||
| a13bac813a | |||
| 85dcc9f7bd | |||
| b696629ad9 | |||
| b9e3128718 | |||
| 88fac4c2bc | |||
| 1fad5ec536 | |||
| 8e7214d531 | |||
| 333c4a3ebb | |||
| b9ba5a3bea | |||
| 2a0989e74d | |||
| e9319dc491 | |||
| 57481a77cd | |||
| 44915cce54 | |||
| 1225483b57 | |||
| daeb8c88a1 | |||
| 8a6b3ff501 | |||
| a6fffeafdc | |||
| d791b4ce49 | |||
| 8a0e4eb441 | |||
| fc84562419 | |||
| 37ebe1ebb3 | |||
| 2d06f070ea | |||
| 527a62069a | |||
| 40afafe1a8 | |||
| e3acf9ae6d | |||
| a68d067a68 | |||
| 5547c65af0 | |||
| b622bb7d7d | |||
| 43efdf18a0 | |||
| c71ab8e9e8 | |||
| 408d6ed8ba | |||
| 1411961e36 | |||
| dfd7ef466c | |||
| 2aa3dfbd0f | |||
| fba10e27cf | |||
| 5417c74f9c | |||
| eb0b0dbe81 | |||
| 561f522658 | |||
| 32d2ffeb3d | |||
| d41946e0a5 | |||
| 61402858f4 | |||
| 17de318645 | |||
| 3aa0144e8d | |||
| f9eafff4c7 | |||
| 4c6d67901d | |||
| e9aa97a089 | |||
| a82b047f75 | |||
| 9a8b44a8df | |||
| a96693004c | |||
| ed9fe11fbf | |||
| 09fb14a796 | |||
| 58a7936bba | |||
| cd0ee361f5 | |||
| 77bd5abe0d | |||
| 450c5496b3 | |||
| 4411e45a3c | |||
| e7d20896d5 | |||
| 32a1115abd | |||
| 4982057500 | |||
| 8977f8bab5 | |||
| 0962a6b3cf | |||
| 3c72929a4f | |||
| e4eb495a70 | |||
| 00e8b0342e | |||
| b1f9867c06 | |||
| 77943b3570 | |||
| 45e4edb1dd | |||
| 9bf53afebf | |||
| e1a502ac4b | |||
| 9346c46e62 | |||
| 1452746305 | |||
| 2e526dace1 | |||
| 76be5b7cac | |||
| 3f0b2caedf | |||
| ec6dc35ca8 | |||
| 01e1ca927e | |||
| 1cc52d6c96 | |||
| e6b3a5b5a9 | |||
| bc4b15a5aa | |||
| 00f61cf6be | |||
| 52e24437bd | |||
| 393ffc8506 | |||
| 2b6cb6ec6e | |||
| 0cba3a624c | |||
| 73433711ca | |||
| 965afa6871 | |||
| e70dbaf917 | |||
| 6b4ce11743 | |||
| d1980a55a7 | |||
| 8b78b39d4c | |||
| ae17651eb5 | |||
| 22fd8409f6 | |||
| d0a4ba417f | |||
| 7b09b098a4 | |||
| bd4c10a8fb | |||
| ed3c5f152e | |||
| 63232d1e92 | |||
| 4a3eba80d5 | |||
| 71d3745342 | |||
| 5fdc98633d | |||
| 57877f268d | |||
| 871a93d58f | |||
| 4b7cbd4f9b | |||
| aa2a9815df | |||
| 2e5b18a008 | |||
| d0a38114cc | |||
| ccc1d516c7 | |||
| 246b710fdd | |||
| 1a21c9fa8e | |||
| 9fd912b1d4 | |||
| 9ded32f97b | |||
| 10aac046bc | |||
| f4527baf89 | |||
| 11ec5bf747 | |||
| 6a53679755 | |||
| 7bedec0692 | |||
| 78feb95811 | |||
| 3aad2bb80e | |||
| 0df8de3661 | |||
| 83ecc73fbd | |||
| c10313cd12 | |||
| 4c98bcd9cb | |||
| 004de235a8 | |||
| 90dbeb6f20 | |||
| 9aa298febe | |||
| 5a13a497dc | |||
| 37711e14dd | |||
| e89fd28707 | |||
| 7a91ee2f49 | |||
| 4b76ea5392 | |||
| d2a81b7bd9 | |||
| 9dd39509b5 | |||
| d605bcfe7a | |||
| 73abdb535a | |||
| ab9506c4f6 | |||
| 994a629401 | |||
| 00c55160a7 | |||
| e3c6edb894 | |||
| 4574c016cd |
@@ -1,4 +1,4 @@
|
|||||||
on: [push, pull_request]
|
on: [push]
|
||||||
|
|
||||||
name: Continuous integration
|
name: Continuous integration
|
||||||
|
|
||||||
@@ -49,3 +49,19 @@ jobs:
|
|||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
- run: cargo build
|
- run: cargo build
|
||||||
|
|
||||||
|
udeps:
|
||||||
|
name: Disallow unused dependencies
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: nightly
|
||||||
|
|
||||||
|
- name: Run cargo-udeps
|
||||||
|
uses: aig787/cargo-udeps-action@v1
|
||||||
|
with:
|
||||||
|
version: 'latest'
|
||||||
|
args: '--all-targets'
|
||||||
|
|
||||||
|
|||||||
2039
Cargo.lock
generated
2039
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
11
Cargo.toml
11
Cargo.toml
@@ -1,8 +1,15 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
default-members = ["server"]
|
default-members = ["server"]
|
||||||
members = ["server", "notmuch", "procmail2notmuch", "shared"]
|
members = ["web", "server", "notmuch", "procmail2notmuch", "shared"]
|
||||||
#members = ["web", "server", "notmuch", "procmail2notmuch", "shared"]
|
|
||||||
|
[workspace.package]
|
||||||
|
authors = ["Bill Thiede <git@xinu.tv>"]
|
||||||
|
edition = "2021"
|
||||||
|
license = "UNLICENSED"
|
||||||
|
publish = ["xinu"]
|
||||||
|
version = "0.10.8"
|
||||||
|
repository = "https://git.z.xinu.tv/wathiede/letterbox"
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
opt-level = 1
|
opt-level = 1
|
||||||
|
|||||||
19
Justfile
Normal file
19
Justfile
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
export CARGO_INCREMENTAL := "0"
|
||||||
|
export RUSTFLAGS := "-D warnings"
|
||||||
|
|
||||||
|
default:
|
||||||
|
@echo "Run: just patch|minor|major"
|
||||||
|
|
||||||
|
major: (_release "major")
|
||||||
|
minor: (_release "minor")
|
||||||
|
patch: (_release "patch")
|
||||||
|
|
||||||
|
sqlx-prepare:
|
||||||
|
cd server; cargo sqlx prepare && git add .sqlx; git commit -m "cargo sqlx prepare" .sqlx || true
|
||||||
|
|
||||||
|
pull:
|
||||||
|
git pull
|
||||||
|
|
||||||
|
|
||||||
|
_release level: pull sqlx-prepare
|
||||||
|
cargo-release release -x {{ level }} --workspace --no-confirm --registry=xinu
|
||||||
@@ -1,16 +1,18 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "letterbox-notmuch"
|
name = "letterbox-notmuch"
|
||||||
version = "0.3.0"
|
|
||||||
edition = "2021"
|
|
||||||
exclude = ["/testdata"]
|
exclude = ["/testdata"]
|
||||||
description = "Wrapper for calling notmuch cli"
|
description = "Wrapper for calling notmuch cli"
|
||||||
license = "UNLICENSED"
|
authors.workspace = true
|
||||||
repository = "https://git.z.xinu.tv/wathiede/letterbox"
|
edition.workspace = true
|
||||||
publish = ["xinu"]
|
license.workspace = true
|
||||||
|
publish.workspace = true
|
||||||
|
repository.workspace = true
|
||||||
|
version.workspace = true
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.4.14"
|
log = "0.4.14"
|
||||||
|
mailparse = "0.16.0"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = { version = "1.0", features = ["unbounded_depth"] }
|
serde_json = { version = "1.0", features = ["unbounded_depth"] }
|
||||||
thiserror = "2.0.0"
|
thiserror = "2.0.0"
|
||||||
|
|||||||
@@ -207,6 +207,7 @@
|
|||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
|
collections::HashMap,
|
||||||
ffi::OsStr,
|
ffi::OsStr,
|
||||||
io::{self},
|
io::{self},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
@@ -270,6 +271,12 @@ pub struct Headers {
|
|||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub bcc: Option<String>,
|
pub bcc: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
#[serde(alias = "Delivered-To")]
|
||||||
|
pub delivered_to: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
#[serde(alias = "X-Original-To")]
|
||||||
|
pub x_original_to: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub reply_to: Option<String>,
|
pub reply_to: Option<String>,
|
||||||
pub date: String,
|
pub date: String,
|
||||||
}
|
}
|
||||||
@@ -459,6 +466,8 @@ pub enum NotmuchError {
|
|||||||
StringUtf8Error(#[from] std::string::FromUtf8Error),
|
StringUtf8Error(#[from] std::string::FromUtf8Error),
|
||||||
#[error("failed to parse str as int")]
|
#[error("failed to parse str as int")]
|
||||||
ParseIntError(#[from] std::num::ParseIntError),
|
ParseIntError(#[from] std::num::ParseIntError),
|
||||||
|
#[error("failed to parse mail: {0}")]
|
||||||
|
MailParseError(#[from] mailparse::MailParseError),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@@ -605,6 +614,80 @@ impl Notmuch {
|
|||||||
Ok(serde_json::from_slice(&res)?)
|
Ok(serde_json::from_slice(&res)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip_all)]
|
||||||
|
pub fn unread_recipients(&self) -> Result<HashMap<String, usize>, NotmuchError> {
|
||||||
|
let slice = self.run_notmuch([
|
||||||
|
"show",
|
||||||
|
"--include-html=false",
|
||||||
|
"--entire-thread=false",
|
||||||
|
"--body=false",
|
||||||
|
"--format=json",
|
||||||
|
// Arbitrary limit to prevent too much work
|
||||||
|
"--limit=1000",
|
||||||
|
"is:unread",
|
||||||
|
])?;
|
||||||
|
// Notmuch returns JSON with invalid unicode. So we lossy convert it to a string here and
|
||||||
|
// use that for parsing in rust.
|
||||||
|
let s = String::from_utf8_lossy(&slice);
|
||||||
|
let mut deserializer = serde_json::Deserializer::from_str(&s);
|
||||||
|
deserializer.disable_recursion_limit();
|
||||||
|
let ts: ThreadSet = serde::de::Deserialize::deserialize(&mut deserializer)?;
|
||||||
|
deserializer.end()?;
|
||||||
|
let mut r = HashMap::new();
|
||||||
|
fn collect_from_thread_node(
|
||||||
|
r: &mut HashMap<String, usize>,
|
||||||
|
tn: &ThreadNode,
|
||||||
|
) -> Result<(), NotmuchError> {
|
||||||
|
let Some(msg) = &tn.0 else {
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
let mut addrs = vec![];
|
||||||
|
let hdr = &msg.headers.to;
|
||||||
|
if let Some(to) = hdr {
|
||||||
|
addrs.push(to);
|
||||||
|
} else {
|
||||||
|
let hdr = &msg.headers.x_original_to;
|
||||||
|
if let Some(to) = hdr {
|
||||||
|
addrs.push(to);
|
||||||
|
} else {
|
||||||
|
let hdr = &msg.headers.delivered_to;
|
||||||
|
if let Some(to) = hdr {
|
||||||
|
addrs.push(to);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
let hdr = &msg.headers.cc;
|
||||||
|
if let Some(cc) = hdr {
|
||||||
|
addrs.push(cc);
|
||||||
|
};
|
||||||
|
for recipient in addrs {
|
||||||
|
mailparse::addrparse(&recipient)?
|
||||||
|
.into_inner()
|
||||||
|
.iter()
|
||||||
|
.for_each(|a| {
|
||||||
|
let mailparse::MailAddr::Single(si) = a else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let addr = &si.addr;
|
||||||
|
|
||||||
|
if addr == "couchmoney@gmail.com" || addr.ends_with("@xinu.tv") {
|
||||||
|
*r.entry(addr.to_lowercase()).or_default() += 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
for t in ts.0 {
|
||||||
|
for tn in t.0 {
|
||||||
|
collect_from_thread_node(&mut r, &tn)?;
|
||||||
|
for sub_tn in tn.1 {
|
||||||
|
collect_from_thread_node(&mut r, &sub_tn)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(r)
|
||||||
|
}
|
||||||
|
|
||||||
fn run_notmuch<I, S>(&self, args: I) -> Result<Vec<u8>, NotmuchError>
|
fn run_notmuch<I, S>(&self, args: I) -> Result<Vec<u8>, NotmuchError>
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = S>,
|
I: IntoIterator<Item = S>,
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "letterbox-procmail2notmuch"
|
name = "letterbox-procmail2notmuch"
|
||||||
version = "0.3.0"
|
|
||||||
edition = "2021"
|
|
||||||
description = "Tool for generating notmuch rules from procmail"
|
description = "Tool for generating notmuch rules from procmail"
|
||||||
license = "UNLICENSED"
|
authors.workspace = true
|
||||||
repository = "https://git.z.xinu.tv/wathiede/letterbox"
|
edition.workspace = true
|
||||||
publish = ["xinu"]
|
license.workspace = true
|
||||||
|
publish.workspace = true
|
||||||
|
repository.workspace = true
|
||||||
|
version.workspace = true
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "letterbox-server"
|
name = "letterbox-server"
|
||||||
version = "0.3.0"
|
|
||||||
edition = "2021"
|
|
||||||
default-run = "letterbox-server"
|
default-run = "letterbox-server"
|
||||||
description = "Backend for letterbox"
|
description = "Backend for letterbox"
|
||||||
license = "UNLICENSED"
|
authors.workspace = true
|
||||||
repository = "https://git.z.xinu.tv/wathiede/letterbox"
|
edition.workspace = true
|
||||||
publish = ["xinu"]
|
license.workspace = true
|
||||||
|
publish.workspace = true
|
||||||
|
repository.workspace = true
|
||||||
|
version.workspace = true
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
@@ -16,7 +17,7 @@ anyhow = "1.0.79"
|
|||||||
async-graphql = { version = "7", features = ["log"] }
|
async-graphql = { version = "7", features = ["log"] }
|
||||||
async-graphql-rocket = "7"
|
async-graphql-rocket = "7"
|
||||||
async-trait = "0.1.81"
|
async-trait = "0.1.81"
|
||||||
build-info = "0.0.39"
|
build-info = "0.0.40"
|
||||||
cacher = { version = "0.1.0", registry = "xinu" }
|
cacher = { version = "0.1.0", registry = "xinu" }
|
||||||
chrono = "0.4.39"
|
chrono = "0.4.39"
|
||||||
clap = { version = "4.5.23", features = ["derive"] }
|
clap = { version = "4.5.23", features = ["derive"] }
|
||||||
@@ -29,12 +30,11 @@ lol_html = "2.0.0"
|
|||||||
mailparse = "0.16.0"
|
mailparse = "0.16.0"
|
||||||
maplit = "1.0.2"
|
maplit = "1.0.2"
|
||||||
memmap = "0.7.0"
|
memmap = "0.7.0"
|
||||||
opentelemetry = "0.28.0"
|
|
||||||
regex = "1.11.1"
|
regex = "1.11.1"
|
||||||
reqwest = { version = "0.12.7", features = ["blocking"] }
|
reqwest = { version = "0.12.7", features = ["blocking"] }
|
||||||
rocket = { version = "0.5.0-rc.2", features = ["json"] }
|
rocket = { version = "0.5.0-rc.2", features = ["json"] }
|
||||||
rocket_cors = "0.6.0"
|
rocket_cors = "0.6.0"
|
||||||
scraper = "0.22.0"
|
scraper = "0.23.0"
|
||||||
serde = { version = "1.0.147", features = ["derive"] }
|
serde = { version = "1.0.147", features = ["derive"] }
|
||||||
serde_json = "1.0.87"
|
serde_json = "1.0.87"
|
||||||
sqlx = { version = "0.8.2", features = ["postgres", "runtime-tokio", "time"] }
|
sqlx = { version = "0.8.2", features = ["postgres", "runtime-tokio", "time"] }
|
||||||
@@ -46,12 +46,12 @@ url = "2.5.2"
|
|||||||
urlencoding = "2.1.3"
|
urlencoding = "2.1.3"
|
||||||
#xtracing = { path = "../../xtracing" }
|
#xtracing = { path = "../../xtracing" }
|
||||||
#xtracing = { git = "http://git-private.h.xinu.tv/wathiede/xtracing.git" }
|
#xtracing = { git = "http://git-private.h.xinu.tv/wathiede/xtracing.git" }
|
||||||
xtracing = { version = "0.2.0", registry = "xinu" }
|
xtracing = { version = "0.3.0", registry = "xinu" }
|
||||||
letterbox-notmuch = { version = "0.1.0", registry = "xinu" }
|
letterbox-notmuch = { version = "0.10.8", path = "../notmuch", registry = "xinu" }
|
||||||
letterbox-shared = { version = "0.1.0", registry = "xinu" }
|
letterbox-shared = { version = "0.10.8", path = "../shared", registry = "xinu" }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
build-info-build = "0.0.39"
|
build-info-build = "0.0.40"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
#default = [ "tantivy" ]
|
#default = [ "tantivy" ]
|
||||||
|
|||||||
20
server/migrations/20250330175930_update-nzfinder-link.sql
Normal file
20
server/migrations/20250330175930_update-nzfinder-link.sql
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
-- Bad examples:
|
||||||
|
-- https://nzbfinder.ws/getnzb/d2c3e5a08abadd985dccc6a574122892030b6a9a.nzb&i=95972&r=b55082d289937c050dedc203c9653850
|
||||||
|
-- https://nzbfinder.ws/getnzb?id=45add174-7da4-4445-bf2b-a67dbbfc07fe.nzb&r=b55082d289937c050dedc203c9653850
|
||||||
|
-- https://nzbfinder.ws/api/v1/getnzb?id=82486020-c192-4fa0-a7e7-798d7d72e973.nzb&r=b55082d289937c050dedc203c9653850
|
||||||
|
UPDATE nzb_posts
|
||||||
|
SET link =
|
||||||
|
regexp_replace(
|
||||||
|
regexp_replace(
|
||||||
|
regexp_replace(
|
||||||
|
link,
|
||||||
|
'https://nzbfinder.ws/getnzb/',
|
||||||
|
'https://nzbfinder.ws/api/v1/getnzb?id='
|
||||||
|
),
|
||||||
|
'https://nzbfinder.ws/getnzb',
|
||||||
|
'https://nzbfinder.ws/api/v1/getnzb'
|
||||||
|
),
|
||||||
|
'&r=',
|
||||||
|
'&apikey='
|
||||||
|
)
|
||||||
|
;
|
||||||
@@ -95,6 +95,10 @@ pub struct Message {
|
|||||||
pub to: Vec<Email>,
|
pub to: Vec<Email>,
|
||||||
// All CC headers found in email
|
// All CC headers found in email
|
||||||
pub cc: Vec<Email>,
|
pub cc: Vec<Email>,
|
||||||
|
// X-Original-To header found in email
|
||||||
|
pub x_original_to: Option<Email>,
|
||||||
|
// Delivered-To header found in email
|
||||||
|
pub delivered_to: Option<Email>,
|
||||||
// First Subject header found in email
|
// First Subject header found in email
|
||||||
pub subject: Option<String>,
|
pub subject: Option<String>,
|
||||||
// Parsed Date header, if found and valid
|
// Parsed Date header, if found and valid
|
||||||
@@ -286,7 +290,7 @@ impl QueryRoot {
|
|||||||
Ok(letterbox_shared::build_version(bi))
|
Ok(letterbox_shared::build_version(bi))
|
||||||
}
|
}
|
||||||
#[instrument(skip_all, fields(query=query))]
|
#[instrument(skip_all, fields(query=query))]
|
||||||
#[instrument(skip_all, fields(query=query, request_id=request_id()))]
|
#[instrument(skip_all, fields(query=query, rid=request_id()))]
|
||||||
async fn count<'ctx>(&self, ctx: &Context<'ctx>, query: String) -> Result<usize, Error> {
|
async fn count<'ctx>(&self, ctx: &Context<'ctx>, query: String) -> Result<usize, Error> {
|
||||||
let nm = ctx.data_unchecked::<Notmuch>();
|
let nm = ctx.data_unchecked::<Notmuch>();
|
||||||
let pool = ctx.data_unchecked::<PgPool>();
|
let pool = ctx.data_unchecked::<PgPool>();
|
||||||
@@ -306,10 +310,49 @@ impl QueryRoot {
|
|||||||
info!("count {newsreader_query:?} newsreader count {newsreader_count} notmuch count {notmuch_count} tantivy count {tantivy_count} total {total}");
|
info!("count {newsreader_query:?} newsreader count {newsreader_count} notmuch count {notmuch_count} tantivy count {tantivy_count} total {total}");
|
||||||
Ok(total)
|
Ok(total)
|
||||||
}
|
}
|
||||||
|
async fn catchup<'ctx>(
|
||||||
|
&self,
|
||||||
|
ctx: &Context<'ctx>,
|
||||||
|
query: String,
|
||||||
|
) -> Result<Vec<String>, Error> {
|
||||||
|
let nm = ctx.data_unchecked::<Notmuch>();
|
||||||
|
let pool = ctx.data_unchecked::<PgPool>();
|
||||||
|
let query: Query = query.parse()?;
|
||||||
|
// TODO: implement optimized versions of fetching just IDs
|
||||||
|
let newsreader_fut = newsreader_search(pool, None, None, None, None, &query);
|
||||||
|
let notmuch_fut = notmuch_search(nm, None, None, None, None, &query);
|
||||||
|
let (newsreader_results, notmuch_results) = join!(newsreader_fut, notmuch_fut);
|
||||||
|
|
||||||
|
let newsreader_results = newsreader_results?;
|
||||||
|
let notmuch_results = notmuch_results?;
|
||||||
|
info!(
|
||||||
|
"newsreader_results ({}) notmuch_results ({})",
|
||||||
|
newsreader_results.len(),
|
||||||
|
notmuch_results.len(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut results: Vec<_> = newsreader_results
|
||||||
|
.into_iter()
|
||||||
|
.chain(notmuch_results)
|
||||||
|
.collect();
|
||||||
|
// The leading '-' is to reverse sort
|
||||||
|
results.sort_by_key(|item| match item {
|
||||||
|
ThreadSummaryCursor::Newsreader(_, ts) => -ts.timestamp,
|
||||||
|
ThreadSummaryCursor::Notmuch(_, ts) => -ts.timestamp,
|
||||||
|
});
|
||||||
|
let ids = results
|
||||||
|
.into_iter()
|
||||||
|
.map(|r| match r {
|
||||||
|
ThreadSummaryCursor::Newsreader(_, ts) => ts.thread,
|
||||||
|
ThreadSummaryCursor::Notmuch(_, ts) => ts.thread,
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
Ok(ids)
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: this function doesn't get parallelism, possibly because notmuch is sync and blocks,
|
// TODO: this function doesn't get parallelism, possibly because notmuch is sync and blocks,
|
||||||
// rewrite that with tokio::process:Command
|
// rewrite that with tokio::process:Command
|
||||||
#[instrument(skip_all, fields(query=query, request_id=request_id()))]
|
#[instrument(skip_all, fields(query=query, rid=request_id()))]
|
||||||
async fn search<'ctx>(
|
async fn search<'ctx>(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Context<'ctx>,
|
ctx: &Context<'ctx>,
|
||||||
@@ -467,7 +510,7 @@ impl QueryRoot {
|
|||||||
.await?)
|
.await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip_all, fields(request_id=request_id()))]
|
#[instrument(skip_all, fields(rid=request_id()))]
|
||||||
async fn tags<'ctx>(&self, ctx: &Context<'ctx>) -> FieldResult<Vec<Tag>> {
|
async fn tags<'ctx>(&self, ctx: &Context<'ctx>) -> FieldResult<Vec<Tag>> {
|
||||||
let nm = ctx.data_unchecked::<Notmuch>();
|
let nm = ctx.data_unchecked::<Notmuch>();
|
||||||
let pool = ctx.data_unchecked::<PgPool>();
|
let pool = ctx.data_unchecked::<PgPool>();
|
||||||
@@ -476,7 +519,7 @@ impl QueryRoot {
|
|||||||
tags.append(&mut nm::tags(nm, needs_unread)?);
|
tags.append(&mut nm::tags(nm, needs_unread)?);
|
||||||
Ok(tags)
|
Ok(tags)
|
||||||
}
|
}
|
||||||
#[instrument(skip_all, fields(thread_id=thread_id, request_id=request_id()))]
|
#[instrument(skip_all, fields(thread_id=thread_id, rid=request_id()))]
|
||||||
async fn thread<'ctx>(&self, ctx: &Context<'ctx>, thread_id: String) -> Result<Thread, Error> {
|
async fn thread<'ctx>(&self, ctx: &Context<'ctx>, thread_id: String) -> Result<Thread, Error> {
|
||||||
let nm = ctx.data_unchecked::<Notmuch>();
|
let nm = ctx.data_unchecked::<Notmuch>();
|
||||||
let cacher = ctx.data_unchecked::<FilesystemCacher>();
|
let cacher = ctx.data_unchecked::<FilesystemCacher>();
|
||||||
@@ -553,7 +596,7 @@ async fn tantivy_search(
|
|||||||
pub struct Mutation;
|
pub struct Mutation;
|
||||||
#[Object]
|
#[Object]
|
||||||
impl Mutation {
|
impl Mutation {
|
||||||
#[instrument(skip_all, fields(query=query, unread=unread, request_id=request_id()))]
|
#[instrument(skip_all, fields(query=query, unread=unread, rid=request_id()))]
|
||||||
async fn set_read_status<'ctx>(
|
async fn set_read_status<'ctx>(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Context<'ctx>,
|
ctx: &Context<'ctx>,
|
||||||
@@ -572,7 +615,7 @@ impl Mutation {
|
|||||||
nm::set_read_status(nm, &query, unread).await?;
|
nm::set_read_status(nm, &query, unread).await?;
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
#[instrument(skip_all, fields(query=query, tag=tag, request_id=request_id()))]
|
#[instrument(skip_all, fields(query=query, tag=tag, rid=request_id()))]
|
||||||
async fn tag_add<'ctx>(
|
async fn tag_add<'ctx>(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Context<'ctx>,
|
ctx: &Context<'ctx>,
|
||||||
@@ -584,7 +627,7 @@ impl Mutation {
|
|||||||
nm.tag_add(&tag, &query)?;
|
nm.tag_add(&tag, &query)?;
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
#[instrument(skip_all, fields(query=query, tag=tag, request_id=request_id()))]
|
#[instrument(skip_all, fields(query=query, tag=tag, rid=request_id()))]
|
||||||
async fn tag_remove<'ctx>(
|
async fn tag_remove<'ctx>(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Context<'ctx>,
|
ctx: &Context<'ctx>,
|
||||||
@@ -607,7 +650,7 @@ impl Mutation {
|
|||||||
|
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
#[instrument(skip_all, fields(request_id=request_id()))]
|
#[instrument(skip_all, fields(rid=request_id()))]
|
||||||
async fn refresh<'ctx>(&self, ctx: &Context<'ctx>) -> Result<bool, Error> {
|
async fn refresh<'ctx>(&self, ctx: &Context<'ctx>) -> Result<bool, Error> {
|
||||||
let nm = ctx.data_unchecked::<Notmuch>();
|
let nm = ctx.data_unchecked::<Notmuch>();
|
||||||
let cacher = ctx.data_unchecked::<FilesystemCacher>();
|
let cacher = ctx.data_unchecked::<FilesystemCacher>();
|
||||||
|
|||||||
@@ -318,13 +318,16 @@ impl<'c> Transformer for SlurpContents<'c> {
|
|||||||
} else {
|
} else {
|
||||||
let resp = reqwest::get(link.as_str()).await?;
|
let resp = reqwest::get(link.as_str()).await?;
|
||||||
let status = resp.status();
|
let status = resp.status();
|
||||||
if status.is_server_error() || retryable_status.contains(&status) {
|
if status.is_server_error() {
|
||||||
return Err(TransformError::RetryableHttpStatusError(
|
error!("status error for {link}: {status}");
|
||||||
status,
|
return Ok(html.to_string());
|
||||||
link.to_string(),
|
}
|
||||||
));
|
if retryable_status.contains(&status) {
|
||||||
|
error!("retryable error for {link}: {status}");
|
||||||
|
return Ok(html.to_string());
|
||||||
}
|
}
|
||||||
if !status.is_success() {
|
if !status.is_success() {
|
||||||
|
error!("unsuccessful for {link}: {status}");
|
||||||
return Ok(html.to_string());
|
return Ok(html.to_string());
|
||||||
}
|
}
|
||||||
let body = resp.text().await?;
|
let body = resp.text().await?;
|
||||||
@@ -682,7 +685,7 @@ fn compute_offset_limit(
|
|||||||
first: Option<i32>,
|
first: Option<i32>,
|
||||||
last: Option<i32>,
|
last: Option<i32>,
|
||||||
) -> (i32, i32) {
|
) -> (i32, i32) {
|
||||||
let default_page_size = 100;
|
let default_page_size = 10000;
|
||||||
match (after, before, first, last) {
|
match (after, before, first, last) {
|
||||||
// Reasonable defaults
|
// Reasonable defaults
|
||||||
(None, None, None, None) => (0, default_page_size),
|
(None, None, None, None) => (0, default_page_size),
|
||||||
@@ -773,7 +776,19 @@ impl Query {
|
|||||||
for uid in &self.uids {
|
for uid in &self.uids {
|
||||||
parts.push(uid.clone());
|
parts.push(uid.clone());
|
||||||
}
|
}
|
||||||
parts.extend(self.remainder.clone());
|
for r in &self.remainder {
|
||||||
|
// Rewrite "to:" to include ExtraTo:. ExtraTo: is configured in
|
||||||
|
// notmuch-config to index Delivered-To and X-Original-To headers.
|
||||||
|
if r.starts_with("to:") {
|
||||||
|
parts.push("(".to_string());
|
||||||
|
parts.push(r.to_string());
|
||||||
|
parts.push("OR".to_string());
|
||||||
|
parts.push(r.replace("to:", "ExtraTo:"));
|
||||||
|
parts.push(")".to_string());
|
||||||
|
} else {
|
||||||
|
parts.push(r.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
parts.join(" ")
|
parts.join(" ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -793,7 +808,17 @@ impl FromStr for Query {
|
|||||||
if word == "is:unread" {
|
if word == "is:unread" {
|
||||||
unread_only = true
|
unread_only = true
|
||||||
} else if word.starts_with("tag:") {
|
} else if word.starts_with("tag:") {
|
||||||
tags.push(word["tag:".len()..].to_string());
|
let t = &word["tag:".len()..];
|
||||||
|
// Per-address emails are faked as `tag:@<domain>/<username>`, rewrite to `to:` form
|
||||||
|
if t.starts_with('@') && t.contains('.') {
|
||||||
|
let t = match t.split_once('/') {
|
||||||
|
None => format!("to:{t}"),
|
||||||
|
Some((domain, user)) => format!("to:{user}{domain}"),
|
||||||
|
};
|
||||||
|
remainder.push(t);
|
||||||
|
} else {
|
||||||
|
tags.push(t.to_string());
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
} else if word.starts_with("tag:") {
|
} else if word.starts_with("tag:") {
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
use std::{
|
use std::{collections::HashMap, fs::File};
|
||||||
collections::HashMap,
|
|
||||||
fs::File,
|
|
||||||
hash::{DefaultHasher, Hash, Hasher},
|
|
||||||
time::Instant,
|
|
||||||
};
|
|
||||||
|
|
||||||
use letterbox_notmuch::Notmuch;
|
use letterbox_notmuch::Notmuch;
|
||||||
|
use letterbox_shared::compute_color;
|
||||||
use log::{error, info, warn};
|
use log::{error, info, warn};
|
||||||
use mailparse::{parse_content_type, parse_mail, MailHeader, MailHeaderMap, ParsedMail};
|
use mailparse::{parse_content_type, parse_mail, MailHeader, MailHeaderMap, ParsedMail};
|
||||||
use memmap::MmapOptions;
|
use memmap::MmapOptions;
|
||||||
@@ -107,7 +103,6 @@ pub async fn search(
|
|||||||
|
|
||||||
#[instrument(name="nm::tags", skip_all, fields(needs_unread=needs_unread))]
|
#[instrument(name="nm::tags", skip_all, fields(needs_unread=needs_unread))]
|
||||||
pub fn tags(nm: &Notmuch, needs_unread: bool) -> Result<Vec<Tag>, ServerError> {
|
pub fn tags(nm: &Notmuch, needs_unread: bool) -> Result<Vec<Tag>, ServerError> {
|
||||||
let now = Instant::now();
|
|
||||||
let unread_msg_cnt: HashMap<String, usize> = if needs_unread {
|
let unread_msg_cnt: HashMap<String, usize> = if needs_unread {
|
||||||
// 10000 is an arbitrary number, if there's more than 10k unread messages, we'll
|
// 10000 is an arbitrary number, if there's more than 10k unread messages, we'll
|
||||||
// get an inaccurate count.
|
// get an inaccurate count.
|
||||||
@@ -123,13 +118,11 @@ pub fn tags(nm: &Notmuch, needs_unread: bool) -> Result<Vec<Tag>, ServerError> {
|
|||||||
} else {
|
} else {
|
||||||
HashMap::new()
|
HashMap::new()
|
||||||
};
|
};
|
||||||
let tags = nm
|
let tags: Vec<_> = nm
|
||||||
.tags()?
|
.tags()?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|tag| {
|
.map(|tag| {
|
||||||
let mut hasher = DefaultHasher::new();
|
let hex = compute_color(&tag);
|
||||||
tag.hash(&mut hasher);
|
|
||||||
let hex = format!("#{:06x}", hasher.finish() % (1 << 24));
|
|
||||||
let unread = if needs_unread {
|
let unread = if needs_unread {
|
||||||
*unread_msg_cnt.get(&tag).unwrap_or(&0)
|
*unread_msg_cnt.get(&tag).unwrap_or(&0)
|
||||||
} else {
|
} else {
|
||||||
@@ -142,8 +135,24 @@ pub fn tags(nm: &Notmuch, needs_unread: bool) -> Result<Vec<Tag>, ServerError> {
|
|||||||
unread,
|
unread,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.chain(
|
||||||
|
nm.unread_recipients()?
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|(name, unread)| {
|
||||||
|
let Some(idx) = name.find('@') else {
|
||||||
|
return None;
|
||||||
|
};
|
||||||
|
let name = format!("{}/{}", &name[idx..], &name[..idx]);
|
||||||
|
let bg_color = compute_color(&name);
|
||||||
|
Some(Tag {
|
||||||
|
name,
|
||||||
|
fg_color: "white".to_string(),
|
||||||
|
bg_color,
|
||||||
|
unread,
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
)
|
||||||
.collect();
|
.collect();
|
||||||
info!("Fetching tags took {} seconds", now.elapsed().as_secs_f32());
|
|
||||||
Ok(tags)
|
Ok(tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,6 +196,8 @@ pub async fn thread(
|
|||||||
|
|
||||||
let to = email_addresses(&path, &m, "to")?;
|
let to = email_addresses(&path, &m, "to")?;
|
||||||
let cc = email_addresses(&path, &m, "cc")?;
|
let cc = email_addresses(&path, &m, "cc")?;
|
||||||
|
let delivered_to = email_addresses(&path, &m, "delivered-to")?.pop();
|
||||||
|
let x_original_to = email_addresses(&path, &m, "x-original-to")?.pop();
|
||||||
let subject = m.headers.get_first_value("subject");
|
let subject = m.headers.get_first_value("subject");
|
||||||
let timestamp = m
|
let timestamp = m
|
||||||
.headers
|
.headers
|
||||||
@@ -306,6 +317,8 @@ pub async fn thread(
|
|||||||
body,
|
body,
|
||||||
path,
|
path,
|
||||||
attachments,
|
attachments,
|
||||||
|
delivered_to,
|
||||||
|
x_original_to,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
messages.reverse();
|
messages.reverse();
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "letterbox-shared"
|
name = "letterbox-shared"
|
||||||
version = "0.3.0"
|
|
||||||
edition = "2021"
|
|
||||||
description = "Shared module for letterbox"
|
description = "Shared module for letterbox"
|
||||||
license = "UNLICENSED"
|
authors.workspace = true
|
||||||
repository = "https://git.z.xinu.tv/wathiede/letterbox"
|
edition.workspace = true
|
||||||
publish = ["xinu"]
|
license.workspace = true
|
||||||
|
publish.workspace = true
|
||||||
|
repository.workspace = true
|
||||||
|
version.workspace = true
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
build-info = "0.0.39"
|
build-info = "0.0.40"
|
||||||
letterbox-notmuch = { version = "0.1.0", registry = "xinu" }
|
letterbox-notmuch = { version = "0.10.8", path = "../notmuch", registry = "xinu" }
|
||||||
serde = { version = "1.0.147", features = ["derive"] }
|
serde = { version = "1.0.147", features = ["derive"] }
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
[package]
|
[package]
|
||||||
version = "0.1.0"
|
|
||||||
name = "letterbox-web"
|
name = "letterbox-web"
|
||||||
authors = ["Bill Thiede <git@xinu.tv>"]
|
|
||||||
edition = "2021"
|
|
||||||
description = "Web frontend for letterbox"
|
description = "Web frontend for letterbox"
|
||||||
license = "UNLICENSED"
|
authors.workspace = true
|
||||||
repository = "https://git.z.xinu.tv/wathiede/letterbox"
|
edition.workspace = true
|
||||||
publish = ["xinu"]
|
license.workspace = true
|
||||||
|
publish.workspace = true
|
||||||
|
repository.workspace = true
|
||||||
|
version.workspace = true
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
build-info-build = "0.0.39"
|
build-info-build = "0.0.40"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
wasm-bindgen-test = "0.3.33"
|
wasm-bindgen-test = "0.3.33"
|
||||||
@@ -26,16 +26,17 @@ serde_json = { version = "1.0.93", features = ["unbounded_depth"] }
|
|||||||
chrono = "0.4.31"
|
chrono = "0.4.31"
|
||||||
graphql_client = "0.14.0"
|
graphql_client = "0.14.0"
|
||||||
thiserror = "2.0.0"
|
thiserror = "2.0.0"
|
||||||
seed_hooks = { git = "https://github.com/wathiede/styles_hooks", package = "seed_hooks", branch = "main" }
|
|
||||||
gloo-net = { version = "0.6.0", features = ["json", "serde_json"] }
|
gloo-net = { version = "0.6.0", features = ["json", "serde_json"] }
|
||||||
human_format = "1.1.0"
|
human_format = "1.1.0"
|
||||||
build-info = "0.0.39"
|
build-info = "0.0.40"
|
||||||
wasm-bindgen = "=0.2.100"
|
wasm-bindgen = "=0.2.100"
|
||||||
uuid = { version = "1.13.1", features = [
|
uuid = { version = "1.13.1", features = [
|
||||||
"js",
|
"js",
|
||||||
] } # direct dep to set js feature, prevents Rng issues
|
] } # direct dep to set js feature, prevents Rng issues
|
||||||
letterbox-shared = { version = "0.1.0", registry = "xinu" }
|
letterbox-shared = { version = "0.10.8", path = "../shared", registry = "xinu" }
|
||||||
letterbox-notmuch = { version = "0.1.0", path = "../notmuch", registry = "xinu" }
|
letterbox-notmuch = { version = "0.10.8", path = "../notmuch", registry = "xinu" }
|
||||||
|
seed_hooks = { version = "0.4.0", registry = "xinu" }
|
||||||
|
strum_macros = "0.27.1"
|
||||||
|
|
||||||
[package.metadata.wasm-pack.profile.release]
|
[package.metadata.wasm-pack.profile.release]
|
||||||
wasm-opt = ['-Os']
|
wasm-opt = ['-Os']
|
||||||
@@ -49,4 +50,6 @@ features = [
|
|||||||
"MediaQueryList",
|
"MediaQueryList",
|
||||||
"Navigator",
|
"Navigator",
|
||||||
"Window",
|
"Window",
|
||||||
|
"History",
|
||||||
|
"ScrollRestoration",
|
||||||
]
|
]
|
||||||
|
|||||||
3
web/graphql/catchup.graphql
Normal file
3
web/graphql/catchup.graphql
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
query CatchupQuery($query: String!) {
|
||||||
|
catchup(query: $query)
|
||||||
|
}
|
||||||
@@ -671,6 +671,30 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"args": [],
|
||||||
|
"deprecationReason": null,
|
||||||
|
"description": null,
|
||||||
|
"isDeprecated": false,
|
||||||
|
"name": "xOriginalTo",
|
||||||
|
"type": {
|
||||||
|
"kind": "OBJECT",
|
||||||
|
"name": "Email",
|
||||||
|
"ofType": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"args": [],
|
||||||
|
"deprecationReason": null,
|
||||||
|
"description": null,
|
||||||
|
"isDeprecated": false,
|
||||||
|
"name": "deliveredTo",
|
||||||
|
"type": {
|
||||||
|
"kind": "OBJECT",
|
||||||
|
"name": "Email",
|
||||||
|
"ofType": null
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"args": [],
|
"args": [],
|
||||||
"deprecationReason": null,
|
"deprecationReason": null,
|
||||||
@@ -1268,6 +1292,45 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"args": [
|
||||||
|
{
|
||||||
|
"defaultValue": null,
|
||||||
|
"description": null,
|
||||||
|
"name": "query",
|
||||||
|
"type": {
|
||||||
|
"kind": "NON_NULL",
|
||||||
|
"name": null,
|
||||||
|
"ofType": {
|
||||||
|
"kind": "SCALAR",
|
||||||
|
"name": "String",
|
||||||
|
"ofType": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"deprecationReason": null,
|
||||||
|
"description": null,
|
||||||
|
"isDeprecated": false,
|
||||||
|
"name": "catchup",
|
||||||
|
"type": {
|
||||||
|
"kind": "NON_NULL",
|
||||||
|
"name": null,
|
||||||
|
"ofType": {
|
||||||
|
"kind": "LIST",
|
||||||
|
"name": null,
|
||||||
|
"ofType": {
|
||||||
|
"kind": "NON_NULL",
|
||||||
|
"name": null,
|
||||||
|
"ofType": {
|
||||||
|
"kind": "SCALAR",
|
||||||
|
"name": "String",
|
||||||
|
"ofType": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"args": [
|
"args": [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -31,6 +31,14 @@ query ShowThreadQuery($threadId: String!) {
|
|||||||
name
|
name
|
||||||
addr
|
addr
|
||||||
}
|
}
|
||||||
|
xOriginalTo {
|
||||||
|
name
|
||||||
|
addr
|
||||||
|
}
|
||||||
|
deliveredTo {
|
||||||
|
name
|
||||||
|
addr
|
||||||
|
}
|
||||||
timestamp
|
timestamp
|
||||||
body {
|
body {
|
||||||
__typename
|
__typename
|
||||||
|
|||||||
@@ -12,6 +12,14 @@ use serde::{de::DeserializeOwned, Serialize};
|
|||||||
)]
|
)]
|
||||||
pub struct FrontPageQuery;
|
pub struct FrontPageQuery;
|
||||||
|
|
||||||
|
#[derive(GraphQLQuery)]
|
||||||
|
#[graphql(
|
||||||
|
schema_path = "graphql/schema.json",
|
||||||
|
query_path = "graphql/catchup.graphql",
|
||||||
|
response_derives = "Debug"
|
||||||
|
)]
|
||||||
|
pub struct CatchupQuery;
|
||||||
|
|
||||||
#[derive(GraphQLQuery)]
|
#[derive(GraphQLQuery)]
|
||||||
#[graphql(
|
#[graphql(
|
||||||
schema_path = "graphql/schema.json",
|
schema_path = "graphql/schema.json",
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ fn main() {
|
|||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
console_error_panic_hook::set_once();
|
console_error_panic_hook::set_once();
|
||||||
|
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
let lvl = Level::Debug;
|
||||||
|
#[cfg(not(debug_assertions))]
|
||||||
let lvl = Level::Info;
|
let lvl = Level::Info;
|
||||||
console_log::init_with_level(lvl).expect("failed to initialize console logging");
|
console_log::init_with_level(lvl).expect("failed to initialize console logging");
|
||||||
// Mount the `app` to the element with the `id` "app".
|
// Mount the `app` to the element with the `id` "app".
|
||||||
|
|||||||
192
web/src/state.rs
192
web/src/state.rs
@@ -29,16 +29,21 @@ pub fn unread_query() -> &'static str {
|
|||||||
pub fn init(url: Url, orders: &mut impl Orders<Msg>) -> Model {
|
pub fn init(url: Url, orders: &mut impl Orders<Msg>) -> Model {
|
||||||
let version = letterbox_shared::build_version(bi);
|
let version = letterbox_shared::build_version(bi);
|
||||||
info!("Build Info: {}", version);
|
info!("Build Info: {}", version);
|
||||||
|
// Disable restoring to scroll position when navigating
|
||||||
|
window()
|
||||||
|
.history()
|
||||||
|
.expect("couldn't get history")
|
||||||
|
.set_scroll_restoration(web_sys::ScrollRestoration::Manual)
|
||||||
|
.expect("failed to set scroll restoration to manual");
|
||||||
if url.hash().is_none() {
|
if url.hash().is_none() {
|
||||||
orders.request_url(urls::search(unread_query(), 0));
|
orders.request_url(urls::search(unread_query(), 0));
|
||||||
} else {
|
} else {
|
||||||
orders.notify(subs::UrlRequested::new(url));
|
orders.request_url(url);
|
||||||
};
|
};
|
||||||
orders.stream(streams::window_event(Ev::Resize, |_| Msg::OnResize));
|
|
||||||
// TODO(wathiede): only do this while viewing the index? Or maybe add a new message that force
|
// TODO(wathiede): only do this while viewing the index? Or maybe add a new message that force
|
||||||
// 'notmuch new' on the server periodically?
|
// 'notmuch new' on the server periodically?
|
||||||
orders.stream(streams::interval(30_000, || Msg::RefreshStart));
|
orders.stream(streams::interval(30_000, || Msg::RefreshStart));
|
||||||
orders.subscribe(on_url_changed);
|
orders.subscribe(Msg::OnUrlChanged);
|
||||||
orders.stream(streams::window_event(Ev::Scroll, |_| Msg::WindowScrolled));
|
orders.stream(streams::window_event(Ev::Scroll, |_| Msg::WindowScrolled));
|
||||||
|
|
||||||
build_info::build_info!(fn bi);
|
build_info::build_info!(fn bi);
|
||||||
@@ -53,18 +58,23 @@ pub fn init(url: Url, orders: &mut impl Orders<Msg>) -> Model {
|
|||||||
client: version,
|
client: version,
|
||||||
server: None,
|
server: None,
|
||||||
},
|
},
|
||||||
|
catchup: None,
|
||||||
|
last_url: Url::current(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_url_changed(uc: subs::UrlChanged) -> Msg {
|
fn on_url_changed(old: &Url, mut new: Url) -> Msg {
|
||||||
let mut url = uc.0;
|
let did_change = *old != new;
|
||||||
|
let mut messages = Vec::new();
|
||||||
|
if did_change {
|
||||||
|
messages.push(Msg::ScrollToTop)
|
||||||
|
}
|
||||||
info!(
|
info!(
|
||||||
"url changed '{}', history {}",
|
"url changed\nold '{old}'\nnew '{new}', history {}",
|
||||||
url,
|
|
||||||
history().length().unwrap_or(0)
|
history().length().unwrap_or(0)
|
||||||
);
|
);
|
||||||
let hpp = url.remaining_hash_path_parts();
|
let hpp = new.remaining_hash_path_parts();
|
||||||
match hpp.as_slice() {
|
let msg = match hpp.as_slice() {
|
||||||
["t", tid] => Msg::ShowThreadRequest {
|
["t", tid] => Msg::ShowThreadRequest {
|
||||||
thread_id: tid.to_string(),
|
thread_id: tid.to_string(),
|
||||||
},
|
},
|
||||||
@@ -101,11 +111,14 @@ fn on_url_changed(uc: subs::UrlChanged) -> Msg {
|
|||||||
last: None,
|
last: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
messages.push(msg);
|
||||||
|
Msg::MultiMsg(messages)
|
||||||
}
|
}
|
||||||
|
|
||||||
// `update` describes how to handle each `Msg`.
|
// `update` describes how to handle each `Msg`.
|
||||||
pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||||
|
info!("update({})", msg);
|
||||||
match msg {
|
match msg {
|
||||||
Msg::Noop => {}
|
Msg::Noop => {}
|
||||||
Msg::RefreshStart => {
|
Msg::RefreshStart => {
|
||||||
@@ -131,7 +144,7 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
|||||||
orders.perform_cmd(async move { Msg::Refresh });
|
orders.perform_cmd(async move { Msg::Refresh });
|
||||||
}
|
}
|
||||||
Msg::Refresh => {
|
Msg::Refresh => {
|
||||||
orders.perform_cmd(async move { on_url_changed(subs::UrlChanged(Url::current())) });
|
orders.request_url(Url::current());
|
||||||
}
|
}
|
||||||
Msg::Reload => {
|
Msg::Reload => {
|
||||||
window()
|
window()
|
||||||
@@ -139,7 +152,10 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
|||||||
.reload()
|
.reload()
|
||||||
.expect("failed to reload window");
|
.expect("failed to reload window");
|
||||||
}
|
}
|
||||||
Msg::OnResize => (),
|
Msg::OnUrlChanged(new_url) => {
|
||||||
|
orders.send_msg(on_url_changed(&model.last_url, new_url.0.clone()));
|
||||||
|
model.last_url = new_url.0;
|
||||||
|
}
|
||||||
|
|
||||||
Msg::NextPage => {
|
Msg::NextPage => {
|
||||||
match &model.context {
|
match &model.context {
|
||||||
@@ -181,10 +197,7 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
Msg::GoToSearchResults => {
|
Msg::GoToSearchResults => {
|
||||||
let url = urls::search(&model.query, 0);
|
orders.send_msg(Msg::SearchQuery(model.query.clone()));
|
||||||
info!("GoToSearchRestuls Start");
|
|
||||||
orders.request_url(url);
|
|
||||||
info!("GoToSearchRestuls End");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Msg::UpdateQuery(query) => model.query = query,
|
Msg::UpdateQuery(query) => model.query = query,
|
||||||
@@ -279,7 +292,9 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Msg::FrontPageResult(Err(e)) => error!("error FrontPageResult: {e:?}"),
|
Msg::FrontPageResult(Err(e)) => {
|
||||||
|
error!("error FrontPageResult: {e:?}");
|
||||||
|
}
|
||||||
Msg::FrontPageResult(Ok(graphql_client::Response {
|
Msg::FrontPageResult(Ok(graphql_client::Response {
|
||||||
data: None,
|
data: None,
|
||||||
errors: None,
|
errors: None,
|
||||||
@@ -307,7 +322,6 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
|||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
);
|
);
|
||||||
info!("pager {:#?}", data.search.page_info);
|
|
||||||
let selected_threads = 'context: {
|
let selected_threads = 'context: {
|
||||||
if let Context::SearchResult {
|
if let Context::SearchResult {
|
||||||
results,
|
results,
|
||||||
@@ -390,6 +404,38 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
|||||||
Msg::ShowThreadResult(bad) => {
|
Msg::ShowThreadResult(bad) => {
|
||||||
error!("show_thread_query error: {bad:#?}");
|
error!("show_thread_query error: {bad:#?}");
|
||||||
}
|
}
|
||||||
|
Msg::CatchupRequest { query } => {
|
||||||
|
orders.perform_cmd(async move {
|
||||||
|
Msg::CatchupResult(
|
||||||
|
send_graphql::<_, graphql::catchup_query::ResponseData>(
|
||||||
|
graphql::CatchupQuery::build_query(graphql::catchup_query::Variables {
|
||||||
|
query,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.await,
|
||||||
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Msg::CatchupResult(Ok(graphql_client::Response {
|
||||||
|
data: Some(data), ..
|
||||||
|
})) => {
|
||||||
|
let items = data.catchup;
|
||||||
|
if items.is_empty() {
|
||||||
|
orders.send_msg(Msg::GoToSearchResults);
|
||||||
|
model.catchup = None;
|
||||||
|
} else {
|
||||||
|
orders.request_url(urls::thread(&items[0]));
|
||||||
|
model.catchup = Some(Catchup {
|
||||||
|
items: items
|
||||||
|
.into_iter()
|
||||||
|
.map(|id| CatchupItem { id, seen: false })
|
||||||
|
.collect(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Msg::CatchupResult(bad) => {
|
||||||
|
error!("catchup_query error: {bad:#?}");
|
||||||
|
}
|
||||||
Msg::SelectionSetNone => {
|
Msg::SelectionSetNone => {
|
||||||
if let Context::SearchResult {
|
if let Context::SearchResult {
|
||||||
selected_threads, ..
|
selected_threads, ..
|
||||||
@@ -503,8 +549,12 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
|||||||
.expect("failed to copy to clipboard");
|
.expect("failed to copy to clipboard");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Msg::ScrollToTop => {
|
||||||
|
info!("scrolling to the top");
|
||||||
|
web_sys::window().unwrap().scroll_to_with_x_and_y(0., 0.);
|
||||||
|
}
|
||||||
Msg::WindowScrolled => {
|
Msg::WindowScrolled => {
|
||||||
info!("WindowScrolled");
|
// TODO: model.content_el doesn't go to None like it should when a DOM is recreated and the refrenced element goes away
|
||||||
if let Some(el) = model.content_el.get() {
|
if let Some(el) = model.content_el.get() {
|
||||||
let ih = window()
|
let ih = window()
|
||||||
.inner_height()
|
.inner_height()
|
||||||
@@ -513,7 +563,6 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
|||||||
.value_of();
|
.value_of();
|
||||||
|
|
||||||
let r = el.get_bounding_client_rect();
|
let r = el.get_bounding_client_rect();
|
||||||
info!("r {r:?} ih {ih}");
|
|
||||||
if r.height() < ih {
|
if r.height() < ih {
|
||||||
// The whole content fits in the window, no scrollbar
|
// The whole content fits in the window, no scrollbar
|
||||||
orders.send_msg(Msg::SetProgress(0.));
|
orders.send_msg(Msg::SetProgress(0.));
|
||||||
@@ -545,7 +594,8 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
|||||||
model.read_completion_ratio = ratio;
|
model.read_completion_ratio = ratio;
|
||||||
}
|
}
|
||||||
Msg::UpdateServerVersion(version) => {
|
Msg::UpdateServerVersion(version) => {
|
||||||
if version != model.versions.client {
|
// Only git versions contain dash, don't autoreload there
|
||||||
|
if !version.contains('-') && version != model.versions.client {
|
||||||
warn!(
|
warn!(
|
||||||
"Server ({}) and client ({}) version mismatch, reloading",
|
"Server ({}) and client ({}) version mismatch, reloading",
|
||||||
version, model.versions.client
|
version, model.versions.client
|
||||||
@@ -554,8 +604,77 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
|||||||
}
|
}
|
||||||
model.versions.server = Some(version);
|
model.versions.server = Some(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Msg::CatchupStart => {
|
||||||
|
let query = if model.query.contains("is:unread") {
|
||||||
|
model.query.to_string()
|
||||||
|
} else {
|
||||||
|
format!("{} is:unread", model.query)
|
||||||
|
};
|
||||||
|
info!("starting catchup mode w/ {}", query);
|
||||||
|
orders.send_msg(Msg::ScrollToTop);
|
||||||
|
orders.send_msg(Msg::CatchupRequest { query });
|
||||||
|
}
|
||||||
|
Msg::CatchupKeepUnread => {
|
||||||
|
if let Some(thread_id) = current_thread_id(&model.context) {
|
||||||
|
orders.send_msg(Msg::SetUnread(thread_id, true));
|
||||||
|
};
|
||||||
|
orders.send_msg(Msg::CatchupNext);
|
||||||
|
}
|
||||||
|
Msg::CatchupMarkAsRead => {
|
||||||
|
if let Some(thread_id) = current_thread_id(&model.context) {
|
||||||
|
orders.send_msg(Msg::SetUnread(thread_id, false));
|
||||||
|
};
|
||||||
|
orders.send_msg(Msg::CatchupNext);
|
||||||
|
}
|
||||||
|
Msg::CatchupNext => {
|
||||||
|
orders.send_msg(Msg::ScrollToTop);
|
||||||
|
let Some(catchup) = &mut model.catchup else {
|
||||||
|
orders.send_msg(Msg::GoToSearchResults);
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let Some(idx) = catchup.items.iter().position(|i| !i.seen) else {
|
||||||
|
// All items have been seen
|
||||||
|
orders.send_msg(Msg::CatchupExit);
|
||||||
|
orders.send_msg(Msg::GoToSearchResults);
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
catchup.items[idx].seen = true;
|
||||||
|
if idx < catchup.items.len() - 1 {
|
||||||
|
// Reached last item
|
||||||
|
orders.request_url(urls::thread(&catchup.items[idx + 1].id));
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
orders.send_msg(Msg::CatchupExit);
|
||||||
|
orders.send_msg(Msg::GoToSearchResults);
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Msg::CatchupExit => {
|
||||||
|
orders.send_msg(Msg::ScrollToTop);
|
||||||
|
model.catchup = None;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn current_thread_id(context: &Context) -> Option<String> {
|
||||||
|
match context {
|
||||||
|
Context::ThreadResult {
|
||||||
|
thread:
|
||||||
|
ShowThreadQueryThread::EmailThread(ShowThreadQueryThreadOnEmailThread {
|
||||||
|
thread_id, ..
|
||||||
|
}),
|
||||||
|
..
|
||||||
|
} => Some(thread_id.clone()),
|
||||||
|
Context::ThreadResult {
|
||||||
|
thread:
|
||||||
|
ShowThreadQueryThread::NewsPost(ShowThreadQueryThreadOnNewsPost { thread_id, .. }),
|
||||||
|
..
|
||||||
|
} => Some(thread_id.clone()),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// `Model` describes our app state.
|
// `Model` describes our app state.
|
||||||
pub struct Model {
|
pub struct Model {
|
||||||
pub query: String,
|
pub query: String,
|
||||||
@@ -565,6 +684,8 @@ pub struct Model {
|
|||||||
pub read_completion_ratio: f64,
|
pub read_completion_ratio: f64,
|
||||||
pub content_el: ElRef<HtmlElement>,
|
pub content_el: ElRef<HtmlElement>,
|
||||||
pub versions: Version,
|
pub versions: Version,
|
||||||
|
pub catchup: Option<Catchup>,
|
||||||
|
pub last_url: Url,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -601,6 +722,15 @@ pub enum Context {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct Catchup {
|
||||||
|
pub items: Vec<CatchupItem>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct CatchupItem {
|
||||||
|
pub id: String,
|
||||||
|
pub seen: bool,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Tag {
|
pub struct Tag {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub bg_color: String,
|
pub bg_color: String,
|
||||||
@@ -614,14 +744,15 @@ pub enum RefreshingState {
|
|||||||
Error(String),
|
Error(String),
|
||||||
}
|
}
|
||||||
// `Msg` describes the different events you can modify state with.
|
// `Msg` describes the different events you can modify state with.
|
||||||
|
#[derive(strum_macros::Display)]
|
||||||
pub enum Msg {
|
pub enum Msg {
|
||||||
Noop,
|
Noop,
|
||||||
// Tell the client to refresh its state
|
// Tell the client to refresh its state
|
||||||
Refresh,
|
Refresh,
|
||||||
// Tell the client to reload whole page from server
|
// Tell the client to reload whole page from server
|
||||||
Reload,
|
Reload,
|
||||||
// Window has changed size
|
// TODO: add GoToUrl
|
||||||
OnResize,
|
OnUrlChanged(subs::UrlChanged),
|
||||||
// Tell the server to update state
|
// Tell the server to update state
|
||||||
RefreshStart,
|
RefreshStart,
|
||||||
RefreshDone(Option<gloo_net::Error>),
|
RefreshDone(Option<gloo_net::Error>),
|
||||||
@@ -651,10 +782,14 @@ pub enum Msg {
|
|||||||
ShowThreadResult(
|
ShowThreadResult(
|
||||||
Result<graphql_client::Response<graphql::show_thread_query::ResponseData>, gloo_net::Error>,
|
Result<graphql_client::Response<graphql::show_thread_query::ResponseData>, gloo_net::Error>,
|
||||||
),
|
),
|
||||||
|
CatchupRequest {
|
||||||
|
query: String,
|
||||||
|
},
|
||||||
|
CatchupResult(
|
||||||
|
Result<graphql_client::Response<graphql::catchup_query::ResponseData>, gloo_net::Error>,
|
||||||
|
),
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
SelectionSetNone,
|
SelectionSetNone,
|
||||||
#[allow(dead_code)]
|
|
||||||
SelectionSetAll,
|
SelectionSetAll,
|
||||||
SelectionAddTag(String),
|
SelectionAddTag(String),
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@@ -670,7 +805,14 @@ pub enum Msg {
|
|||||||
|
|
||||||
CopyToClipboard(String),
|
CopyToClipboard(String),
|
||||||
|
|
||||||
|
ScrollToTop,
|
||||||
WindowScrolled,
|
WindowScrolled,
|
||||||
SetProgress(f64),
|
SetProgress(f64),
|
||||||
UpdateServerVersion(String),
|
UpdateServerVersion(String),
|
||||||
|
|
||||||
|
CatchupStart,
|
||||||
|
CatchupKeepUnread,
|
||||||
|
CatchupMarkAsRead,
|
||||||
|
CatchupNext,
|
||||||
|
CatchupExit,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
use std::collections::HashSet;
|
use std::{cell::RefCell, cmp::Ordering, collections::HashSet};
|
||||||
|
|
||||||
use chrono::{DateTime, Datelike, Duration, Local, Utc};
|
use chrono::{DateTime, Datelike, Duration, Local, Utc};
|
||||||
use human_format::{Formatter, Scales};
|
use human_format::{Formatter, Scales};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use letterbox_shared::compute_color;
|
use letterbox_shared::compute_color;
|
||||||
use log::{debug, error, info};
|
use log::error;
|
||||||
use seed::{prelude::*, *};
|
use seed::{prelude::*, *};
|
||||||
use seed_hooks::{state_access::CloneState, topo, use_state};
|
use seed_hooks::{state_access::CloneState, topo, use_state, StateAccessEventHandlers};
|
||||||
use web_sys::HtmlElement;
|
use web_sys::{HtmlElement, HtmlInputElement};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
api::urls,
|
api::urls,
|
||||||
graphql::{front_page_query::*, show_thread_query::*},
|
graphql::{front_page_query::*, show_thread_query::*},
|
||||||
state::{unread_query, Context, Model, Msg, RefreshingState, Tag},
|
state::{unread_query, CatchupItem, Context, Model, Msg, RefreshingState, Tag, Version},
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO(wathiede): create a QueryString enum that wraps single and multiple message ids and thread
|
// TODO(wathiede): create a QueryString enum that wraps single and multiple message ids and thread
|
||||||
@@ -21,6 +21,8 @@ use crate::{
|
|||||||
const MAX_RAW_MESSAGE_SIZE: usize = 100_000;
|
const MAX_RAW_MESSAGE_SIZE: usize = 100_000;
|
||||||
|
|
||||||
mod tw_classes {
|
mod tw_classes {
|
||||||
|
use seed::{prelude::*, *};
|
||||||
|
|
||||||
pub const TAG: &[&str] = &[
|
pub const TAG: &[&str] = &[
|
||||||
"rounded-md",
|
"rounded-md",
|
||||||
"px-2",
|
"px-2",
|
||||||
@@ -37,22 +39,30 @@ mod tw_classes {
|
|||||||
"text-xs",
|
"text-xs",
|
||||||
"[text-shadow:_0_1px_0_rgb(0_0_0_/_40%)]",
|
"[text-shadow:_0_1px_0_rgb(0_0_0_/_40%)]",
|
||||||
];
|
];
|
||||||
pub const BUTTON: &[&str] = &[
|
|
||||||
"bg-neutral-900",
|
// TODO: should this be a builder pattern?
|
||||||
"rounded-md",
|
pub fn button() -> seed::Attrs {
|
||||||
"p-2",
|
button_with_color("bg-neutral-900", "hover:bg-neutral-700")
|
||||||
"border",
|
}
|
||||||
"border-neutral-700",
|
|
||||||
"text-center",
|
pub fn button_with_color<T: ToClasses>(bg: T, hover: T) -> seed::Attrs {
|
||||||
"text-sm",
|
C![
|
||||||
"transition-all",
|
"rounded-md",
|
||||||
"shadow-md",
|
"p-2",
|
||||||
"hover:shadow-lg",
|
"border",
|
||||||
"hover:bg-neutral-700",
|
"border-neutral-700",
|
||||||
"disabled:pointer-events-none",
|
"text-center",
|
||||||
"disabled:opacity-50",
|
"text-sm",
|
||||||
"disabled:shadow-none",
|
"transition-all",
|
||||||
];
|
"shadow-md",
|
||||||
|
"hover:shadow-lg",
|
||||||
|
"disabled:pointer-events-none",
|
||||||
|
"disabled:opacity-50",
|
||||||
|
"disabled:shadow-none",
|
||||||
|
bg,
|
||||||
|
hover,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
pub const CHECKBOX: &[&str] = &[
|
pub const CHECKBOX: &[&str] = &[
|
||||||
"w-8",
|
"w-8",
|
||||||
@@ -60,6 +70,7 @@ mod tw_classes {
|
|||||||
"accent-green-600",
|
"accent-green-600",
|
||||||
"appearance-none",
|
"appearance-none",
|
||||||
"checked:appearance-auto",
|
"checked:appearance-auto",
|
||||||
|
"indeterminate:appearance-auto",
|
||||||
"rounded",
|
"rounded",
|
||||||
"border",
|
"border",
|
||||||
"border-neutral-500",
|
"border-neutral-500",
|
||||||
@@ -67,24 +78,82 @@ mod tw_classes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(model: &Model) -> Node<Msg> {
|
pub fn view(model: &Model) -> Node<Msg> {
|
||||||
let content = match &model.context {
|
match &model.context {
|
||||||
Context::None => div![h1!["Loading"]],
|
Context::None => normal_view(
|
||||||
|
div![h1!["Loading"]],
|
||||||
|
&model.versions,
|
||||||
|
&model.query,
|
||||||
|
&model.refreshing_state,
|
||||||
|
model.read_completion_ratio,
|
||||||
|
&model.tags,
|
||||||
|
),
|
||||||
Context::ThreadResult {
|
Context::ThreadResult {
|
||||||
thread: ShowThreadQueryThread::EmailThread(thread_data),
|
thread: ShowThreadQueryThread::EmailThread(thread_data),
|
||||||
open_messages,
|
open_messages,
|
||||||
} => thread(thread_data, open_messages, &model.content_el),
|
} => {
|
||||||
|
if let Some(catchup) = &model.catchup {
|
||||||
|
catchup_view(
|
||||||
|
thread(thread_data, open_messages, &model.content_el, true),
|
||||||
|
&catchup.items,
|
||||||
|
model.read_completion_ratio,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
normal_view(
|
||||||
|
thread(thread_data, open_messages, &model.content_el, false),
|
||||||
|
&model.versions,
|
||||||
|
&model.query,
|
||||||
|
&model.refreshing_state,
|
||||||
|
model.read_completion_ratio,
|
||||||
|
&model.tags,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Context::ThreadResult {
|
Context::ThreadResult {
|
||||||
thread: ShowThreadQueryThread::NewsPost(post),
|
thread: ShowThreadQueryThread::NewsPost(post),
|
||||||
..
|
..
|
||||||
} => news_post(post, &model.content_el),
|
} => {
|
||||||
|
if let Some(catchup) = &model.catchup {
|
||||||
|
catchup_view(
|
||||||
|
news_post(post, &model.content_el, true),
|
||||||
|
&catchup.items,
|
||||||
|
model.read_completion_ratio,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
normal_view(
|
||||||
|
news_post(post, &model.content_el, false),
|
||||||
|
&model.versions,
|
||||||
|
&model.query,
|
||||||
|
&model.refreshing_state,
|
||||||
|
model.read_completion_ratio,
|
||||||
|
&model.tags,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Context::SearchResult {
|
Context::SearchResult {
|
||||||
query,
|
query,
|
||||||
results,
|
results,
|
||||||
count,
|
count,
|
||||||
pager,
|
pager,
|
||||||
selected_threads,
|
selected_threads,
|
||||||
} => search_results(&query, results.as_slice(), *count, pager, selected_threads),
|
} => normal_view(
|
||||||
};
|
search_results(&query, results.as_slice(), *count, pager, selected_threads),
|
||||||
|
&model.versions,
|
||||||
|
&model.query,
|
||||||
|
&model.refreshing_state,
|
||||||
|
model.read_completion_ratio,
|
||||||
|
&model.tags,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn normal_view(
|
||||||
|
content: Node<Msg>,
|
||||||
|
versions: &Version,
|
||||||
|
query: &str,
|
||||||
|
refreshing_state: &RefreshingState,
|
||||||
|
read_completion_ratio: f64,
|
||||||
|
tags: &Option<Vec<Tag>>,
|
||||||
|
) -> Node<Msg> {
|
||||||
div![
|
div![
|
||||||
C![
|
C![
|
||||||
"relative",
|
"relative",
|
||||||
@@ -95,21 +164,90 @@ pub fn view(model: &Model) -> Node<Msg> {
|
|||||||
"lg:flex-nowrap",
|
"lg:flex-nowrap",
|
||||||
"w-full"
|
"w-full"
|
||||||
],
|
],
|
||||||
reading_progress(model.read_completion_ratio),
|
|
||||||
div![
|
div![
|
||||||
C!["w-full", "lg:w-48", "flex-none", "flex", "flex-col"],
|
C!["w-full", "lg:w-48", "flex-none", "flex", "flex-col"],
|
||||||
tags(model),
|
view_tags(tags),
|
||||||
versions(&model.versions)
|
view_versions(&versions)
|
||||||
],
|
],
|
||||||
div![
|
div![
|
||||||
// TODO: This "overflow-hidden" is a hack because I can't figure out
|
// TODO: This "overflow-hidden" is a hack because I can't figure out
|
||||||
// how to prevent the search input box on mobile for growing it's
|
// how to prevent the search input box on mobile for growing it's
|
||||||
// parent wider
|
// parent wider
|
||||||
C!["flex-auto", "flex", "flex-col", "overflow-hidden"],
|
C!["flex-auto", "flex", "flex-col", "overflow-hidden"],
|
||||||
view_header(&model.query, &model.refreshing_state, true),
|
view_header(query, refreshing_state, true),
|
||||||
content,
|
content,
|
||||||
view_header(&model.query, &model.refreshing_state, false),
|
view_header(query, refreshing_state, false),
|
||||||
]
|
],
|
||||||
|
reading_progress(read_completion_ratio),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn catchup_view(
|
||||||
|
content: Node<Msg>,
|
||||||
|
items: &[CatchupItem],
|
||||||
|
read_completion_ratio: f64,
|
||||||
|
) -> Node<Msg> {
|
||||||
|
div![
|
||||||
|
C!["w-full", "relative", "text-white"],
|
||||||
|
div![
|
||||||
|
C![
|
||||||
|
"fixed",
|
||||||
|
"top-0",
|
||||||
|
"right-0",
|
||||||
|
"left-0",
|
||||||
|
"p-4",
|
||||||
|
"border-b",
|
||||||
|
"border-gray-500",
|
||||||
|
"bg-black/50",
|
||||||
|
],
|
||||||
|
div![
|
||||||
|
C!["absolute", "top-0", "right-4", "text-gray-500", "p-4"],
|
||||||
|
span![i![C!["fas", "fa-x"]]],
|
||||||
|
ev(Ev::Click, move |_| Msg::CatchupExit)
|
||||||
|
],
|
||||||
|
h1![
|
||||||
|
C!["text-center"],
|
||||||
|
format!("{} left ", items.iter().filter(|i| !i.seen).count(),)
|
||||||
|
]
|
||||||
|
],
|
||||||
|
div![C!["mt-12", "mb-20"], content],
|
||||||
|
div![
|
||||||
|
C![
|
||||||
|
"fixed",
|
||||||
|
"bottom-0",
|
||||||
|
"left-0",
|
||||||
|
"right-0",
|
||||||
|
"flex",
|
||||||
|
"justify-center",
|
||||||
|
"gap-4",
|
||||||
|
"p-4",
|
||||||
|
"border-t",
|
||||||
|
"border-gray-500",
|
||||||
|
"bg-black/50",
|
||||||
|
],
|
||||||
|
button![
|
||||||
|
tw_classes::button(),
|
||||||
|
span![i![C!["far", "fa-envelope"]]],
|
||||||
|
span![C!["pl-2"], "Keep unread"],
|
||||||
|
ev(Ev::Click, |_| Msg::CatchupKeepUnread)
|
||||||
|
],
|
||||||
|
button![
|
||||||
|
tw_classes::button(),
|
||||||
|
span![i![C!["fas", "fa-house"]]],
|
||||||
|
span![C!["pl-2"], "Go home"],
|
||||||
|
ev(Ev::Click, |_| Msg::MultiMsg(vec![
|
||||||
|
Msg::CatchupExit,
|
||||||
|
Msg::GoToSearchResults
|
||||||
|
]))
|
||||||
|
],
|
||||||
|
button![
|
||||||
|
tw_classes::button_with_color("bg-green-800", "hover:bg-green-700"),
|
||||||
|
span![i![C!["far", "fa-envelope-open"]]],
|
||||||
|
span![C!["pl-2"], "Mark as read"],
|
||||||
|
ev(Ev::Click, |_| Msg::CatchupMarkAsRead)
|
||||||
|
]
|
||||||
|
],
|
||||||
|
reading_progress(read_completion_ratio)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +273,6 @@ fn search_results(
|
|||||||
tags.remove(idx);
|
tags.remove(idx);
|
||||||
};
|
};
|
||||||
let is_unread = unread_idx.is_some();
|
let is_unread = unread_idx.is_some();
|
||||||
// TODO: add check-all button, and tristate indicator
|
|
||||||
div![
|
div![
|
||||||
C![
|
C![
|
||||||
"flex",
|
"flex",
|
||||||
@@ -189,11 +326,12 @@ fn search_results(
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
let show_bulk_edit = !selected_threads.is_empty();
|
let show_bulk_edit = !selected_threads.is_empty();
|
||||||
|
let all_selected = selected_threads.len() == results.len();
|
||||||
div![
|
div![
|
||||||
C!["flex", "flex-col", "flex-auto", "p-4"],
|
C!["flex", "flex-col", "flex-auto", "p-4"],
|
||||||
search_toolbar(count, pager, show_bulk_edit),
|
search_toolbar(count, pager, show_bulk_edit, all_selected),
|
||||||
div![rows],
|
div![rows],
|
||||||
search_toolbar(count, pager, show_bulk_edit),
|
search_toolbar(count, pager, show_bulk_edit, all_selected),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,59 +448,92 @@ fn human_age(timestamp: i64) -> String {
|
|||||||
datetime
|
datetime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[topo::nested]
|
||||||
fn search_toolbar(
|
fn search_toolbar(
|
||||||
count: usize,
|
count: usize,
|
||||||
pager: &FrontPageQuerySearchPageInfo,
|
pager: &FrontPageQuerySearchPageInfo,
|
||||||
show_bulk_edit: bool,
|
show_bulk_edit: bool,
|
||||||
|
all_selected: bool,
|
||||||
) -> Node<Msg> {
|
) -> Node<Msg> {
|
||||||
|
let indeterminate = show_bulk_edit && !all_selected;
|
||||||
|
let tristate_el: ElRef<HtmlInputElement> = use_state(|| Default::default()).get();
|
||||||
|
let tri = el_ref(&tristate_el);
|
||||||
|
if let Some(tri) = tri.get() {
|
||||||
|
tri.set_indeterminate(indeterminate);
|
||||||
|
}
|
||||||
nav![
|
nav![
|
||||||
C!["p-4", "flex", "w-full", "justify-between"],
|
C!["py-4", "flex", "w-full", "justify-between"],
|
||||||
div![
|
div![
|
||||||
C!["gap-2", "flex"],
|
C!["gap-2", "flex", IF!(show_bulk_edit => "hidden")],
|
||||||
IF!(show_bulk_edit =>
|
div![button![
|
||||||
|
tw_classes::button(),
|
||||||
|
attrs! {At::Title => "Mark as read"},
|
||||||
|
span![i![C!["far", "fa-eye"]]],
|
||||||
|
span![C!["pl-2", "hidden", "md:inline"], "Catch-up"],
|
||||||
|
ev(Ev::Click, |_| Msg::CatchupStart)
|
||||||
|
]],
|
||||||
|
],
|
||||||
|
div![
|
||||||
|
C!["gap-2", "flex", IF!(!show_bulk_edit => "hidden")],
|
||||||
div![
|
div![
|
||||||
button![
|
C!["flex", "items-center", "mr-4"],
|
||||||
C![&tw_classes::BUTTON, "rounded-r-none"],
|
input![
|
||||||
attrs!{At::Title => "Mark as read"},
|
tri,
|
||||||
span![i![C!["far", "fa-envelope-open"]]],
|
C![&tw_classes::CHECKBOX],
|
||||||
span![C!["pl-2", "hidden", "md:inline"], "Read"],
|
attrs! {
|
||||||
ev(Ev::Click, |_| Msg::SelectionMarkAsRead)
|
At::Type=>"checkbox",
|
||||||
],
|
At::Checked=>all_selected,
|
||||||
button![
|
}
|
||||||
C![&tw_classes::BUTTON, "rounded-l-none"],
|
],
|
||||||
attrs!{At::Title => "Mark as unread"},
|
ev(Ev::Input, move |_| {
|
||||||
span![i![C!["far", "fa-envelope"]]],
|
if all_selected {
|
||||||
span![C!["pl-2", "hidden", "md:inline"], "Unread"],
|
Msg::SelectionSetNone
|
||||||
ev(Ev::Click, |_| Msg::SelectionMarkAsUnread)
|
} else {
|
||||||
]
|
Msg::SelectionSetAll
|
||||||
]),
|
}
|
||||||
IF!(show_bulk_edit =>
|
}),
|
||||||
|
],
|
||||||
div![
|
div![
|
||||||
button![
|
button![
|
||||||
C![&tw_classes::BUTTON, "text-red-500"],
|
tw_classes::button(),
|
||||||
attrs!{At::Title => "Mark as spam"},
|
C!["rounded-r-none"],
|
||||||
span![i![C!["far", "fa-hand"]]],
|
attrs! {At::Title => "Mark as read"},
|
||||||
span![C!["pl-2", "hidden", "md:inline"], "Spam"],
|
span![i![C!["far", "fa-envelope-open"]]],
|
||||||
ev(Ev::Click, |_|
|
span![C!["pl-2", "hidden", "md:inline"], "Read"],
|
||||||
Msg::MultiMsg(vec![
|
ev(Ev::Click, |_| Msg::SelectionMarkAsRead)
|
||||||
Msg::SelectionAddTag("Spam".to_string()),
|
],
|
||||||
Msg::SelectionMarkAsRead
|
button![
|
||||||
])
|
tw_classes::button(),
|
||||||
)
|
C!["rounded-l-none"],
|
||||||
|
attrs! {At::Title => "Mark as unread"},
|
||||||
|
span![i![C!["far", "fa-envelope"]]],
|
||||||
|
span![C!["pl-2", "hidden", "md:inline"], "Unread"],
|
||||||
|
ev(Ev::Click, |_| Msg::SelectionMarkAsUnread)
|
||||||
]
|
]
|
||||||
]),
|
],
|
||||||
|
div![button![
|
||||||
|
tw_classes::button(),
|
||||||
|
C!["text-red-500"],
|
||||||
|
attrs! {At::Title => "Mark as spam"},
|
||||||
|
span![i![C!["far", "fa-hand"]]],
|
||||||
|
span![C!["pl-2", "hidden", "md:inline"], "Spam"],
|
||||||
|
ev(Ev::Click, |_| Msg::MultiMsg(vec![
|
||||||
|
Msg::SelectionAddTag("Spam".to_string()),
|
||||||
|
Msg::SelectionMarkAsRead
|
||||||
|
]))
|
||||||
|
]],
|
||||||
],
|
],
|
||||||
div![
|
div![
|
||||||
C!["flex", "gap-2", "items-center"],
|
C!["flex", "gap-2", "items-center"],
|
||||||
p![format!("{count} results")],
|
p![format!("{count} results")],
|
||||||
button![
|
button![
|
||||||
C![&tw_classes::BUTTON],
|
tw_classes::button(),
|
||||||
IF!(!pager.has_previous_page => attrs!{ At::Disabled=>true }),
|
IF!(!pager.has_previous_page => attrs!{ At::Disabled=>true }),
|
||||||
"<",
|
"<",
|
||||||
IF!(pager.has_previous_page => ev(Ev::Click, |_| Msg::PreviousPage)),
|
IF!(pager.has_previous_page => ev(Ev::Click, |_| Msg::PreviousPage)),
|
||||||
],
|
],
|
||||||
button![
|
button![
|
||||||
C![&tw_classes::BUTTON],
|
tw_classes::button(),
|
||||||
IF!(!pager.has_next_page => attrs!{ At::Disabled=>true }),
|
IF!(!pager.has_next_page => attrs!{ At::Disabled=>true }),
|
||||||
">",
|
">",
|
||||||
IF!(pager.has_next_page => ev(Ev::Click, |_| Msg::NextPage))
|
IF!(pager.has_next_page => ev(Ev::Click, |_| Msg::NextPage))
|
||||||
@@ -459,6 +630,53 @@ fn render_open_header(msg: &ShowThreadQueryThreadOnEmailThreadMessages) -> Node<
|
|||||||
let is_unread = has_unread(&msg.tags);
|
let is_unread = has_unread(&msg.tags);
|
||||||
let avatar = render_avatar(photo_url, &from, true);
|
let avatar = render_avatar(photo_url, &from, true);
|
||||||
let unknown = "UNKNOWN".to_string();
|
let unknown = "UNKNOWN".to_string();
|
||||||
|
let to_xinu = RefCell::new(false);
|
||||||
|
let to_addrs: Vec<_> = msg
|
||||||
|
.to
|
||||||
|
.iter()
|
||||||
|
.map(|to| {
|
||||||
|
let ShowThreadQueryThreadOnEmailThreadMessagesTo { name, addr } = to;
|
||||||
|
span![
|
||||||
|
addr.as_ref().map(|addr| {
|
||||||
|
if addr.ends_with("xinu.tv") {
|
||||||
|
*to_xinu.borrow_mut() = true;
|
||||||
|
}
|
||||||
|
attrs! {
|
||||||
|
At::Title => addr
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
name.as_ref()
|
||||||
|
.unwrap_or_else(|| addr.as_ref().unwrap_or(&unknown)),
|
||||||
|
" ",
|
||||||
|
addr.as_ref().map(|addr| copy_text_widget(&addr)),
|
||||||
|
" "
|
||||||
|
]
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
let cc_addrs: Vec<_> = msg
|
||||||
|
.cc
|
||||||
|
.iter()
|
||||||
|
.map(|cc| {
|
||||||
|
let ShowThreadQueryThreadOnEmailThreadMessagesCc { name, addr } = cc;
|
||||||
|
span![
|
||||||
|
addr.as_ref().map(|addr| {
|
||||||
|
if addr.ends_with("xinu.tv") {
|
||||||
|
*to_xinu.borrow_mut() = true;
|
||||||
|
}
|
||||||
|
attrs! {
|
||||||
|
At::Title => addr
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
name.as_ref()
|
||||||
|
.unwrap_or_else(|| addr.as_ref().unwrap_or(&unknown)),
|
||||||
|
" ",
|
||||||
|
addr.as_ref().map(|addr| copy_text_widget(&addr)),
|
||||||
|
" "
|
||||||
|
]
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
let show_x_original_to = !*to_xinu.borrow() && msg.x_original_to.is_some();
|
||||||
|
let show_delivered_to = !*to_xinu.borrow() && !show_x_original_to && msg.delivered_to.is_some();
|
||||||
div![
|
div![
|
||||||
C!["flex", "p-4", "bg-neutral-800"],
|
C!["flex", "p-4", "bg-neutral-800"],
|
||||||
div![avatar],
|
div![avatar],
|
||||||
@@ -480,8 +698,28 @@ fn render_open_header(msg: &ShowThreadQueryThreadOnEmailThreadMessages) -> Node<
|
|||||||
"To: "
|
"To: "
|
||||||
],
|
],
|
||||||
span![
|
span![
|
||||||
msg.to.iter().map(|to| {
|
to_addrs
|
||||||
let ShowThreadQueryThreadOnEmailThreadMessagesTo { name, addr } = to;
|
]
|
||||||
|
]),
|
||||||
|
IF!(!msg.cc.is_empty() =>div![
|
||||||
|
C!["text-xs"],
|
||||||
|
span![
|
||||||
|
C!["font-semibold"],
|
||||||
|
"CC: "
|
||||||
|
],
|
||||||
|
span![
|
||||||
|
cc_addrs
|
||||||
|
]
|
||||||
|
]),
|
||||||
|
IF!(show_x_original_to => div![
|
||||||
|
C!["text-xs"],
|
||||||
|
span![
|
||||||
|
C!["font-semibold"],
|
||||||
|
"Original To: "
|
||||||
|
],
|
||||||
|
span![
|
||||||
|
msg.x_original_to.as_ref().map(|to| {
|
||||||
|
let ShowThreadQueryThreadOnEmailThreadMessagesXOriginalTo { name, addr } = to;
|
||||||
span![
|
span![
|
||||||
addr.as_ref().map(|addr| attrs! {
|
addr.as_ref().map(|addr| attrs! {
|
||||||
At::Title => addr
|
At::Title => addr
|
||||||
@@ -494,15 +732,15 @@ fn render_open_header(msg: &ShowThreadQueryThreadOnEmailThreadMessages) -> Node<
|
|||||||
})
|
})
|
||||||
]
|
]
|
||||||
]),
|
]),
|
||||||
IF!(!msg.cc.is_empty() =>div![
|
IF!(show_delivered_to => div![
|
||||||
C!["text-xs"],
|
C!["text-xs"],
|
||||||
span![
|
span![
|
||||||
C!["font-semibold"],
|
C!["font-semibold"],
|
||||||
"CC: "
|
"Delivered To: "
|
||||||
],
|
],
|
||||||
span![
|
span![
|
||||||
msg.cc.iter().map(|cc| {
|
msg.delivered_to.as_ref().map(|to| {
|
||||||
let ShowThreadQueryThreadOnEmailThreadMessagesCc { name, addr } = cc;
|
let ShowThreadQueryThreadOnEmailThreadMessagesDeliveredTo { name, addr } = to;
|
||||||
span![
|
span![
|
||||||
addr.as_ref().map(|addr| attrs! {
|
addr.as_ref().map(|addr| attrs! {
|
||||||
At::Title => addr
|
At::Title => addr
|
||||||
@@ -556,6 +794,51 @@ fn render_closed_header(msg: &ShowThreadQueryThreadOnEmailThreadMessages) -> Nod
|
|||||||
let is_unread = has_unread(&msg.tags);
|
let is_unread = has_unread(&msg.tags);
|
||||||
let avatar = render_avatar(photo_url, &from, false);
|
let avatar = render_avatar(photo_url, &from, false);
|
||||||
let unknown = "UNKNOWN".to_string();
|
let unknown = "UNKNOWN".to_string();
|
||||||
|
let to_xinu = RefCell::new(false);
|
||||||
|
let to_addrs: Vec<_> = msg
|
||||||
|
.to
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(i, to)| {
|
||||||
|
let ShowThreadQueryThreadOnEmailThreadMessagesTo { name, addr } = to;
|
||||||
|
span![
|
||||||
|
addr.as_ref().map(|addr| {
|
||||||
|
if addr.ends_with("xinu.tv") {
|
||||||
|
*to_xinu.borrow_mut() = true;
|
||||||
|
}
|
||||||
|
attrs! {
|
||||||
|
At::Title => addr
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
if i > 0 { ", " } else { "" },
|
||||||
|
name.as_ref()
|
||||||
|
.unwrap_or_else(|| addr.as_ref().unwrap_or(&unknown))
|
||||||
|
]
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
let cc_addrs: Vec<_> = msg
|
||||||
|
.cc
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(i, cc)| {
|
||||||
|
let ShowThreadQueryThreadOnEmailThreadMessagesCc { name, addr } = cc;
|
||||||
|
span![
|
||||||
|
addr.as_ref().map(|addr| {
|
||||||
|
if addr.ends_with("xinu.tv") {
|
||||||
|
*to_xinu.borrow_mut() = true;
|
||||||
|
}
|
||||||
|
attrs! {
|
||||||
|
At::Title => addr
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
if i > 0 { ", " } else { "" },
|
||||||
|
name.as_ref()
|
||||||
|
.unwrap_or_else(|| addr.as_ref().unwrap_or(&unknown))
|
||||||
|
]
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
let show_x_original_to = !*to_xinu.borrow() && msg.x_original_to.is_some();
|
||||||
|
let show_delivered_to = !*to_xinu.borrow() && !show_x_original_to && msg.delivered_to.is_some();
|
||||||
div![
|
div![
|
||||||
C!["flex", "p-4", "bg-neutral-800"],
|
C!["flex", "p-4", "bg-neutral-800"],
|
||||||
div![avatar],
|
div![avatar],
|
||||||
@@ -576,16 +859,7 @@ fn render_closed_header(msg: &ShowThreadQueryThreadOnEmailThreadMessages) -> Nod
|
|||||||
"To: "
|
"To: "
|
||||||
],
|
],
|
||||||
span![
|
span![
|
||||||
msg.to.iter().enumerate().map(|(i, to)| {
|
to_addrs
|
||||||
let ShowThreadQueryThreadOnEmailThreadMessagesTo { name, addr } = to;
|
|
||||||
span![
|
|
||||||
addr.as_ref().map(|addr| attrs! {
|
|
||||||
At::Title => addr
|
|
||||||
}),
|
|
||||||
if i > 0 { ", " } else { "" },
|
|
||||||
name.as_ref().unwrap_or_else(|| addr.as_ref().unwrap_or(&unknown))
|
|
||||||
]
|
|
||||||
})
|
|
||||||
],
|
],
|
||||||
" "
|
" "
|
||||||
]),
|
]),
|
||||||
@@ -595,17 +869,46 @@ fn render_closed_header(msg: &ShowThreadQueryThreadOnEmailThreadMessages) -> Nod
|
|||||||
C!["font-semibold"],
|
C!["font-semibold"],
|
||||||
"CC: "
|
"CC: "
|
||||||
],
|
],
|
||||||
msg.cc.iter().enumerate().map(|(i,cc)| {
|
cc_addrs
|
||||||
let ShowThreadQueryThreadOnEmailThreadMessagesCc { name, addr } = cc;
|
]),
|
||||||
span![
|
IF!(show_x_original_to => div![
|
||||||
addr.as_ref().map(|addr| attrs! {
|
C!["text-xs"],
|
||||||
At::Title => addr
|
span![
|
||||||
}),
|
C!["font-semibold"],
|
||||||
if i > 0 { ", " } else { "" },
|
"Original To: "
|
||||||
name.as_ref().unwrap_or_else(|| addr.as_ref().unwrap_or(&unknown))
|
],
|
||||||
]
|
span![
|
||||||
})
|
msg.x_original_to.as_ref().map(|to| {
|
||||||
])
|
let ShowThreadQueryThreadOnEmailThreadMessagesXOriginalTo { name, addr } = to;
|
||||||
|
span![
|
||||||
|
addr.as_ref().map(|addr| attrs! {
|
||||||
|
At::Title => addr
|
||||||
|
}),
|
||||||
|
name.as_ref().unwrap_or_else(|| addr.as_ref().unwrap_or(&unknown)),
|
||||||
|
" ",
|
||||||
|
]
|
||||||
|
})
|
||||||
|
]
|
||||||
|
]),
|
||||||
|
IF!(show_delivered_to => div![
|
||||||
|
C!["text-xs"],
|
||||||
|
span![
|
||||||
|
C!["font-semibold"],
|
||||||
|
"Delivered To: "
|
||||||
|
],
|
||||||
|
span![
|
||||||
|
msg.delivered_to.as_ref().map(|to| {
|
||||||
|
let ShowThreadQueryThreadOnEmailThreadMessagesDeliveredTo { name, addr } = to;
|
||||||
|
span![
|
||||||
|
addr.as_ref().map(|addr| attrs! {
|
||||||
|
At::Title => addr
|
||||||
|
}),
|
||||||
|
name.as_ref().unwrap_or_else(|| addr.as_ref().unwrap_or(&unknown)),
|
||||||
|
" ",
|
||||||
|
]
|
||||||
|
})
|
||||||
|
]
|
||||||
|
]),
|
||||||
],
|
],
|
||||||
span![
|
span![
|
||||||
C!["text-right"],
|
C!["text-right"],
|
||||||
@@ -631,6 +934,13 @@ fn render_closed_header(msg: &ShowThreadQueryThreadOnEmailThreadMessages) -> Nod
|
|||||||
|
|
||||||
fn message_render(msg: &ShowThreadQueryThreadOnEmailThreadMessages, open: bool) -> Node<Msg> {
|
fn message_render(msg: &ShowThreadQueryThreadOnEmailThreadMessages, open: bool) -> Node<Msg> {
|
||||||
let expand_id = msg.id.clone();
|
let expand_id = msg.id.clone();
|
||||||
|
let from = match &msg.from {
|
||||||
|
Some(ShowThreadQueryThreadOnEmailThreadMessagesFrom {
|
||||||
|
addr: Some(addr), ..
|
||||||
|
}) => Some(addr.to_string()),
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
let from = from.map(|f| f.replace('.', "-").replace('@', "-"));
|
||||||
div![
|
div![
|
||||||
C!["lg:mb-4"],
|
C!["lg:mb-4"],
|
||||||
div![
|
div![
|
||||||
@@ -650,7 +960,7 @@ fn message_render(msg: &ShowThreadQueryThreadOnEmailThreadMessages, open: bool)
|
|||||||
],
|
],
|
||||||
IF!(open =>
|
IF!(open =>
|
||||||
div![
|
div![
|
||||||
C!["bg-white", "text-black", "p-4", "min-w-full", "w-0","overflow-x-auto"],
|
C!["bg-white", "text-black", "p-4", "min-w-full", "w-0","overflow-x-auto", from],
|
||||||
match &msg.body {
|
match &msg.body {
|
||||||
ShowThreadQueryThreadOnEmailThreadMessagesBody::UnhandledContentType(
|
ShowThreadQueryThreadOnEmailThreadMessagesBody::UnhandledContentType(
|
||||||
ShowThreadQueryThreadOnEmailThreadMessagesBodyOnUnhandledContentType { contents ,content_tree},
|
ShowThreadQueryThreadOnEmailThreadMessagesBodyOnUnhandledContentType { contents ,content_tree},
|
||||||
@@ -754,11 +1064,13 @@ fn render_attachements(
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: add cathup_mode:bool and hide elements when true
|
||||||
#[topo::nested]
|
#[topo::nested]
|
||||||
fn thread(
|
fn thread(
|
||||||
thread: &ShowThreadQueryThreadOnEmailThread,
|
thread: &ShowThreadQueryThreadOnEmailThread,
|
||||||
open_messages: &HashSet<String>,
|
open_messages: &HashSet<String>,
|
||||||
content_el: &ElRef<HtmlElement>,
|
content_el: &ElRef<HtmlElement>,
|
||||||
|
catchup_mode: bool,
|
||||||
) -> Node<Msg> {
|
) -> Node<Msg> {
|
||||||
// TODO(wathiede): show per-message subject if it changes significantly from top-level subject
|
// TODO(wathiede): show per-message subject if it changes significantly from top-level subject
|
||||||
let subject = if thread.subject.is_empty() {
|
let subject = if thread.subject.is_empty() {
|
||||||
@@ -786,16 +1098,17 @@ fn thread(
|
|||||||
let spam_add_thread_id = thread.thread_id.clone();
|
let spam_add_thread_id = thread.thread_id.clone();
|
||||||
let spam_unread_thread_id = thread.thread_id.clone();
|
let spam_unread_thread_id = thread.thread_id.clone();
|
||||||
div![
|
div![
|
||||||
C!["lg:p-4"],
|
C!["lg:p-4", "max-w-4xl"],
|
||||||
div![
|
div![
|
||||||
C!["p-4", "lg:p-0"],
|
C!["p-4", "lg:p-0"],
|
||||||
h3![C!["text-xl"], subject],
|
h3![C!["text-xl"], subject],
|
||||||
span![removable_tags_chiclet(&thread.thread_id, &tags)],
|
span![removable_tags_chiclet(&thread.thread_id, &tags)],
|
||||||
div![
|
IF!(!catchup_mode => div![
|
||||||
C!["pt-4", "gap-2", "flex", "justify-around"],
|
C!["pt-4", "gap-2", "flex", "justify-around"],
|
||||||
div![
|
div![
|
||||||
button![
|
button![
|
||||||
C![&tw_classes::BUTTON, "rounded-r-none"],
|
tw_classes::button(),
|
||||||
|
C!["rounded-r-none"],
|
||||||
attrs! {At::Title => "Mark as read"},
|
attrs! {At::Title => "Mark as read"},
|
||||||
span![i![C!["far", "fa-envelope-open"]]],
|
span![i![C!["far", "fa-envelope-open"]]],
|
||||||
span![C!["pl-2"], "Read"],
|
span![C!["pl-2"], "Read"],
|
||||||
@@ -805,7 +1118,8 @@ fn thread(
|
|||||||
])),
|
])),
|
||||||
],
|
],
|
||||||
button![
|
button![
|
||||||
C![&tw_classes::BUTTON, "rounded-l-none"],
|
tw_classes::button(),
|
||||||
|
C!["rounded-l-none"],
|
||||||
attrs! {At::Title => "Mark as unread"},
|
attrs! {At::Title => "Mark as unread"},
|
||||||
span![i![C!["far", "fa-envelope"]]],
|
span![i![C!["far", "fa-envelope"]]],
|
||||||
span![C!["pl-2"], "Unread"],
|
span![C!["pl-2"], "Unread"],
|
||||||
@@ -816,7 +1130,8 @@ fn thread(
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
div![button![
|
div![button![
|
||||||
C![&tw_classes::BUTTON, "text-red-500"],
|
tw_classes::button(),
|
||||||
|
C!["text-red-500"],
|
||||||
attrs! {At::Title => "Spam"},
|
attrs! {At::Title => "Spam"},
|
||||||
span![i![C!["far", "fa-hand"]]],
|
span![i![C!["far", "fa-hand"]]],
|
||||||
span![C!["pl-2"], "Spam"],
|
span![C!["pl-2"], "Spam"],
|
||||||
@@ -826,13 +1141,13 @@ fn thread(
|
|||||||
Msg::GoToSearchResults
|
Msg::GoToSearchResults
|
||||||
])),
|
])),
|
||||||
]]
|
]]
|
||||||
],
|
]),
|
||||||
],
|
],
|
||||||
div![
|
div![
|
||||||
C!["lg:mt-4", "mail-thread"],
|
C!["lg:mt-4", "mail-thread"],
|
||||||
el_ref(content_el),
|
el_ref(content_el),
|
||||||
messages,
|
messages,
|
||||||
click_to_top()
|
IF!(!catchup_mode => click_to_top())
|
||||||
],
|
],
|
||||||
/* TODO(wathiede): plumb in orignal id
|
/* TODO(wathiede): plumb in orignal id
|
||||||
a![
|
a![
|
||||||
@@ -857,9 +1172,7 @@ fn view_content_tree(content_tree: &str) -> Node<Msg> {
|
|||||||
}
|
}
|
||||||
]],
|
]],
|
||||||
" Debug",
|
" Debug",
|
||||||
ev(Ev::Click, move |_| {
|
debug_open.on_click(|d| *d = !*d)
|
||||||
debug_open.set(!debug_open.get());
|
|
||||||
})
|
|
||||||
],
|
],
|
||||||
IF!(debug_open.get() =>
|
IF!(debug_open.get() =>
|
||||||
pre![C!["NOTPORTED","content-tree"], content_tree]),
|
pre![C!["NOTPORTED","content-tree"], content_tree]),
|
||||||
@@ -879,11 +1192,12 @@ fn view_header(
|
|||||||
false
|
false
|
||||||
};
|
};
|
||||||
let query = Url::decode_uri_component(query).unwrap_or("".to_string());
|
let query = Url::decode_uri_component(query).unwrap_or("".to_string());
|
||||||
|
|
||||||
nav![
|
nav![
|
||||||
C!["flex", "px-4", "pt-4", "overflow-hidden"],
|
C!["flex", "px-4", "pt-4", "overflow-hidden"],
|
||||||
a![
|
a![
|
||||||
C![IF![is_error => "bg-red-500"], "rounded-r-none"],
|
C![IF![is_error => "bg-red-500"], "rounded-r-none"],
|
||||||
C![&tw_classes::BUTTON],
|
tw_classes::button(),
|
||||||
span![i![C![
|
span![i![C![
|
||||||
"fa-solid",
|
"fa-solid",
|
||||||
"fa-arrow-rotate-right",
|
"fa-arrow-rotate-right",
|
||||||
@@ -892,7 +1206,7 @@ fn view_header(
|
|||||||
ev(Ev::Click, |_| Msg::RefreshStart),
|
ev(Ev::Click, |_| Msg::RefreshStart),
|
||||||
],
|
],
|
||||||
a![
|
a![
|
||||||
C![&tw_classes::BUTTON],
|
tw_classes::button(),
|
||||||
C!["px-4", "rounded-none"],
|
C!["px-4", "rounded-none"],
|
||||||
attrs! {
|
attrs! {
|
||||||
At::Href => urls::search(unread_query(), 0)
|
At::Href => urls::search(unread_query(), 0)
|
||||||
@@ -900,7 +1214,7 @@ fn view_header(
|
|||||||
"Unread",
|
"Unread",
|
||||||
],
|
],
|
||||||
a![
|
a![
|
||||||
C![&tw_classes::BUTTON],
|
tw_classes::button(),
|
||||||
C!["px-4", "rounded-none"],
|
C!["px-4", "rounded-none"],
|
||||||
attrs! {
|
attrs! {
|
||||||
At::Href => urls::search("", 0)
|
At::Href => urls::search("", 0)
|
||||||
@@ -925,8 +1239,13 @@ fn view_header(
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tags(model: &Model) -> Node<Msg> {
|
pub fn view_tags(tags: &Option<Vec<Tag>>) -> Node<Msg> {
|
||||||
fn view_tag(display_name: &str, indent: usize, t: &Tag, search_unread: bool) -> Node<Msg> {
|
fn inner_view_tag(
|
||||||
|
display_name: &str,
|
||||||
|
indent: usize,
|
||||||
|
t: &Tag,
|
||||||
|
search_unread: bool,
|
||||||
|
) -> Node<Msg> {
|
||||||
// Hacky, but necessary for tailwind to see all the classes we're using
|
// Hacky, but necessary for tailwind to see all the classes we're using
|
||||||
let indent_cls = match indent {
|
let indent_cls = match indent {
|
||||||
0 => "",
|
0 => "",
|
||||||
@@ -967,11 +1286,7 @@ pub fn tags(model: &Model) -> Node<Msg> {
|
|||||||
],
|
],
|
||||||
IF!(t.unread>0 => format!("{}", t.unread))
|
IF!(t.unread>0 => format!("{}", t.unread))
|
||||||
],
|
],
|
||||||
ev(Ev::Click, |_| {
|
ev(Ev::Click, |_| { Msg::ScrollToTop })
|
||||||
// Scroll window to the top when searching for a tag.
|
|
||||||
info!("scrolling to the top because you clicked a tag");
|
|
||||||
web_sys::window().unwrap().scroll_to_with_x_and_y(0., 0.);
|
|
||||||
})
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
fn matches(a: &[&str], b: &[&str]) -> usize {
|
fn matches(a: &[&str], b: &[&str]) -> usize {
|
||||||
@@ -979,7 +1294,10 @@ pub fn tags(model: &Model) -> Node<Msg> {
|
|||||||
.take_while(|(a, b)| a == b)
|
.take_while(|(a, b)| a == b)
|
||||||
.count()
|
.count()
|
||||||
}
|
}
|
||||||
fn view_tags<'a>(tags: impl Iterator<Item = &'a Tag>, search_unread: bool) -> Vec<Node<Msg>> {
|
fn inner_view_tags<'a>(
|
||||||
|
tags: impl Iterator<Item = &'a Tag>,
|
||||||
|
search_unread: bool,
|
||||||
|
) -> Vec<Node<Msg>> {
|
||||||
let mut tag_els = Vec::new();
|
let mut tag_els = Vec::new();
|
||||||
let mut last = Vec::new();
|
let mut last = Vec::new();
|
||||||
for t in tags {
|
for t in tags {
|
||||||
@@ -989,7 +1307,7 @@ pub fn tags(model: &Model) -> Node<Msg> {
|
|||||||
// Synthesize fake tags for proper indenting.
|
// Synthesize fake tags for proper indenting.
|
||||||
for i in n..parts.len() - 1 {
|
for i in n..parts.len() - 1 {
|
||||||
let display_name = parts[n];
|
let display_name = parts[n];
|
||||||
tag_els.push(view_tag(
|
tag_els.push(inner_view_tag(
|
||||||
&display_name,
|
&display_name,
|
||||||
n,
|
n,
|
||||||
&Tag {
|
&Tag {
|
||||||
@@ -1003,22 +1321,33 @@ pub fn tags(model: &Model) -> Node<Msg> {
|
|||||||
n = parts.len() - 1;
|
n = parts.len() - 1;
|
||||||
}
|
}
|
||||||
let display_name = parts[n];
|
let display_name = parts[n];
|
||||||
tag_els.push(view_tag(&display_name, n, t, search_unread));
|
tag_els.push(inner_view_tag(&display_name, n, t, search_unread));
|
||||||
last = parts;
|
last = parts;
|
||||||
}
|
}
|
||||||
tag_els
|
tag_els
|
||||||
}
|
}
|
||||||
let unread = model
|
let mut unread = tags
|
||||||
.tags
|
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|tags| tags.iter().filter(|t| t.unread > 0).collect())
|
.map(|tags| tags.iter().filter(|t| t.unread > 0).collect())
|
||||||
.unwrap_or(Vec::new());
|
.unwrap_or(Vec::new());
|
||||||
|
unread.sort_by(|a, b| {
|
||||||
|
let r = if a.name.starts_with('@') && b.name.starts_with('@') {
|
||||||
|
a.name.cmp(&b.name)
|
||||||
|
} else if a.name.starts_with('@') {
|
||||||
|
Ordering::Less
|
||||||
|
} else if b.name.starts_with('@') {
|
||||||
|
Ordering::Greater
|
||||||
|
} else {
|
||||||
|
a.name.cmp(&b.name)
|
||||||
|
};
|
||||||
|
return r;
|
||||||
|
});
|
||||||
let tags_open = use_state(|| false);
|
let tags_open = use_state(|| false);
|
||||||
let force_tags_open = unread.is_empty();
|
let force_tags_open = unread.is_empty();
|
||||||
aside![
|
aside![
|
||||||
C!["p-2"],
|
C!["p-2"],
|
||||||
IF!(!unread.is_empty() => p![C!["uppercase", "font-bold"], "Unread"]),
|
IF!(!unread.is_empty() => p![C!["uppercase", "font-bold"], "Unread"]),
|
||||||
IF!(!unread.is_empty() => div![C!["flex","flex-col"], view_tags(unread.into_iter(), true)]),
|
IF!(!unread.is_empty() => div![C!["flex","flex-col"], inner_view_tags(unread.into_iter(), true)]),
|
||||||
p![
|
p![
|
||||||
span![C!["uppercase", "font-bold", "pr-2"], "Tags"],
|
span![C!["uppercase", "font-bold", "pr-2"], "Tags"],
|
||||||
IF!(!force_tags_open =>
|
IF!(!force_tags_open =>
|
||||||
@@ -1030,16 +1359,20 @@ pub fn tags(model: &Model) -> Node<Msg> {
|
|||||||
"fa-angle-down"
|
"fa-angle-down"
|
||||||
}
|
}
|
||||||
]]),
|
]]),
|
||||||
ev(Ev::Click, move |_| {
|
tags_open.on_click(|t| *t = !*t)
|
||||||
tags_open.set(!tags_open.get());
|
|
||||||
})
|
|
||||||
],
|
],
|
||||||
div![
|
div![
|
||||||
IF!(force_tags_open||tags_open.get() => model.tags.as_ref().map(|tags| view_tags(tags.iter(),false))),
|
IF!(force_tags_open||tags_open.get() => tags.as_ref().map(|t| inner_view_tags(t.iter(),false))),
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
fn news_post(post: &ShowThreadQueryThreadOnNewsPost, content_el: &ElRef<HtmlElement>) -> Node<Msg> {
|
|
||||||
|
// TODO: add cathup_mode:bool and hide elements when true
|
||||||
|
fn news_post(
|
||||||
|
post: &ShowThreadQueryThreadOnNewsPost,
|
||||||
|
content_el: &ElRef<HtmlElement>,
|
||||||
|
catchup_mode: bool,
|
||||||
|
) -> Node<Msg> {
|
||||||
let subject = &post.title;
|
let subject = &post.title;
|
||||||
set_title(subject);
|
set_title(subject);
|
||||||
let read_thread_id = post.thread_id.clone();
|
let read_thread_id = post.thread_id.clone();
|
||||||
@@ -1070,11 +1403,12 @@ fn news_post(post: &ShowThreadQueryThreadOnNewsPost, content_el: &ElRef<HtmlElem
|
|||||||
C!["p-4", "lg:p-0"],
|
C!["p-4", "lg:p-0"],
|
||||||
h3![C!["text-xl"], subject],
|
h3![C!["text-xl"], subject],
|
||||||
span![tag(format!("News/{}", post.slug))],
|
span![tag(format!("News/{}", post.slug))],
|
||||||
div![
|
IF!(!catchup_mode => div![
|
||||||
C!["pt-4", "gap-2", "flex", "justify-around"],
|
C!["pt-4", "gap-2", "flex", "justify-around"],
|
||||||
div![
|
div![
|
||||||
button![
|
button![
|
||||||
C![&tw_classes::BUTTON, "rounded-r-none"],
|
tw_classes::button(),
|
||||||
|
C!["rounded-r-none"],
|
||||||
attrs! {At::Title => "Mark as read"},
|
attrs! {At::Title => "Mark as read"},
|
||||||
span![i![C!["far", "fa-envelope-open"]]],
|
span![i![C!["far", "fa-envelope-open"]]],
|
||||||
span![C!["pl-2"], "Read"],
|
span![C!["pl-2"], "Read"],
|
||||||
@@ -1084,7 +1418,8 @@ fn news_post(post: &ShowThreadQueryThreadOnNewsPost, content_el: &ElRef<HtmlElem
|
|||||||
])),
|
])),
|
||||||
],
|
],
|
||||||
button![
|
button![
|
||||||
C![&tw_classes::BUTTON, "rounded-l-none"],
|
tw_classes::button(),
|
||||||
|
C!["rounded-l-none"],
|
||||||
attrs! {At::Title => "Mark as unread"},
|
attrs! {At::Title => "Mark as unread"},
|
||||||
span![i![C!["far", "fa-envelope"]]],
|
span![i![C!["far", "fa-envelope"]]],
|
||||||
span![C!["pl-2"], "Unread"],
|
span![C!["pl-2"], "Unread"],
|
||||||
@@ -1096,7 +1431,7 @@ fn news_post(post: &ShowThreadQueryThreadOnNewsPost, content_el: &ElRef<HtmlElem
|
|||||||
],
|
],
|
||||||
// Placeholder for symmetry with email view that has Spam button
|
// Placeholder for symmetry with email view that has Spam button
|
||||||
div![],
|
div![],
|
||||||
],
|
]),
|
||||||
],
|
],
|
||||||
div![
|
div![
|
||||||
C!["lg:mt-4"],
|
C!["lg:mt-4"],
|
||||||
@@ -1116,12 +1451,11 @@ fn news_post(post: &ShowThreadQueryThreadOnNewsPost, content_el: &ElRef<HtmlElem
|
|||||||
raw![&post.body]
|
raw![&post.body]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
click_to_top(),
|
IF!(!catchup_mode => click_to_top()),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
fn render_news_post_header(post: &ShowThreadQueryThreadOnNewsPost) -> Node<Msg> {
|
fn render_news_post_header(post: &ShowThreadQueryThreadOnNewsPost) -> Node<Msg> {
|
||||||
let from = &post.site;
|
let from = &post.site;
|
||||||
// TODO: move avatar/favicon stuff to the server side and and come up with a solution for emails
|
|
||||||
let id = post.thread_id.clone();
|
let id = post.thread_id.clone();
|
||||||
let is_unread = !post.is_read;
|
let is_unread = !post.is_read;
|
||||||
let url = &post.url;
|
let url = &post.url;
|
||||||
@@ -1159,7 +1493,7 @@ fn render_news_post_header(post: &ShowThreadQueryThreadOnNewsPost) -> Node<Msg>
|
|||||||
div![
|
div![
|
||||||
C!["flex", "gap-2", "pt-2", "text-sm"],
|
C!["flex", "gap-2", "pt-2", "text-sm"],
|
||||||
a![
|
a![
|
||||||
C![&tw_classes::BUTTON],
|
tw_classes::button(),
|
||||||
attrs! {
|
attrs! {
|
||||||
At::Href => post.url,
|
At::Href => post.url,
|
||||||
At::Target => "_blank",
|
At::Target => "_blank",
|
||||||
@@ -1168,7 +1502,7 @@ fn render_news_post_header(post: &ShowThreadQueryThreadOnNewsPost) -> Node<Msg>
|
|||||||
i![C!["fas", "fa-up-right-from-square"]],
|
i![C!["fas", "fa-up-right-from-square"]],
|
||||||
],
|
],
|
||||||
a![
|
a![
|
||||||
C![&tw_classes::BUTTON],
|
tw_classes::button(),
|
||||||
attrs! {
|
attrs! {
|
||||||
At::Href => add_archive_url,
|
At::Href => add_archive_url,
|
||||||
At::Target => "_blank",
|
At::Target => "_blank",
|
||||||
@@ -1177,7 +1511,7 @@ fn render_news_post_header(post: &ShowThreadQueryThreadOnNewsPost) -> Node<Msg>
|
|||||||
i![C!["fas", "fa-plus"]],
|
i![C!["fas", "fa-plus"]],
|
||||||
],
|
],
|
||||||
a![
|
a![
|
||||||
C![&tw_classes::BUTTON],
|
tw_classes::button(),
|
||||||
attrs! {
|
attrs! {
|
||||||
At::Href => view_archive_url,
|
At::Href => view_archive_url,
|
||||||
At::Target => "_blank",
|
At::Target => "_blank",
|
||||||
@@ -1210,7 +1544,6 @@ fn render_news_post_header(post: &ShowThreadQueryThreadOnNewsPost) -> Node<Msg>
|
|||||||
}
|
}
|
||||||
fn reading_progress(ratio: f64) -> Node<Msg> {
|
fn reading_progress(ratio: f64) -> Node<Msg> {
|
||||||
let percent = ratio * 100.;
|
let percent = ratio * 100.;
|
||||||
info!("percent {percent}");
|
|
||||||
div![
|
div![
|
||||||
C![
|
C![
|
||||||
"fixed",
|
"fixed",
|
||||||
@@ -1229,8 +1562,7 @@ fn reading_progress(ratio: f64) -> Node<Msg> {
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
pub fn versions(versions: &crate::state::Version) -> Node<Msg> {
|
pub fn view_versions(versions: &Version) -> Node<Msg> {
|
||||||
debug!("versions {versions:?}");
|
|
||||||
aside![
|
aside![
|
||||||
C!["p-2"],
|
C!["p-2"],
|
||||||
p![C!["uppercase", "font-bold"], "Versions"],
|
p![C!["uppercase", "font-bold"], "Versions"],
|
||||||
@@ -1245,11 +1577,10 @@ pub fn versions(versions: &crate::state::Version) -> Node<Msg> {
|
|||||||
|
|
||||||
fn click_to_top() -> Node<Msg> {
|
fn click_to_top() -> Node<Msg> {
|
||||||
button![
|
button![
|
||||||
C![&tw_classes::BUTTON, "bg-red-500", "lg:m-0", "m-4"],
|
tw_classes::button_with_color("bg-red-500", "hover:bg-neutral-700"),
|
||||||
|
C!["lg:m-0", "m-4"],
|
||||||
span!["Top"],
|
span!["Top"],
|
||||||
span![i![C!["fas", "fa-arrow-turn-up"]]],
|
span![i![C!["fas", "fa-arrow-turn-up"]]],
|
||||||
ev(Ev::Click, |_| web_sys::window()
|
ev(Ev::Click, |_| Msg::ScrollToTop)
|
||||||
.unwrap()
|
|
||||||
.scroll_to_with_x_and_y(0., 0.))
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,15 @@ html {
|
|||||||
margin-left: 2em;
|
margin-left: 2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mail-thread .noreply-news-bloomberg-com img.logo-image {
|
||||||
|
width: initial !important;
|
||||||
|
max-width: 100% !important;
|
||||||
|
}
|
||||||
|
.mail-thread .noreply-news-bloomberg-com h2 {
|
||||||
|
margin: 0 !important;
|
||||||
|
padding: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
/* Hackaday figures have unreadable black on dark grey */
|
/* Hackaday figures have unreadable black on dark grey */
|
||||||
.news-post figcaption.wp-caption-text {
|
.news-post figcaption.wp-caption-text {
|
||||||
background-color: initial !important;
|
background-color: initial !important;
|
||||||
|
|||||||
Reference in New Issue
Block a user