Compare commits
21 Commits
letterbox-
...
letterbox-
| Author | SHA1 | Date | |
|---|---|---|---|
| 32a1115abd | |||
| 4982057500 | |||
| 8977f8bab5 | |||
| 0962a6b3cf | |||
| 3c72929a4f | |||
| e4eb495a70 | |||
| 00e8b0342e | |||
| b1f9867c06 | |||
| 77943b3570 | |||
| 45e4edb1dd | |||
| 9bf53afebf | |||
| e1a502ac4b | |||
| 9346c46e62 | |||
| 1452746305 | |||
| 2e526dace1 | |||
| 76be5b7cac | |||
| 3f0b2caedf | |||
| ec6dc35ca8 | |||
| 01e1ca927e | |||
| 1cc52d6c96 | |||
| e6b3a5b5a9 |
54
Cargo.lock
generated
54
Cargo.lock
generated
@@ -787,9 +787,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.30"
|
||||
version = "4.5.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "92b7b18d71fad5313a1e320fa9897994228ce274b60faa4d694fe0ea89cd9e6d"
|
||||
checksum = "027bb0d98429ae334a8698531da7077bdf906419543a35a55c2cb1b66437d767"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
@@ -797,9 +797,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.5.30"
|
||||
version = "4.5.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a35db2071778a7344791a4fb4f95308b5673d219dee3ae348b86642574ecc90c"
|
||||
checksum = "5589e0cba072e0f3d23791efac0fd8627b49c829c196a492e88168e6a669d863"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
@@ -910,9 +910,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "console_log"
|
||||
version = "0.1.2"
|
||||
version = "0.1.4"
|
||||
source = "sparse+https://git.z.xinu.tv/api/packages/wathiede/cargo/"
|
||||
checksum = "e628484ff9348e6c256644436f215c0a9766867820da8cf161c567db1c877e32"
|
||||
checksum = "d36495b7586d34322c3ffcff0e0d9d0b70f3a4ce88a9c199b3d8a01afb1debd7"
|
||||
dependencies = [
|
||||
"log",
|
||||
"wasm-bindgen",
|
||||
@@ -1517,9 +1517,9 @@ checksum = "b2972feb8dffe7bc8c5463b1dacda1b0dfbed3710e50f977d965429692d74cd8"
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.13.0"
|
||||
version = "1.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
|
||||
checksum = "b7914353092ddf589ad78f25c5c1c21b7f80b0ff8621e7c814c3485b5306da9d"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
@@ -1620,9 +1620,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.0.35"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c"
|
||||
checksum = "11faaf5a5236997af9848be0bef4db95824b1d534ebc64d0f0c6cf3e67bd38dc"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"miniz_oxide",
|
||||
@@ -2965,7 +2965,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "letterbox-notmuch"
|
||||
version = "0.8.5"
|
||||
version = "0.9.4"
|
||||
dependencies = [
|
||||
"itertools 0.14.0",
|
||||
"log",
|
||||
@@ -2980,14 +2980,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "letterbox-procmail2notmuch"
|
||||
version = "0.8.5"
|
||||
version = "0.9.4"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "letterbox-server"
|
||||
version = "0.8.5"
|
||||
version = "0.9.4"
|
||||
dependencies = [
|
||||
"ammonia",
|
||||
"anyhow",
|
||||
@@ -3030,7 +3030,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "letterbox-shared"
|
||||
version = "0.8.5"
|
||||
version = "0.9.4"
|
||||
dependencies = [
|
||||
"build-info",
|
||||
"letterbox-notmuch",
|
||||
@@ -3039,7 +3039,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "letterbox-web"
|
||||
version = "0.8.5"
|
||||
version = "0.9.4"
|
||||
dependencies = [
|
||||
"build-info",
|
||||
"build-info-build",
|
||||
@@ -3057,6 +3057,7 @@ dependencies = [
|
||||
"seed_hooks",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"strum_macros 0.27.1",
|
||||
"thiserror 2.0.11",
|
||||
"uuid",
|
||||
"wasm-bindgen",
|
||||
@@ -3072,9 +3073,9 @@ checksum = "0c2cdeb66e45e9f36bfad5bbdb4d2384e70936afbee843c6f6543f0c551ebb25"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.169"
|
||||
version = "0.2.170"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
|
||||
checksum = "875b3680cb2f8f71bdcf9a30f38d48282f5d3c95cbf9b3fa57269bb5d5c06828"
|
||||
|
||||
[[package]]
|
||||
name = "libgit2-sys"
|
||||
@@ -5241,9 +5242,9 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||
|
||||
[[package]]
|
||||
name = "scraper"
|
||||
version = "0.22.0"
|
||||
version = "0.23.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc3d051b884f40e309de6c149734eab57aa8cc1347992710dc80bcc1c2194c15"
|
||||
checksum = "527e65d9d888567588db4c12da1087598d0f6f8b346cc2c5abc91f05fc2dffe2"
|
||||
dependencies = [
|
||||
"cssparser 0.34.0",
|
||||
"ego-tree",
|
||||
@@ -5962,7 +5963,7 @@ version = "0.26.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06"
|
||||
dependencies = [
|
||||
"strum_macros",
|
||||
"strum_macros 0.26.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -5978,6 +5979,19 @@ dependencies = [
|
||||
"syn 2.0.98",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strum_macros"
|
||||
version = "0.27.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c77a8c5abcaf0f9ce05d62342b7d298c346515365c36b673df4ebe3ced01fde8"
|
||||
dependencies = [
|
||||
"heck 0.5.0",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rustversion",
|
||||
"syn 2.0.98",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "subtle"
|
||||
version = "1.0.0"
|
||||
|
||||
@@ -8,7 +8,7 @@ authors = ["Bill Thiede <git@xinu.tv>"]
|
||||
edition = "2021"
|
||||
license = "UNLICENSED"
|
||||
publish = ["xinu"]
|
||||
version = "0.8.5"
|
||||
version = "0.9.4"
|
||||
repository = "https://git.z.xinu.tv/wathiede/letterbox"
|
||||
|
||||
[profile.dev]
|
||||
|
||||
@@ -271,6 +271,12 @@ pub struct Headers {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub bcc: Option<String>,
|
||||
#[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 date: String,
|
||||
}
|
||||
@@ -639,6 +645,16 @@ impl Notmuch {
|
||||
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 {
|
||||
|
||||
@@ -35,7 +35,7 @@ regex = "1.11.1"
|
||||
reqwest = { version = "0.12.7", features = ["blocking"] }
|
||||
rocket = { version = "0.5.0-rc.2", features = ["json"] }
|
||||
rocket_cors = "0.6.0"
|
||||
scraper = "0.22.0"
|
||||
scraper = "0.23.0"
|
||||
serde = { version = "1.0.147", features = ["derive"] }
|
||||
serde_json = "1.0.87"
|
||||
sqlx = { version = "0.8.2", features = ["postgres", "runtime-tokio", "time"] }
|
||||
@@ -48,8 +48,8 @@ urlencoding = "2.1.3"
|
||||
#xtracing = { path = "../../xtracing" }
|
||||
#xtracing = { git = "http://git-private.h.xinu.tv/wathiede/xtracing.git" }
|
||||
xtracing = { version = "0.3.0", registry = "xinu" }
|
||||
letterbox-notmuch = { version = "0.8.5", path = "../notmuch", registry = "xinu" }
|
||||
letterbox-shared = { version = "0.8.5", path = "../shared", registry = "xinu" }
|
||||
letterbox-notmuch = { version = "0.9.4", path = "../notmuch", registry = "xinu" }
|
||||
letterbox-shared = { version = "0.9.4", path = "../shared", registry = "xinu" }
|
||||
|
||||
[build-dependencies]
|
||||
build-info-build = "0.0.39"
|
||||
|
||||
@@ -95,6 +95,10 @@ pub struct Message {
|
||||
pub to: Vec<Email>,
|
||||
// All CC headers found in 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
|
||||
pub subject: Option<String>,
|
||||
// Parsed Date header, if found and valid
|
||||
@@ -306,6 +310,45 @@ impl QueryRoot {
|
||||
info!("count {newsreader_query:?} newsreader count {newsreader_count} notmuch count {notmuch_count} tantivy count {tantivy_count} total {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,
|
||||
// rewrite that with tokio::process:Command
|
||||
|
||||
@@ -682,7 +682,7 @@ fn compute_offset_limit(
|
||||
first: Option<i32>,
|
||||
last: Option<i32>,
|
||||
) -> (i32, i32) {
|
||||
let default_page_size = 100;
|
||||
let default_page_size = 10000;
|
||||
match (after, before, first, last) {
|
||||
// Reasonable defaults
|
||||
(None, None, None, None) => (0, default_page_size),
|
||||
@@ -773,7 +773,19 @@ impl Query {
|
||||
for uid in &self.uids {
|
||||
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(" ")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,6 +196,8 @@ pub async fn thread(
|
||||
|
||||
let to = email_addresses(&path, &m, "to")?;
|
||||
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 timestamp = m
|
||||
.headers
|
||||
@@ -315,6 +317,8 @@ pub async fn thread(
|
||||
body,
|
||||
path,
|
||||
attachments,
|
||||
delivered_to,
|
||||
x_original_to,
|
||||
});
|
||||
}
|
||||
messages.reverse();
|
||||
|
||||
@@ -12,5 +12,5 @@ version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
build-info = "0.0.39"
|
||||
letterbox-notmuch = { version = "0.8.5", path = "../notmuch", registry = "xinu" }
|
||||
letterbox-notmuch = { version = "0.9.4", path = "../notmuch", registry = "xinu" }
|
||||
serde = { version = "1.0.147", features = ["derive"] }
|
||||
|
||||
@@ -33,9 +33,10 @@ wasm-bindgen = "=0.2.100"
|
||||
uuid = { version = "1.13.1", features = [
|
||||
"js",
|
||||
] } # direct dep to set js feature, prevents Rng issues
|
||||
letterbox-shared = { version = "0.8.5", path = "../shared", registry = "xinu" }
|
||||
letterbox-notmuch = { version = "0.8.5", path = "../notmuch", registry = "xinu" }
|
||||
letterbox-shared = { version = "0.9.4", path = "../shared", registry = "xinu" }
|
||||
letterbox-notmuch = { version = "0.9.4", path = "../notmuch", registry = "xinu" }
|
||||
seed_hooks = { version = "0.4.0", registry = "xinu" }
|
||||
strum_macros = "0.27.1"
|
||||
|
||||
[package.metadata.wasm-pack.profile.release]
|
||||
wasm-opt = ['-Os']
|
||||
|
||||
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": [],
|
||||
"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": [
|
||||
{
|
||||
|
||||
@@ -31,6 +31,14 @@ query ShowThreadQuery($threadId: String!) {
|
||||
name
|
||||
addr
|
||||
}
|
||||
xOriginalTo {
|
||||
name
|
||||
addr
|
||||
}
|
||||
deliveredTo {
|
||||
name
|
||||
addr
|
||||
}
|
||||
timestamp
|
||||
body {
|
||||
__typename
|
||||
|
||||
@@ -12,6 +12,14 @@ use serde::{de::DeserializeOwned, Serialize};
|
||||
)]
|
||||
pub struct FrontPageQuery;
|
||||
|
||||
#[derive(GraphQLQuery)]
|
||||
#[graphql(
|
||||
schema_path = "graphql/schema.json",
|
||||
query_path = "graphql/catchup.graphql",
|
||||
response_derives = "Debug"
|
||||
)]
|
||||
pub struct CatchupQuery;
|
||||
|
||||
#[derive(GraphQLQuery)]
|
||||
#[graphql(
|
||||
schema_path = "graphql/schema.json",
|
||||
|
||||
@@ -18,6 +18,9 @@ fn main() {
|
||||
#[cfg(debug_assertions)]
|
||||
console_error_panic_hook::set_once();
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
let lvl = Level::Debug;
|
||||
#[cfg(not(debug_assertions))]
|
||||
let lvl = Level::Info;
|
||||
console_log::init_with_level(lvl).expect("failed to initialize console logging");
|
||||
// Mount the `app` to the element with the `id` "app".
|
||||
|
||||
174
web/src/state.rs
174
web/src/state.rs
@@ -32,13 +32,13 @@ pub fn init(url: Url, orders: &mut impl Orders<Msg>) -> Model {
|
||||
if url.hash().is_none() {
|
||||
orders.request_url(urls::search(unread_query(), 0));
|
||||
} 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
|
||||
// 'notmuch new' on the server periodically?
|
||||
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));
|
||||
|
||||
build_info::build_info!(fn bi);
|
||||
@@ -53,18 +53,23 @@ pub fn init(url: Url, orders: &mut impl Orders<Msg>) -> Model {
|
||||
client: version,
|
||||
server: None,
|
||||
},
|
||||
catchup: None,
|
||||
last_url: Url::current(),
|
||||
}
|
||||
}
|
||||
|
||||
fn on_url_changed(uc: subs::UrlChanged) -> Msg {
|
||||
let mut url = uc.0;
|
||||
fn on_url_changed(old: &Url, mut new: Url) -> Msg {
|
||||
let did_change = *old != new;
|
||||
let mut messages = Vec::new();
|
||||
if did_change {
|
||||
messages.push(Msg::ScrollToTop)
|
||||
}
|
||||
info!(
|
||||
"url changed '{}', history {}",
|
||||
url,
|
||||
"url changed\nold '{old}'\nnew '{new}', history {}",
|
||||
history().length().unwrap_or(0)
|
||||
);
|
||||
let hpp = url.remaining_hash_path_parts();
|
||||
match hpp.as_slice() {
|
||||
let hpp = new.remaining_hash_path_parts();
|
||||
let msg = match hpp.as_slice() {
|
||||
["t", tid] => Msg::ShowThreadRequest {
|
||||
thread_id: tid.to_string(),
|
||||
},
|
||||
@@ -101,11 +106,14 @@ fn on_url_changed(uc: subs::UrlChanged) -> Msg {
|
||||
last: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
messages.push(msg);
|
||||
Msg::MultiMsg(messages)
|
||||
}
|
||||
|
||||
// `update` describes how to handle each `Msg`.
|
||||
pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
debug!("update({})", msg);
|
||||
match msg {
|
||||
Msg::Noop => {}
|
||||
Msg::RefreshStart => {
|
||||
@@ -131,7 +139,7 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
orders.perform_cmd(async move { Msg::Refresh });
|
||||
}
|
||||
Msg::Refresh => {
|
||||
orders.perform_cmd(async move { on_url_changed(subs::UrlChanged(Url::current())) });
|
||||
orders.request_url(Url::current());
|
||||
}
|
||||
Msg::Reload => {
|
||||
window()
|
||||
@@ -139,6 +147,10 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
.reload()
|
||||
.expect("failed to reload window");
|
||||
}
|
||||
Msg::OnUrlChanged(new_url) => {
|
||||
orders.send_msg(on_url_changed(&model.last_url, new_url.0.clone()));
|
||||
model.last_url = new_url.0;
|
||||
}
|
||||
Msg::OnResize => (),
|
||||
|
||||
Msg::NextPage => {
|
||||
@@ -181,10 +193,7 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
};
|
||||
}
|
||||
Msg::GoToSearchResults => {
|
||||
let url = urls::search(&model.query, 0);
|
||||
info!("GoToSearchRestuls Start");
|
||||
orders.request_url(url);
|
||||
info!("GoToSearchRestuls End");
|
||||
orders.send_msg(Msg::SearchQuery(model.query.clone()));
|
||||
}
|
||||
|
||||
Msg::UpdateQuery(query) => model.query = query,
|
||||
@@ -307,7 +316,6 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
})
|
||||
.collect(),
|
||||
);
|
||||
info!("pager {:#?}", data.search.page_info);
|
||||
let selected_threads = 'context: {
|
||||
if let Context::SearchResult {
|
||||
results,
|
||||
@@ -390,6 +398,38 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
Msg::ShowThreadResult(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 => {
|
||||
if let Context::SearchResult {
|
||||
selected_threads, ..
|
||||
@@ -503,8 +543,11 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
.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 => {
|
||||
info!("WindowScrolled");
|
||||
if let Some(el) = model.content_el.get() {
|
||||
let ih = window()
|
||||
.inner_height()
|
||||
@@ -513,7 +556,6 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
.value_of();
|
||||
|
||||
let r = el.get_bounding_client_rect();
|
||||
info!("r {r:?} ih {ih}");
|
||||
if r.height() < ih {
|
||||
// The whole content fits in the window, no scrollbar
|
||||
orders.send_msg(Msg::SetProgress(0.));
|
||||
@@ -554,8 +596,77 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
}
|
||||
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.
|
||||
pub struct Model {
|
||||
pub query: String,
|
||||
@@ -565,6 +676,8 @@ pub struct Model {
|
||||
pub read_completion_ratio: f64,
|
||||
pub content_el: ElRef<HtmlElement>,
|
||||
pub versions: Version,
|
||||
pub catchup: Option<Catchup>,
|
||||
pub last_url: Url,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -601,6 +714,15 @@ pub enum Context {
|
||||
},
|
||||
}
|
||||
|
||||
pub struct Catchup {
|
||||
pub items: Vec<CatchupItem>,
|
||||
}
|
||||
|
||||
pub struct CatchupItem {
|
||||
pub id: String,
|
||||
pub seen: bool,
|
||||
}
|
||||
|
||||
pub struct Tag {
|
||||
pub name: String,
|
||||
pub bg_color: String,
|
||||
@@ -614,12 +736,15 @@ pub enum RefreshingState {
|
||||
Error(String),
|
||||
}
|
||||
// `Msg` describes the different events you can modify state with.
|
||||
#[derive(strum_macros::Display)]
|
||||
pub enum Msg {
|
||||
Noop,
|
||||
// Tell the client to refresh its state
|
||||
Refresh,
|
||||
// Tell the client to reload whole page from server
|
||||
Reload,
|
||||
// TODO: add GoToUrl
|
||||
OnUrlChanged(subs::UrlChanged),
|
||||
// Window has changed size
|
||||
OnResize,
|
||||
// Tell the server to update state
|
||||
@@ -651,10 +776,14 @@ pub enum Msg {
|
||||
ShowThreadResult(
|
||||
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,
|
||||
#[allow(dead_code)]
|
||||
SelectionSetAll,
|
||||
SelectionAddTag(String),
|
||||
#[allow(dead_code)]
|
||||
@@ -670,7 +799,14 @@ pub enum Msg {
|
||||
|
||||
CopyToClipboard(String),
|
||||
|
||||
ScrollToTop,
|
||||
WindowScrolled,
|
||||
SetProgress(f64),
|
||||
UpdateServerVersion(String),
|
||||
|
||||
CatchupStart,
|
||||
CatchupKeepUnread,
|
||||
CatchupMarkAsRead,
|
||||
CatchupNext,
|
||||
CatchupExit,
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use std::{cmp::Ordering, collections::HashSet};
|
||||
use std::{cell::RefCell, cmp::Ordering, collections::HashSet};
|
||||
|
||||
use chrono::{DateTime, Datelike, Duration, Local, Utc};
|
||||
use human_format::{Formatter, Scales};
|
||||
use itertools::Itertools;
|
||||
use letterbox_shared::compute_color;
|
||||
use log::{debug, error, info};
|
||||
use log::{debug, error};
|
||||
use seed::{prelude::*, *};
|
||||
use seed_hooks::{state_access::CloneState, topo, use_state, StateAccessEventHandlers};
|
||||
use web_sys::{HtmlElement, HtmlInputElement};
|
||||
@@ -12,7 +12,7 @@ use web_sys::{HtmlElement, HtmlInputElement};
|
||||
use crate::{
|
||||
api::urls,
|
||||
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
|
||||
@@ -21,6 +21,8 @@ use crate::{
|
||||
const MAX_RAW_MESSAGE_SIZE: usize = 100_000;
|
||||
|
||||
mod tw_classes {
|
||||
use seed::{prelude::*, *};
|
||||
|
||||
pub const TAG: &[&str] = &[
|
||||
"rounded-md",
|
||||
"px-2",
|
||||
@@ -37,22 +39,30 @@ mod tw_classes {
|
||||
"text-xs",
|
||||
"[text-shadow:_0_1px_0_rgb(0_0_0_/_40%)]",
|
||||
];
|
||||
pub const BUTTON: &[&str] = &[
|
||||
"bg-neutral-900",
|
||||
"rounded-md",
|
||||
"p-2",
|
||||
"border",
|
||||
"border-neutral-700",
|
||||
"text-center",
|
||||
"text-sm",
|
||||
"transition-all",
|
||||
"shadow-md",
|
||||
"hover:shadow-lg",
|
||||
"hover:bg-neutral-700",
|
||||
"disabled:pointer-events-none",
|
||||
"disabled:opacity-50",
|
||||
"disabled:shadow-none",
|
||||
];
|
||||
|
||||
// TODO: should this be a builder pattern?
|
||||
pub fn button() -> seed::Attrs {
|
||||
button_with_color("bg-neutral-900", "hover:bg-neutral-700")
|
||||
}
|
||||
|
||||
pub fn button_with_color<T: ToClasses>(bg: T, hover: T) -> seed::Attrs {
|
||||
C![
|
||||
"rounded-md",
|
||||
"p-2",
|
||||
"border",
|
||||
"border-neutral-700",
|
||||
"text-center",
|
||||
"text-sm",
|
||||
"transition-all",
|
||||
"shadow-md",
|
||||
"hover:shadow-lg",
|
||||
"disabled:pointer-events-none",
|
||||
"disabled:opacity-50",
|
||||
"disabled:shadow-none",
|
||||
bg,
|
||||
hover,
|
||||
]
|
||||
}
|
||||
|
||||
pub const CHECKBOX: &[&str] = &[
|
||||
"w-8",
|
||||
@@ -68,24 +78,82 @@ mod tw_classes {
|
||||
}
|
||||
|
||||
pub fn view(model: &Model) -> Node<Msg> {
|
||||
let content = match &model.context {
|
||||
Context::None => div![h1!["Loading"]],
|
||||
match &model.context {
|
||||
Context::None => normal_view(
|
||||
div![h1!["Loading"]],
|
||||
&model.versions,
|
||||
&model.query,
|
||||
&model.refreshing_state,
|
||||
model.read_completion_ratio,
|
||||
&model.tags,
|
||||
),
|
||||
Context::ThreadResult {
|
||||
thread: ShowThreadQueryThread::EmailThread(thread_data),
|
||||
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),
|
||||
&catchup.items,
|
||||
model.read_completion_ratio,
|
||||
)
|
||||
} else {
|
||||
normal_view(
|
||||
thread(thread_data, open_messages, &model.content_el),
|
||||
&model.versions,
|
||||
&model.query,
|
||||
&model.refreshing_state,
|
||||
model.read_completion_ratio,
|
||||
&model.tags,
|
||||
)
|
||||
}
|
||||
}
|
||||
Context::ThreadResult {
|
||||
thread: ShowThreadQueryThread::NewsPost(post),
|
||||
..
|
||||
} => news_post(post, &model.content_el),
|
||||
} => {
|
||||
if let Some(catchup) = &model.catchup {
|
||||
catchup_view(
|
||||
news_post(post, &model.content_el),
|
||||
&catchup.items,
|
||||
model.read_completion_ratio,
|
||||
)
|
||||
} else {
|
||||
normal_view(
|
||||
news_post(post, &model.content_el),
|
||||
&model.versions,
|
||||
&model.query,
|
||||
&model.refreshing_state,
|
||||
model.read_completion_ratio,
|
||||
&model.tags,
|
||||
)
|
||||
}
|
||||
}
|
||||
Context::SearchResult {
|
||||
query,
|
||||
results,
|
||||
count,
|
||||
pager,
|
||||
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![
|
||||
C![
|
||||
"relative",
|
||||
@@ -98,19 +166,79 @@ pub fn view(model: &Model) -> Node<Msg> {
|
||||
],
|
||||
div![
|
||||
C!["w-full", "lg:w-48", "flex-none", "flex", "flex-col"],
|
||||
tags(model),
|
||||
versions(&model.versions)
|
||||
view_tags(tags),
|
||||
view_versions(&versions)
|
||||
],
|
||||
div![
|
||||
// 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
|
||||
// parent wider
|
||||
C!["flex-auto", "flex", "flex-col", "overflow-hidden"],
|
||||
view_header(&model.query, &model.refreshing_state, true),
|
||||
view_header(query, refreshing_state, true),
|
||||
content,
|
||||
view_header(&model.query, &model.refreshing_state, false),
|
||||
view_header(query, refreshing_state, false),
|
||||
],
|
||||
reading_progress(model.read_completion_ratio),
|
||||
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",
|
||||
],
|
||||
div![
|
||||
C!["absolute", "right-4", "text-gray-500"],
|
||||
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-4"], content],
|
||||
div![
|
||||
C![
|
||||
"fixed",
|
||||
"bottom-0",
|
||||
"left-0",
|
||||
"right-0",
|
||||
"flex",
|
||||
"justify-center",
|
||||
"gap-4",
|
||||
"p-4",
|
||||
"border-t",
|
||||
"border-gray-500",
|
||||
"bg-black",
|
||||
],
|
||||
button![
|
||||
tw_classes::button(),
|
||||
span![i![C!["far", "fa-envelope"]]],
|
||||
span![C!["pl-2"], "Keep unread"],
|
||||
ev(Ev::Click, move |_| Msg::CatchupKeepUnread)
|
||||
],
|
||||
button![
|
||||
tw_classes::button_with_color("bg-green-800", "hover:bg-neutral-700"),
|
||||
span![i![C!["far", "fa-envelope-open"]]],
|
||||
span![C!["pl-2"], "Mark as read"],
|
||||
ev(Ev::Click, move |_| Msg::CatchupMarkAsRead)
|
||||
]
|
||||
],
|
||||
reading_progress(read_completion_ratio)
|
||||
]
|
||||
}
|
||||
|
||||
@@ -322,16 +450,22 @@ fn search_toolbar(
|
||||
let tristate_el: ElRef<HtmlInputElement> = use_state(|| Default::default()).get();
|
||||
let tri = el_ref(&tristate_el);
|
||||
if let Some(tri) = tri.get() {
|
||||
info!(
|
||||
"setting tristate to {indeterminate}, current {}",
|
||||
tri.indeterminate()
|
||||
);
|
||||
tri.set_indeterminate(indeterminate);
|
||||
}
|
||||
nav![
|
||||
C!["py-4", "flex", "w-full", "justify-between"],
|
||||
div![
|
||||
C!["gap-2", "flex", IF!(!show_bulk_edit => "invisible")],
|
||||
C!["gap-2", "flex", IF!(show_bulk_edit => "hidden")],
|
||||
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![
|
||||
C!["flex", "items-center", "mr-4"],
|
||||
input![
|
||||
@@ -352,14 +486,16 @@ fn search_toolbar(
|
||||
],
|
||||
div![
|
||||
button![
|
||||
C![&tw_classes::BUTTON, "rounded-r-none"],
|
||||
tw_classes::button(),
|
||||
C!["rounded-r-none"],
|
||||
attrs! {At::Title => "Mark as read"},
|
||||
span![i![C!["far", "fa-envelope-open"]]],
|
||||
span![C!["pl-2", "hidden", "md:inline"], "Read"],
|
||||
ev(Ev::Click, |_| Msg::SelectionMarkAsRead)
|
||||
],
|
||||
button![
|
||||
C![&tw_classes::BUTTON, "rounded-l-none"],
|
||||
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"],
|
||||
@@ -367,7 +503,8 @@ fn search_toolbar(
|
||||
]
|
||||
],
|
||||
div![button![
|
||||
C![&tw_classes::BUTTON, "text-red-500"],
|
||||
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"],
|
||||
@@ -381,13 +518,13 @@ fn search_toolbar(
|
||||
C!["flex", "gap-2", "items-center"],
|
||||
p![format!("{count} results")],
|
||||
button![
|
||||
C![&tw_classes::BUTTON],
|
||||
tw_classes::button(),
|
||||
IF!(!pager.has_previous_page => attrs!{ At::Disabled=>true }),
|
||||
"<",
|
||||
IF!(pager.has_previous_page => ev(Ev::Click, |_| Msg::PreviousPage)),
|
||||
],
|
||||
button![
|
||||
C![&tw_classes::BUTTON],
|
||||
tw_classes::button(),
|
||||
IF!(!pager.has_next_page => attrs!{ At::Disabled=>true }),
|
||||
">",
|
||||
IF!(pager.has_next_page => ev(Ev::Click, |_| Msg::NextPage))
|
||||
@@ -484,6 +621,53 @@ fn render_open_header(msg: &ShowThreadQueryThreadOnEmailThreadMessages) -> Node<
|
||||
let is_unread = has_unread(&msg.tags);
|
||||
let avatar = render_avatar(photo_url, &from, true);
|
||||
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![
|
||||
C!["flex", "p-4", "bg-neutral-800"],
|
||||
div![avatar],
|
||||
@@ -505,8 +689,28 @@ fn render_open_header(msg: &ShowThreadQueryThreadOnEmailThreadMessages) -> Node<
|
||||
"To: "
|
||||
],
|
||||
span![
|
||||
msg.to.iter().map(|to| {
|
||||
let ShowThreadQueryThreadOnEmailThreadMessagesTo { name, addr } = to;
|
||||
to_addrs
|
||||
]
|
||||
]),
|
||||
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![
|
||||
addr.as_ref().map(|addr| attrs! {
|
||||
At::Title => addr
|
||||
@@ -519,15 +723,15 @@ fn render_open_header(msg: &ShowThreadQueryThreadOnEmailThreadMessages) -> Node<
|
||||
})
|
||||
]
|
||||
]),
|
||||
IF!(!msg.cc.is_empty() =>div![
|
||||
IF!(show_delivered_to => div![
|
||||
C!["text-xs"],
|
||||
span![
|
||||
C!["font-semibold"],
|
||||
"CC: "
|
||||
"Delivered To: "
|
||||
],
|
||||
span![
|
||||
msg.cc.iter().map(|cc| {
|
||||
let ShowThreadQueryThreadOnEmailThreadMessagesCc { name, addr } = cc;
|
||||
msg.delivered_to.as_ref().map(|to| {
|
||||
let ShowThreadQueryThreadOnEmailThreadMessagesDeliveredTo { name, addr } = to;
|
||||
span![
|
||||
addr.as_ref().map(|addr| attrs! {
|
||||
At::Title => addr
|
||||
@@ -581,6 +785,51 @@ fn render_closed_header(msg: &ShowThreadQueryThreadOnEmailThreadMessages) -> Nod
|
||||
let is_unread = has_unread(&msg.tags);
|
||||
let avatar = render_avatar(photo_url, &from, false);
|
||||
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![
|
||||
C!["flex", "p-4", "bg-neutral-800"],
|
||||
div![avatar],
|
||||
@@ -601,16 +850,7 @@ fn render_closed_header(msg: &ShowThreadQueryThreadOnEmailThreadMessages) -> Nod
|
||||
"To: "
|
||||
],
|
||||
span![
|
||||
msg.to.iter().enumerate().map(|(i, to)| {
|
||||
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))
|
||||
]
|
||||
})
|
||||
to_addrs
|
||||
],
|
||||
" "
|
||||
]),
|
||||
@@ -620,17 +860,46 @@ fn render_closed_header(msg: &ShowThreadQueryThreadOnEmailThreadMessages) -> Nod
|
||||
C!["font-semibold"],
|
||||
"CC: "
|
||||
],
|
||||
msg.cc.iter().enumerate().map(|(i,cc)| {
|
||||
let ShowThreadQueryThreadOnEmailThreadMessagesCc { name, addr } = cc;
|
||||
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))
|
||||
]
|
||||
})
|
||||
])
|
||||
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![
|
||||
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![
|
||||
C!["text-right"],
|
||||
@@ -779,6 +1048,7 @@ fn render_attachements(
|
||||
]
|
||||
}
|
||||
|
||||
// TODO: add cathup_mode:bool and hide elements when true
|
||||
#[topo::nested]
|
||||
fn thread(
|
||||
thread: &ShowThreadQueryThreadOnEmailThread,
|
||||
@@ -811,7 +1081,7 @@ fn thread(
|
||||
let spam_add_thread_id = thread.thread_id.clone();
|
||||
let spam_unread_thread_id = thread.thread_id.clone();
|
||||
div![
|
||||
C!["lg:p-4"],
|
||||
C!["lg:p-4", "max-w-4xl"],
|
||||
div![
|
||||
C!["p-4", "lg:p-0"],
|
||||
h3![C!["text-xl"], subject],
|
||||
@@ -820,7 +1090,8 @@ fn thread(
|
||||
C!["pt-4", "gap-2", "flex", "justify-around"],
|
||||
div![
|
||||
button![
|
||||
C![&tw_classes::BUTTON, "rounded-r-none"],
|
||||
tw_classes::button(),
|
||||
C!["rounded-r-none"],
|
||||
attrs! {At::Title => "Mark as read"},
|
||||
span![i![C!["far", "fa-envelope-open"]]],
|
||||
span![C!["pl-2"], "Read"],
|
||||
@@ -830,7 +1101,8 @@ fn thread(
|
||||
])),
|
||||
],
|
||||
button![
|
||||
C![&tw_classes::BUTTON, "rounded-l-none"],
|
||||
tw_classes::button(),
|
||||
C!["rounded-l-none"],
|
||||
attrs! {At::Title => "Mark as unread"},
|
||||
span![i![C!["far", "fa-envelope"]]],
|
||||
span![C!["pl-2"], "Unread"],
|
||||
@@ -841,7 +1113,8 @@ fn thread(
|
||||
],
|
||||
],
|
||||
div![button![
|
||||
C![&tw_classes::BUTTON, "text-red-500"],
|
||||
tw_classes::button(),
|
||||
C!["text-red-500"],
|
||||
attrs! {At::Title => "Spam"},
|
||||
span![i![C!["far", "fa-hand"]]],
|
||||
span![C!["pl-2"], "Spam"],
|
||||
@@ -907,7 +1180,7 @@ fn view_header(
|
||||
C!["flex", "px-4", "pt-4", "overflow-hidden"],
|
||||
a![
|
||||
C![IF![is_error => "bg-red-500"], "rounded-r-none"],
|
||||
C![&tw_classes::BUTTON],
|
||||
tw_classes::button(),
|
||||
span![i![C![
|
||||
"fa-solid",
|
||||
"fa-arrow-rotate-right",
|
||||
@@ -916,7 +1189,7 @@ fn view_header(
|
||||
ev(Ev::Click, |_| Msg::RefreshStart),
|
||||
],
|
||||
a![
|
||||
C![&tw_classes::BUTTON],
|
||||
tw_classes::button(),
|
||||
C!["px-4", "rounded-none"],
|
||||
attrs! {
|
||||
At::Href => urls::search(unread_query(), 0)
|
||||
@@ -924,7 +1197,7 @@ fn view_header(
|
||||
"Unread",
|
||||
],
|
||||
a![
|
||||
C![&tw_classes::BUTTON],
|
||||
tw_classes::button(),
|
||||
C!["px-4", "rounded-none"],
|
||||
attrs! {
|
||||
At::Href => urls::search("", 0)
|
||||
@@ -949,8 +1222,13 @@ fn view_header(
|
||||
]
|
||||
}
|
||||
|
||||
pub fn tags(model: &Model) -> Node<Msg> {
|
||||
fn view_tag(display_name: &str, indent: usize, t: &Tag, search_unread: bool) -> Node<Msg> {
|
||||
pub fn view_tags(tags: &Option<Vec<Tag>>) -> 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
|
||||
let indent_cls = match indent {
|
||||
0 => "",
|
||||
@@ -991,11 +1269,7 @@ pub fn tags(model: &Model) -> Node<Msg> {
|
||||
],
|
||||
IF!(t.unread>0 => format!("{}", t.unread))
|
||||
],
|
||||
ev(Ev::Click, |_| {
|
||||
// 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.);
|
||||
})
|
||||
ev(Ev::Click, |_| { Msg::ScrollToTop })
|
||||
]
|
||||
}
|
||||
fn matches(a: &[&str], b: &[&str]) -> usize {
|
||||
@@ -1003,7 +1277,10 @@ pub fn tags(model: &Model) -> Node<Msg> {
|
||||
.take_while(|(a, b)| a == b)
|
||||
.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 last = Vec::new();
|
||||
for t in tags {
|
||||
@@ -1013,7 +1290,7 @@ pub fn tags(model: &Model) -> Node<Msg> {
|
||||
// Synthesize fake tags for proper indenting.
|
||||
for i in n..parts.len() - 1 {
|
||||
let display_name = parts[n];
|
||||
tag_els.push(view_tag(
|
||||
tag_els.push(inner_view_tag(
|
||||
&display_name,
|
||||
n,
|
||||
&Tag {
|
||||
@@ -1027,13 +1304,12 @@ pub fn tags(model: &Model) -> Node<Msg> {
|
||||
n = parts.len() - 1;
|
||||
}
|
||||
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;
|
||||
}
|
||||
tag_els
|
||||
}
|
||||
let mut unread = model
|
||||
.tags
|
||||
let mut unread = tags
|
||||
.as_ref()
|
||||
.map(|tags| tags.iter().filter(|t| t.unread > 0).collect())
|
||||
.unwrap_or(Vec::new());
|
||||
@@ -1054,7 +1330,7 @@ pub fn tags(model: &Model) -> Node<Msg> {
|
||||
aside![
|
||||
C!["p-2"],
|
||||
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![
|
||||
span![C!["uppercase", "font-bold", "pr-2"], "Tags"],
|
||||
IF!(!force_tags_open =>
|
||||
@@ -1069,10 +1345,12 @@ pub fn tags(model: &Model) -> Node<Msg> {
|
||||
tags_open.on_click(|t| *t = !*t)
|
||||
],
|
||||
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))),
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
// TODO: add cathup_mode:bool and hide elements when true
|
||||
fn news_post(post: &ShowThreadQueryThreadOnNewsPost, content_el: &ElRef<HtmlElement>) -> Node<Msg> {
|
||||
let subject = &post.title;
|
||||
set_title(subject);
|
||||
@@ -1108,7 +1386,8 @@ fn news_post(post: &ShowThreadQueryThreadOnNewsPost, content_el: &ElRef<HtmlElem
|
||||
C!["pt-4", "gap-2", "flex", "justify-around"],
|
||||
div![
|
||||
button![
|
||||
C![&tw_classes::BUTTON, "rounded-r-none"],
|
||||
tw_classes::button(),
|
||||
C!["rounded-r-none"],
|
||||
attrs! {At::Title => "Mark as read"},
|
||||
span![i![C!["far", "fa-envelope-open"]]],
|
||||
span![C!["pl-2"], "Read"],
|
||||
@@ -1118,7 +1397,8 @@ fn news_post(post: &ShowThreadQueryThreadOnNewsPost, content_el: &ElRef<HtmlElem
|
||||
])),
|
||||
],
|
||||
button![
|
||||
C![&tw_classes::BUTTON, "rounded-l-none"],
|
||||
tw_classes::button(),
|
||||
C!["rounded-l-none"],
|
||||
attrs! {At::Title => "Mark as unread"},
|
||||
span![i![C!["far", "fa-envelope"]]],
|
||||
span![C!["pl-2"], "Unread"],
|
||||
@@ -1193,7 +1473,7 @@ fn render_news_post_header(post: &ShowThreadQueryThreadOnNewsPost) -> Node<Msg>
|
||||
div![
|
||||
C!["flex", "gap-2", "pt-2", "text-sm"],
|
||||
a![
|
||||
C![&tw_classes::BUTTON],
|
||||
tw_classes::button(),
|
||||
attrs! {
|
||||
At::Href => post.url,
|
||||
At::Target => "_blank",
|
||||
@@ -1202,7 +1482,7 @@ fn render_news_post_header(post: &ShowThreadQueryThreadOnNewsPost) -> Node<Msg>
|
||||
i![C!["fas", "fa-up-right-from-square"]],
|
||||
],
|
||||
a![
|
||||
C![&tw_classes::BUTTON],
|
||||
tw_classes::button(),
|
||||
attrs! {
|
||||
At::Href => add_archive_url,
|
||||
At::Target => "_blank",
|
||||
@@ -1211,7 +1491,7 @@ fn render_news_post_header(post: &ShowThreadQueryThreadOnNewsPost) -> Node<Msg>
|
||||
i![C!["fas", "fa-plus"]],
|
||||
],
|
||||
a![
|
||||
C![&tw_classes::BUTTON],
|
||||
tw_classes::button(),
|
||||
attrs! {
|
||||
At::Href => view_archive_url,
|
||||
At::Target => "_blank",
|
||||
@@ -1244,7 +1524,6 @@ fn render_news_post_header(post: &ShowThreadQueryThreadOnNewsPost) -> Node<Msg>
|
||||
}
|
||||
fn reading_progress(ratio: f64) -> Node<Msg> {
|
||||
let percent = ratio * 100.;
|
||||
info!("percent {percent}");
|
||||
div![
|
||||
C![
|
||||
"fixed",
|
||||
@@ -1263,8 +1542,7 @@ fn reading_progress(ratio: f64) -> Node<Msg> {
|
||||
]
|
||||
]
|
||||
}
|
||||
pub fn versions(versions: &crate::state::Version) -> Node<Msg> {
|
||||
debug!("versions {versions:?}");
|
||||
pub fn view_versions(versions: &Version) -> Node<Msg> {
|
||||
aside![
|
||||
C!["p-2"],
|
||||
p![C!["uppercase", "font-bold"], "Versions"],
|
||||
@@ -1279,11 +1557,10 @@ pub fn versions(versions: &crate::state::Version) -> Node<Msg> {
|
||||
|
||||
fn click_to_top() -> Node<Msg> {
|
||||
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![i![C!["fas", "fa-arrow-turn-up"]]],
|
||||
ev(Ev::Click, |_| web_sys::window()
|
||||
.unwrap()
|
||||
.scroll_to_with_x_and_y(0., 0.))
|
||||
ev(Ev::Click, |_| Msg::ScrollToTop)
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user