Compare commits
25 Commits
server-sid
...
2a24a20529
| Author | SHA1 | Date | |
|---|---|---|---|
| 2a24a20529 | |||
| e6692059b4 | |||
| a7b172099b | |||
| f52a76dba3 | |||
| 43e4334890 | |||
| 1d00bdb757 | |||
| 6901c9fde9 | |||
| 6251c54873 | |||
| f6c1835b18 | |||
| 95976c2860 | |||
| 01589d7136 | |||
| a2664473c8 | |||
| da15ef0f15 | |||
| 035508f3ad | |||
| 69558f15b4 | |||
| a8f538eddf | |||
| 01e5ea14ab | |||
| 042d475c75 | |||
| dd0af52feb | |||
| 130f9bbeba | |||
| 0a05b32a7a | |||
| c3f897c61a | |||
| c62bac037f | |||
| 79a57f3082 | |||
| c33de9d754 |
1701
Cargo.lock
generated
1701
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,5 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
|
resolver = "2"
|
||||||
members = [
|
members = [
|
||||||
"web",
|
"web",
|
||||||
"server",
|
"server",
|
||||||
|
|||||||
4
dev.sh
4
dev.sh
@@ -1,7 +1,7 @@
|
|||||||
cd -- "$( dirname -- "${BASH_SOURCE[0]}" )"
|
cd -- "$( dirname -- "${BASH_SOURCE[0]}" )"
|
||||||
tmux new-session -d -s letterbox-dev
|
tmux new-session -d -s letterbox-dev
|
||||||
tmux rename-window web
|
tmux rename-window web
|
||||||
tmux send-keys "cd web; trunk serve --release --address 0.0.0.0 --port 6758 --proxy-backend http://localhost:9345/ --proxy-rewrite=/api/ -w ../shared -w ../notmuch -w ./" C-m
|
tmux send-keys "cd web; trunk serve -w ../shared -w ../notmuch -w ./" C-m
|
||||||
tmux new-window -n server
|
tmux new-window -n server
|
||||||
tmux send-keys "cd server; cargo watch -x run -w ../shared -w ../notmuch -w ./" C-m
|
tmux send-keys "cd server; cargo watch -c -x run -w ../shared -w ../notmuch -w ./" C-m
|
||||||
tmux attach -d -t letterbox-dev
|
tmux attach -d -t letterbox-dev
|
||||||
|
|||||||
@@ -454,6 +454,8 @@ pub enum NotmuchError {
|
|||||||
SerdeJson(#[from] serde_json::Error),
|
SerdeJson(#[from] serde_json::Error),
|
||||||
#[error("failed to parse bytes as str")]
|
#[error("failed to parse bytes as str")]
|
||||||
Utf8Error(#[from] std::str::Utf8Error),
|
Utf8Error(#[from] std::str::Utf8Error),
|
||||||
|
#[error("failed to parse bytes as String")]
|
||||||
|
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),
|
||||||
}
|
}
|
||||||
@@ -478,6 +480,11 @@ impl Notmuch {
|
|||||||
self.run_notmuch(std::iter::empty::<&str>())
|
self.run_notmuch(std::iter::empty::<&str>())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn tags(&self) -> Result<Vec<String>, NotmuchError> {
|
||||||
|
let res = self.run_notmuch(["search", "--format=json", "--output=tags", "*"])?;
|
||||||
|
Ok(serde_json::from_slice(&res)?)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn search(
|
pub fn search(
|
||||||
&self,
|
&self,
|
||||||
query: &str,
|
query: &str,
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
name = "server"
|
name = "server"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
default-bin = "server"
|
||||||
|
|
||||||
# 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]
|
||||||
rocket = { version = "0.5.0-rc.2", features = [ "json" ] }
|
rocket = { version = "0.5.0-rc.2", features = [ "json" ] }
|
||||||
rocket_cors = { git = "https://github.com/lawliet89/rocket_cors", branch = "master" }
|
|
||||||
notmuch = { path = "../notmuch" }
|
notmuch = { path = "../notmuch" }
|
||||||
shared = { path = "../shared" }
|
shared = { path = "../shared" }
|
||||||
serde_json = "1.0.87"
|
serde_json = "1.0.87"
|
||||||
@@ -16,6 +16,10 @@ serde = { version = "1.0.147", features = ["derive"] }
|
|||||||
log = "0.4.17"
|
log = "0.4.17"
|
||||||
tokio = "1.26.0"
|
tokio = "1.26.0"
|
||||||
glog = "0.1.0"
|
glog = "0.1.0"
|
||||||
|
urlencoding = "2.1.3"
|
||||||
|
async-graphql = "6.0.11"
|
||||||
|
async-graphql-rocket = "6.0.11"
|
||||||
|
rocket_cors = "0.6.0"
|
||||||
|
|
||||||
[dependencies.rocket_contrib]
|
[dependencies.rocket_contrib]
|
||||||
version = "0.4.11"
|
version = "0.4.11"
|
||||||
|
|||||||
@@ -1,23 +1,24 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
|
|
||||||
use std::{error::Error, io::Cursor, str::FromStr};
|
use std::{error::Error, io::Cursor, str::FromStr};
|
||||||
|
|
||||||
|
use async_graphql::{http::GraphiQLSource, EmptyMutation, EmptySubscription, Schema};
|
||||||
|
use async_graphql_rocket::{GraphQLQuery, GraphQLRequest, GraphQLResponse};
|
||||||
use glog::Flags;
|
use glog::Flags;
|
||||||
use notmuch::{Notmuch, NotmuchError, SearchSummary, ThreadSet};
|
use notmuch::{Notmuch, NotmuchError, ThreadSet};
|
||||||
use rocket::{
|
use rocket::{
|
||||||
http::{ContentType, Header},
|
http::{ContentType, Header},
|
||||||
request::Request,
|
request::Request,
|
||||||
response::{Debug, Responder},
|
response::{content, Debug, Responder},
|
||||||
serde::json::Json,
|
serde::json::Json,
|
||||||
Response, State,
|
Response, State,
|
||||||
};
|
};
|
||||||
use rocket_cors::{AllowedHeaders, AllowedOrigins};
|
use rocket_cors::{AllowedHeaders, AllowedOrigins};
|
||||||
|
use server::{
|
||||||
#[get("/")]
|
error::ServerError,
|
||||||
fn hello() -> &'static str {
|
graphql::{GraphqlSchema, QueryRoot},
|
||||||
"Hello, world!"
|
};
|
||||||
}
|
use shared::Message;
|
||||||
|
|
||||||
#[get("/refresh")]
|
#[get("/refresh")]
|
||||||
async fn refresh(nm: &State<Notmuch>) -> Result<Json<String>, Debug<NotmuchError>> {
|
async fn refresh(nm: &State<Notmuch>) -> Result<Json<String>, Debug<NotmuchError>> {
|
||||||
@@ -39,14 +40,15 @@ async fn search(
|
|||||||
results_per_page: Option<usize>,
|
results_per_page: Option<usize>,
|
||||||
) -> Result<Json<shared::SearchResult>, Debug<NotmuchError>> {
|
) -> Result<Json<shared::SearchResult>, Debug<NotmuchError>> {
|
||||||
let page = page.unwrap_or(0);
|
let page = page.unwrap_or(0);
|
||||||
let results_per_page = results_per_page.unwrap_or(10);
|
let results_per_page = results_per_page.unwrap_or(20);
|
||||||
|
let query = urlencoding::decode(query).map_err(NotmuchError::from)?;
|
||||||
info!(" search '{query}'");
|
info!(" search '{query}'");
|
||||||
let res = shared::SearchResult {
|
let res = shared::SearchResult {
|
||||||
summary: nm.search(query, page * results_per_page, results_per_page)?,
|
summary: nm.search(&query, page * results_per_page, results_per_page)?,
|
||||||
query: query.to_string(),
|
query: query.to_string(),
|
||||||
page,
|
page,
|
||||||
results_per_page,
|
results_per_page,
|
||||||
total: nm.count(query)?,
|
total: nm.count(&query)?,
|
||||||
};
|
};
|
||||||
Ok(Json(res))
|
Ok(Json(res))
|
||||||
}
|
}
|
||||||
@@ -55,14 +57,16 @@ async fn search(
|
|||||||
async fn show_pretty(
|
async fn show_pretty(
|
||||||
nm: &State<Notmuch>,
|
nm: &State<Notmuch>,
|
||||||
query: &str,
|
query: &str,
|
||||||
) -> Result<Json<ThreadSet>, Debug<NotmuchError>> {
|
) -> Result<Json<ThreadSet>, Debug<ServerError>> {
|
||||||
let res = nm.show(query)?;
|
let query = urlencoding::decode(query).map_err(|e| ServerError::from(NotmuchError::from(e)))?;
|
||||||
|
let res = nm.show(&query).map_err(ServerError::from)?;
|
||||||
Ok(Json(res))
|
Ok(Json(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/show/<query>")]
|
#[get("/show/<query>")]
|
||||||
async fn show(nm: &State<Notmuch>, query: &str) -> Result<Json<ThreadSet>, Debug<NotmuchError>> {
|
async fn show(nm: &State<Notmuch>, query: &str) -> Result<Json<ThreadSet>, Debug<NotmuchError>> {
|
||||||
let res = nm.show(query)?;
|
let query = urlencoding::decode(query).map_err(NotmuchError::from)?;
|
||||||
|
let res = nm.show(&query)?;
|
||||||
Ok(Json(res))
|
Ok(Json(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,6 +124,24 @@ async fn original(
|
|||||||
Ok((ContentType::Plain, res))
|
Ok((ContentType::Plain, res))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[rocket::get("/")]
|
||||||
|
fn graphiql() -> content::RawHtml<String> {
|
||||||
|
content::RawHtml(GraphiQLSource::build().endpoint("/graphql").finish())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[rocket::get("/graphql?<query..>")]
|
||||||
|
async fn graphql_query(schema: &State<GraphqlSchema>, query: GraphQLQuery) -> GraphQLResponse {
|
||||||
|
query.execute(schema.inner()).await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[rocket::post("/graphql", data = "<request>", format = "application/json")]
|
||||||
|
async fn graphql_request(
|
||||||
|
schema: &State<GraphqlSchema>,
|
||||||
|
request: GraphQLRequest,
|
||||||
|
) -> GraphQLResponse {
|
||||||
|
request.execute(schema.inner()).await
|
||||||
|
}
|
||||||
|
|
||||||
#[rocket::main]
|
#[rocket::main]
|
||||||
async fn main() -> Result<(), Box<dyn Error>> {
|
async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
glog::new()
|
glog::new()
|
||||||
@@ -143,21 +165,28 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
.to_cors()?;
|
.to_cors()?;
|
||||||
|
|
||||||
|
let schema = Schema::build(QueryRoot, EmptyMutation, EmptySubscription)
|
||||||
|
.data(Notmuch::default())
|
||||||
|
.finish();
|
||||||
|
|
||||||
let _ = rocket::build()
|
let _ = rocket::build()
|
||||||
.mount(
|
.mount(
|
||||||
"/",
|
"/",
|
||||||
routes![
|
routes![
|
||||||
original_part,
|
original_part,
|
||||||
original,
|
original,
|
||||||
hello,
|
|
||||||
refresh,
|
refresh,
|
||||||
search_all,
|
search_all,
|
||||||
search,
|
search,
|
||||||
show_pretty,
|
show_pretty,
|
||||||
show
|
show,
|
||||||
|
graphql_query,
|
||||||
|
graphql_request,
|
||||||
|
graphiql
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.attach(cors)
|
.attach(cors)
|
||||||
|
.manage(schema)
|
||||||
.manage(Notmuch::default())
|
.manage(Notmuch::default())
|
||||||
//.manage(Notmuch::with_config("../notmuch/testdata/notmuch.config"))
|
//.manage(Notmuch::with_config("../notmuch/testdata/notmuch.config"))
|
||||||
.launch()
|
.launch()
|
||||||
9
server/src/error.rs
Normal file
9
server/src/error.rs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
|
#[derive(Error, Debug)]
|
||||||
|
pub enum ServerError {
|
||||||
|
#[error("notmuch")]
|
||||||
|
NotmuchError(#[from] notmuch::NotmuchError),
|
||||||
|
#[error("flatten")]
|
||||||
|
FlattenError,
|
||||||
|
}
|
||||||
147
server/src/graphql.rs
Normal file
147
server/src/graphql.rs
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
use std::hash::{DefaultHasher, Hash, Hasher};
|
||||||
|
|
||||||
|
use async_graphql::{
|
||||||
|
connection::{self, Connection, Edge},
|
||||||
|
Context, EmptyMutation, EmptySubscription, Error, FieldResult, Object, Schema, SimpleObject,
|
||||||
|
};
|
||||||
|
use log::info;
|
||||||
|
use notmuch::Notmuch;
|
||||||
|
|
||||||
|
pub struct QueryRoot;
|
||||||
|
|
||||||
|
/// # Number of seconds since the Epoch
|
||||||
|
pub type UnixTime = isize;
|
||||||
|
|
||||||
|
/// # Thread ID, sans "thread:"
|
||||||
|
pub type ThreadId = String;
|
||||||
|
|
||||||
|
#[derive(Debug, SimpleObject)]
|
||||||
|
pub struct ThreadSummary {
|
||||||
|
pub thread: ThreadId,
|
||||||
|
pub timestamp: UnixTime,
|
||||||
|
/// user-friendly timestamp
|
||||||
|
pub date_relative: String,
|
||||||
|
/// number of matched messages
|
||||||
|
pub matched: isize,
|
||||||
|
/// total messages in thread
|
||||||
|
pub total: isize,
|
||||||
|
/// comma-separated names with | between matched and unmatched
|
||||||
|
pub authors: String,
|
||||||
|
pub subject: String,
|
||||||
|
pub tags: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(SimpleObject)]
|
||||||
|
struct Tag {
|
||||||
|
name: String,
|
||||||
|
fg_color: String,
|
||||||
|
bg_color: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Object]
|
||||||
|
impl QueryRoot {
|
||||||
|
async fn count<'ctx>(&self, ctx: &Context<'ctx>, query: String) -> Result<usize, Error> {
|
||||||
|
let nm = ctx.data_unchecked::<Notmuch>();
|
||||||
|
Ok(nm.count(&query)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn search<'ctx>(
|
||||||
|
&self,
|
||||||
|
ctx: &Context<'ctx>,
|
||||||
|
after: Option<String>,
|
||||||
|
before: Option<String>,
|
||||||
|
first: Option<i32>,
|
||||||
|
last: Option<i32>,
|
||||||
|
query: String,
|
||||||
|
) -> Result<Connection<usize, ThreadSummary>, Error> {
|
||||||
|
let nm = ctx.data_unchecked::<Notmuch>();
|
||||||
|
connection::query(
|
||||||
|
after,
|
||||||
|
before,
|
||||||
|
first,
|
||||||
|
last,
|
||||||
|
|after, before, first, last| async move {
|
||||||
|
info!("{after:?} {before:?} {first:?} {last:?} {query}");
|
||||||
|
let mut start = 0usize;
|
||||||
|
let total = nm.count(&query)?;
|
||||||
|
let page_size = first.unwrap_or(20);
|
||||||
|
|
||||||
|
if let Some(after) = after {
|
||||||
|
if after >= total {
|
||||||
|
return Ok(Connection::new(false, false));
|
||||||
|
}
|
||||||
|
start = after + 1;
|
||||||
|
}
|
||||||
|
let mut end = start + page_size;
|
||||||
|
if end > total {
|
||||||
|
end = total;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(wathiede): handle last/end.
|
||||||
|
if let Some(before) = before {
|
||||||
|
if before == 0 {
|
||||||
|
return Ok(Connection::new(false, false));
|
||||||
|
}
|
||||||
|
end = before;
|
||||||
|
}
|
||||||
|
|
||||||
|
let slice: Vec<ThreadSummary> = nm
|
||||||
|
.search(&query, start, first.unwrap_or(20))?
|
||||||
|
.0
|
||||||
|
.into_iter()
|
||||||
|
.map(|ts| ThreadSummary {
|
||||||
|
thread: ts.thread,
|
||||||
|
timestamp: ts.timestamp,
|
||||||
|
date_relative: ts.date_relative,
|
||||||
|
matched: ts.matched,
|
||||||
|
total: ts.total,
|
||||||
|
authors: ts.authors,
|
||||||
|
subject: ts.subject,
|
||||||
|
tags: ts.tags,
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
//let mut slice = &res[..];
|
||||||
|
|
||||||
|
/*
|
||||||
|
if let Some(first) = first {
|
||||||
|
slice = &slice[..first.min(slice.len())];
|
||||||
|
end -= first.min(slice.len());
|
||||||
|
} else if let Some(last) = last {
|
||||||
|
slice = &slice[slice.len() - last.min(slice.len())..];
|
||||||
|
start = end - last.min(slice.len());
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
let mut connection = Connection::new(start > 0, end < total);
|
||||||
|
connection.edges.extend(
|
||||||
|
slice
|
||||||
|
.into_iter()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(idx, item)| Edge::new(start + idx, item)),
|
||||||
|
);
|
||||||
|
Ok::<_, Error>(connection)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn tags<'ctx>(&self, ctx: &Context<'ctx>) -> FieldResult<Vec<Tag>> {
|
||||||
|
let nm = ctx.data_unchecked::<Notmuch>();
|
||||||
|
Ok(nm
|
||||||
|
.tags()?
|
||||||
|
.into_iter()
|
||||||
|
.map(|tag| {
|
||||||
|
let mut hasher = DefaultHasher::new();
|
||||||
|
tag.hash(&mut hasher);
|
||||||
|
let hex = format!("#{:06x}", hasher.finish() % (1 << 24));
|
||||||
|
Tag {
|
||||||
|
name: tag,
|
||||||
|
fg_color: "white".to_string(),
|
||||||
|
bg_color: hex,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type GraphqlSchema = Schema<QueryRoot, EmptyMutation, EmptySubscription>;
|
||||||
3
server/src/lib.rs
Normal file
3
server/src/lib.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
pub mod error;
|
||||||
|
pub mod graphql;
|
||||||
|
pub mod nm;
|
||||||
13
server/src/nm.rs
Normal file
13
server/src/nm.rs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
use shared::Message;
|
||||||
|
|
||||||
|
use crate::error;
|
||||||
|
|
||||||
|
// TODO(wathiede): decide good error type
|
||||||
|
pub fn threadset_to_messages(
|
||||||
|
thread_set: notmuch::ThreadSet,
|
||||||
|
) -> Result<Vec<Message>, error::ServerError> {
|
||||||
|
for t in thread_set.0 {
|
||||||
|
for _tn in t.0 {}
|
||||||
|
}
|
||||||
|
Ok(Vec::new())
|
||||||
|
}
|
||||||
@@ -9,3 +9,6 @@ pub struct SearchResult {
|
|||||||
pub results_per_page: usize,
|
pub results_per_page: usize,
|
||||||
pub total: usize,
|
pub total: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct Message {}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ itertools = "0.10.5"
|
|||||||
serde_json = { version = "1.0.93", features = ["unbounded_depth"] }
|
serde_json = { version = "1.0.93", features = ["unbounded_depth"] }
|
||||||
wasm-timer = "0.2.5"
|
wasm-timer = "0.2.5"
|
||||||
css-inline = "0.8.5"
|
css-inline = "0.8.5"
|
||||||
|
chrono = "0.4.31"
|
||||||
|
|
||||||
[package.metadata.wasm-pack.profile.release]
|
[package.metadata.wasm-pack.profile.release]
|
||||||
wasm-opt = ['-Os']
|
wasm-opt = ['-Os']
|
||||||
|
|||||||
11
web/Trunk.toml
Normal file
11
web/Trunk.toml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
[build]
|
||||||
|
release = true
|
||||||
|
|
||||||
|
[serve]
|
||||||
|
# The address to serve on.
|
||||||
|
address = "0.0.0.0"
|
||||||
|
port = 6758
|
||||||
|
|
||||||
|
[[proxy]]
|
||||||
|
backend = "http://localhost:9345/"
|
||||||
|
rewrite= "/api/"
|
||||||
@@ -4,18 +4,21 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
<link rel="modulepreload" href="/pkg/package.js" as="script" type="text/javascript">
|
|
||||||
<link rel="preload" href="/pkg/package_bg.wasm" as="fetch" type="application/wasm" crossorigin="anonymous">
|
|
||||||
<link rel="stylesheet", href="https://jenil.github.io/bulmaswatch/cyborg/bulmaswatch.min.css">
|
<link rel="stylesheet", href="https://jenil.github.io/bulmaswatch/cyborg/bulmaswatch.min.css">
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css" integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css" integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
||||||
|
<link rel="icon" href="https://static.xinu.tv/favicon/letterbox.svg" />
|
||||||
<style>
|
<style>
|
||||||
|
|
||||||
.message {
|
.message {
|
||||||
padding-left: 0.5em;
|
padding: 0.5em;*/
|
||||||
}
|
}
|
||||||
.body {
|
.body {
|
||||||
background: white;
|
background: white;
|
||||||
color: black;
|
color: black;
|
||||||
padding-bottom: 1em;
|
padding: 0.5em;
|
||||||
|
margin-left: -0.5em;
|
||||||
|
margin-right: -0.5em;
|
||||||
|
margin-top: 0.5em;
|
||||||
}
|
}
|
||||||
.error {
|
.error {
|
||||||
background-color: red;
|
background-color: red;
|
||||||
@@ -27,13 +30,26 @@ iframe {
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.index {
|
||||||
|
table-layout: fixed;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
.index .from {
|
.index .from {
|
||||||
width: 200px;
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
width: 10em;
|
||||||
}
|
}
|
||||||
.index .subject {
|
.index .subject {
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
.index .date {
|
.index .date {
|
||||||
|
width: 7em;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
text-align: right;
|
||||||
}
|
}
|
||||||
.footer {
|
.footer {
|
||||||
background-color: #eee;
|
background-color: #eee;
|
||||||
@@ -78,15 +94,35 @@ input, .input {
|
|||||||
input::placeholder, .input::placeholder{
|
input::placeholder, .input::placeholder{
|
||||||
color: #555;
|
color: #555;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.search-results .row {
|
||||||
|
border-bottom: 1px #444 solid;
|
||||||
|
padding-bottom: .5em;
|
||||||
|
padding-top: .5em;
|
||||||
|
}
|
||||||
|
.search-results .row .subject {
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.search-results .row .from {
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.search-results .row .tag {
|
||||||
|
height: 1.5em;
|
||||||
|
padding-left: .5em;
|
||||||
|
padding-right: .5em;
|
||||||
|
}
|
||||||
|
.float-right {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<section id="app"></section>
|
<section id="app"></section>
|
||||||
<script type="module">
|
|
||||||
import init from '/pkg/package.js';
|
|
||||||
init('/pkg/package_bg.wasm');
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use std::{
|
|||||||
hash::{Hash, Hasher},
|
hash::{Hash, Hasher},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use chrono::{DateTime, Datelike, Duration, Local, Utc};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use log::{debug, error, info, Level};
|
use log::{debug, error, info, Level};
|
||||||
use notmuch::{Content, Part, Thread, ThreadNode, ThreadSet};
|
use notmuch::{Content, Part, Thread, ThreadNode, ThreadSet};
|
||||||
@@ -22,9 +23,12 @@ const SEARCH_RESULTS_PER_PAGE: usize = 20;
|
|||||||
|
|
||||||
// `init` describes what should happen when your app started.
|
// `init` describes what should happen when your app started.
|
||||||
fn init(url: Url, orders: &mut impl Orders<Msg>) -> Model {
|
fn init(url: Url, orders: &mut impl Orders<Msg>) -> Model {
|
||||||
orders
|
if url.hash().is_none() {
|
||||||
.subscribe(on_url_changed)
|
orders.request_url(urls::search("is:unread", 0));
|
||||||
.notify(subs::UrlChanged(url.clone()));
|
} else {
|
||||||
|
orders.notify(subs::UrlRequested::new(url));
|
||||||
|
};
|
||||||
|
orders.subscribe(on_url_changed);
|
||||||
|
|
||||||
Model {
|
Model {
|
||||||
context: Context::None,
|
context: Context::None,
|
||||||
@@ -119,6 +123,9 @@ enum RefreshingState {
|
|||||||
// `Msg` describes the different events you can modify state with.
|
// `Msg` describes the different events you can modify state with.
|
||||||
enum Msg {
|
enum Msg {
|
||||||
Noop,
|
Noop,
|
||||||
|
// Tell the client to refresh its state
|
||||||
|
Reload,
|
||||||
|
// Tell the server to update state
|
||||||
RefreshStart,
|
RefreshStart,
|
||||||
RefreshDone(Option<FetchError>),
|
RefreshDone(Option<FetchError>),
|
||||||
SearchRequest {
|
SearchRequest {
|
||||||
@@ -149,6 +156,10 @@ fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
|||||||
} else {
|
} else {
|
||||||
RefreshingState::None
|
RefreshingState::None
|
||||||
};
|
};
|
||||||
|
orders.perform_cmd(async move { Msg::Reload });
|
||||||
|
}
|
||||||
|
Msg::Reload => {
|
||||||
|
orders.perform_cmd(async move { on_url_changed(subs::UrlChanged(Url::current())) });
|
||||||
}
|
}
|
||||||
|
|
||||||
Msg::SearchRequest {
|
Msg::SearchRequest {
|
||||||
@@ -315,7 +326,6 @@ fn view_message(thread: &ThreadNode) -> Node<Msg> {
|
|||||||
div![C!["header"], "From: ", &message.headers.from],
|
div![C!["header"], "From: ", &message.headers.from],
|
||||||
div![C!["header"], "Date: ", &message.headers.date],
|
div![C!["header"], "Date: ", &message.headers.date],
|
||||||
div![C!["header"], "To: ", &message.headers.to],
|
div![C!["header"], "To: ", &message.headers.to],
|
||||||
hr![],
|
|
||||||
div![
|
div![
|
||||||
C!["body"],
|
C!["body"],
|
||||||
match &message.body {
|
match &message.body {
|
||||||
@@ -352,7 +362,7 @@ fn view_part(part: &Part) -> Node<Msg> {
|
|||||||
.build();
|
.build();
|
||||||
let inlined = inliner.inline(html).expect("failed to inline CSS");
|
let inlined = inliner.inline(html).expect("failed to inline CSS");
|
||||||
|
|
||||||
return div![C!["view-part-text-html"], div!["TEST"], raw![&inlined]];
|
return div![C!["view-part-text-html"], raw![&inlined]];
|
||||||
} else {
|
} else {
|
||||||
div![
|
div![
|
||||||
C!["error"],
|
C!["error"],
|
||||||
@@ -472,6 +482,29 @@ fn pretty_authors(authors: &str) -> impl Iterator<Item = Node<Msg>> + '_ {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn human_age(timestamp: i64) -> String {
|
||||||
|
let now = Local::now();
|
||||||
|
let yesterday = now - Duration::days(1);
|
||||||
|
let ts = DateTime::<Utc>::from_timestamp(timestamp, 0)
|
||||||
|
.unwrap()
|
||||||
|
.with_timezone(&Local);
|
||||||
|
let age = now - ts;
|
||||||
|
let datetime = if age < Duration::minutes(1) {
|
||||||
|
format!("{} min. ago", age.num_seconds())
|
||||||
|
} else if age < Duration::hours(1) {
|
||||||
|
format!("{} min. ago", age.num_minutes())
|
||||||
|
} else if ts.date_naive() == now.date_naive() {
|
||||||
|
ts.format("Today %H:%M").to_string()
|
||||||
|
} else if ts.date_naive() == yesterday.date_naive() {
|
||||||
|
ts.format("Yest. %H:%M").to_string()
|
||||||
|
} else if age < Duration::weeks(1) {
|
||||||
|
ts.format("%a %H:%M").to_string()
|
||||||
|
} else {
|
||||||
|
ts.format("%b %e %H:%M").to_string()
|
||||||
|
};
|
||||||
|
datetime
|
||||||
|
}
|
||||||
|
|
||||||
fn view_mobile_search_results(query: &str, search_results: &shared::SearchResult) -> Node<Msg> {
|
fn view_mobile_search_results(query: &str, search_results: &shared::SearchResult) -> Node<Msg> {
|
||||||
if query.is_empty() {
|
if query.is_empty() {
|
||||||
set_title("all mail");
|
set_title("all mail");
|
||||||
@@ -494,22 +527,24 @@ fn view_mobile_search_results(query: &str, search_results: &shared::SearchResult
|
|||||||
]
|
]
|
||||||
*/
|
*/
|
||||||
let tid = r.thread.clone();
|
let tid = r.thread.clone();
|
||||||
|
let datetime = human_age(r.timestamp as i64);
|
||||||
div![
|
div![
|
||||||
|
C!["row"],
|
||||||
div![
|
div![
|
||||||
C!["subject"],
|
C!["subject"],
|
||||||
&r.subject,
|
&r.subject,
|
||||||
ev(Ev::Click, move |_| Msg::ShowPrettyRequest(tid)),
|
ev(Ev::Click, move |_| Msg::ShowPrettyRequest(tid)),
|
||||||
],
|
],
|
||||||
|
span![C!["from", "is-size-7"], pretty_authors(&r.authors)],
|
||||||
div![
|
div![
|
||||||
span![C!["from"], pretty_authors(&r.authors)],
|
span![C!["is-size-7"], tags_chiclet(&r.tags, true)],
|
||||||
span![C!["tags"], tags_chiclet(&r.tags, true)],
|
span![C!["is-size-7", "float-right", "date"], datetime]
|
||||||
],
|
]
|
||||||
span![C!["date"], &r.date_relative],
|
|
||||||
hr![],
|
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
let first = search_results.page * search_results.results_per_page;
|
let first = search_results.page * search_results.results_per_page;
|
||||||
div![
|
div![
|
||||||
|
C!["search-results"],
|
||||||
h1!["Search results"],
|
h1!["Search results"],
|
||||||
view_search_pager(first, summaries.len(), search_results.total),
|
view_search_pager(first, summaries.len(), search_results.total),
|
||||||
rows,
|
rows,
|
||||||
@@ -526,6 +561,7 @@ fn view_search_results(query: &str, search_results: &shared::SearchResult) -> No
|
|||||||
let summaries = &search_results.summary.0;
|
let summaries = &search_results.summary.0;
|
||||||
let rows = summaries.iter().map(|r| {
|
let rows = summaries.iter().map(|r| {
|
||||||
let tid = r.thread.clone();
|
let tid = r.thread.clone();
|
||||||
|
let datetime = human_age(r.timestamp as i64);
|
||||||
tr![
|
tr![
|
||||||
td![
|
td![
|
||||||
C!["from"],
|
C!["from"],
|
||||||
@@ -544,7 +580,7 @@ fn view_search_results(query: &str, search_results: &shared::SearchResult) -> No
|
|||||||
&r.subject,
|
&r.subject,
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
td![C!["date"], &r.date_relative]
|
td![C!["date"], datetime]
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
let first = search_results.page * search_results.results_per_page;
|
let first = search_results.page * search_results.results_per_page;
|
||||||
@@ -576,12 +612,8 @@ fn view_search_pager(start: usize, count: usize, total: usize) -> Node<Msg> {
|
|||||||
nav![
|
nav![
|
||||||
C!["pagination"],
|
C!["pagination"],
|
||||||
a![
|
a![
|
||||||
C![
|
C!["pagination-previous", "button",],
|
||||||
"pagination-previous",
|
IF!(is_first => attrs!{ At::Disabled=>true }),
|
||||||
"button",
|
|
||||||
IF!(is_first => "is-static"),
|
|
||||||
IF!(is_first => "is-info"),
|
|
||||||
],
|
|
||||||
"<",
|
"<",
|
||||||
ev(Ev::Click, |_| Msg::PreviousPage)
|
ev(Ev::Click, |_| Msg::PreviousPage)
|
||||||
],
|
],
|
||||||
@@ -606,17 +638,20 @@ fn view_thread(thread_set: &ThreadSet) -> Node<Msg> {
|
|||||||
let subject = first_subject(&thread_node).unwrap_or("<No subject>".to_string());
|
let subject = first_subject(&thread_node).unwrap_or("<No subject>".to_string());
|
||||||
set_title(&subject);
|
set_title(&subject);
|
||||||
div![
|
div![
|
||||||
h1![subject],
|
C!["container"],
|
||||||
|
h1![C!["title"], subject],
|
||||||
|
view_message(&thread_node),
|
||||||
a![
|
a![
|
||||||
attrs! {At::Href=>api::original(&thread_node.0.as_ref().expect("message missing").id)},
|
attrs! {At::Href=>api::original(&thread_node.0.as_ref().expect("message missing").id)},
|
||||||
"Original"
|
"Original"
|
||||||
],
|
],
|
||||||
view_message(&thread_node),
|
/*
|
||||||
div![
|
div![
|
||||||
C!["debug"],
|
C!["debug"],
|
||||||
"Add zippy for debug dump",
|
"Add zippy for debug dump",
|
||||||
view_debug_thread_set(thread_set)
|
view_debug_thread_set(thread_set)
|
||||||
] /* pre![format!("Thread: {:#?}", thread_set).replace(" ", " ")] */
|
] /* pre![format!("Thread: {:#?}", thread_set).replace(" ", " ")] */
|
||||||
|
*/
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -730,7 +765,8 @@ fn view_desktop(model: &Model) -> Node<Msg> {
|
|||||||
};
|
};
|
||||||
div![
|
div![
|
||||||
view_header(&model.query, &model.refreshing_state),
|
view_header(&model.query, &model.refreshing_state),
|
||||||
section![C!["section"], div![C!["container"], content],]
|
section![C!["section"], content],
|
||||||
|
view_header(&model.query, &model.refreshing_state),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -742,7 +778,8 @@ fn view_mobile(model: &Model) -> Node<Msg> {
|
|||||||
};
|
};
|
||||||
div![
|
div![
|
||||||
view_header(&model.query, &model.refreshing_state),
|
view_header(&model.query, &model.refreshing_state),
|
||||||
section![C!["section"], div![C!["content"], content],]
|
section![C!["section"], div![C!["content"], content]],
|
||||||
|
view_header(&model.query, &model.refreshing_state),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user