Compare commits

...

5 Commits

10 changed files with 103 additions and 18 deletions

6
Cargo.lock generated
View File

@ -222,15 +222,14 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.28"
version = "0.4.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95ed24df0632f708f5f6d8082675bef2596f7084dee3dd55f632290bf35bfe0f"
checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38"
dependencies = [
"android-tzdata",
"iana-time-zone",
"js-sys",
"num-traits",
"time 0.1.45",
"wasm-bindgen",
"windows-targets",
]
@ -1243,6 +1242,7 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
name = "letterbox"
version = "0.1.0"
dependencies = [
"chrono",
"console_error_panic_hook",
"console_log",
"css-inline",

View File

@ -2,6 +2,7 @@
name = "server"
version = "0.1.0"
edition = "2021"
default-bin = "server"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -13,6 +13,8 @@ use rocket::{
Response, State,
};
use rocket_cors::{AllowedHeaders, AllowedOrigins};
use server::{error::ServerError, nm::threadset_to_messages};
use shared::Message;
#[get("/")]
fn hello() -> &'static str {
@ -56,9 +58,9 @@ async fn search(
async fn show_pretty(
nm: &State<Notmuch>,
query: &str,
) -> Result<Json<ThreadSet>, Debug<NotmuchError>> {
let query = urlencoding::decode(query).map_err(NotmuchError::from)?;
let res = nm.show(&query)?;
) -> Result<Json<Vec<Message>>, Debug<ServerError>> {
let query = urlencoding::decode(query).map_err(|e| ServerError::from(NotmuchError::from(e)))?;
let res = threadset_to_messages(nm.show(&query).map_err(ServerError::from)?)?;
Ok(Json(res))
}

9
server/src/error.rs Normal file
View File

@ -0,0 +1,9 @@
use thiserror::Error;
#[derive(Error, Debug)]
pub enum ServerError {
#[error("notmuch")]
NotmuchError(#[from] notmuch::NotmuchError),
#[error("flatten")]
FlattenError,
}

2
server/src/lib.rs Normal file
View File

@ -0,0 +1,2 @@
pub mod error;
pub mod nm;

13
server/src/nm.rs Normal file
View 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())
}

View File

@ -9,3 +9,6 @@ pub struct SearchResult {
pub results_per_page: usize,
pub total: usize,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Message {}

View File

@ -27,6 +27,7 @@ itertools = "0.10.5"
serde_json = { version = "1.0.93", features = ["unbounded_depth"] }
wasm-timer = "0.2.5"
css-inline = "0.8.5"
chrono = "0.4.31"
[package.metadata.wasm-pack.profile.release]
wasm-opt = ['-Os']

View File

@ -6,7 +6,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<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="icon" href="https://static.xinu.tv/favicon/letterbox.svg" />
<style>
.message {
padding: 0.5em;*/
}
@ -37,7 +39,7 @@ iframe {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
width: 15em;
width: 10em;
}
.index .subject {
overflow: hidden;
@ -45,8 +47,9 @@ iframe {
white-space: nowrap;
}
.index .date {
width: 8em;
width: 6em;
white-space: nowrap;
text-align: right;
}
.footer {
background-color: #eee;
@ -91,6 +94,30 @@ input, .input {
input::placeholder, .input::placeholder{
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>
</head>

View File

@ -7,6 +7,7 @@ use std::{
hash::{Hash, Hasher},
};
use chrono::{DateTime, Datelike, Duration, Local, Utc};
use itertools::Itertools;
use log::{debug, error, info, Level};
use notmuch::{Content, Part, Thread, ThreadNode, ThreadSet};
@ -481,6 +482,28 @@ fn pretty_authors(authors: &str) -> impl Iterator<Item = Node<Msg>> + '_ {
)
}
fn human_age(timestamp: i64) -> String {
let now = Local::now();
let ts = DateTime::<Utc>::from_timestamp(timestamp, 0)
.unwrap()
.with_timezone(&Local);
let age = now - ts;
let weekday = now.weekday();
let datetime = if age < Duration::minutes(1) {
format!("{} ago", age.num_seconds())
} else if age < Duration::hours(1) {
format!("{} ago", age.num_minutes())
} else if age < Duration::days(1) {
ts.format("%H:%M").to_string()
} else if age < Duration::weeks(1) {
ts.format("%a %H:%M").to_string()
} else {
ts.format("%b %e").to_string()
};
info!("dateime {datetime} TZ: {}", ts.offset());
datetime
}
fn view_mobile_search_results(query: &str, search_results: &shared::SearchResult) -> Node<Msg> {
if query.is_empty() {
set_title("all mail");
@ -503,21 +526,24 @@ fn view_mobile_search_results(query: &str, search_results: &shared::SearchResult
]
*/
let tid = r.thread.clone();
let datetime = human_age(r.timestamp as i64);
div![
C!["row"],
div![
C!["subject"],
&r.subject,
ev(Ev::Click, move |_| Msg::ShowPrettyRequest(tid)),
],
span![C!["from", "is-size-7"], pretty_authors(&r.authors)],
div![
span![C!["from"], pretty_authors(&r.authors)],
span![C!["tags"], tags_chiclet(&r.tags, true)],
],
span![C!["date"], &r.date_relative],
span![C!["is-size-7"], tags_chiclet(&r.tags, true)],
span![C!["is-size-7", "float-right", "date"], datetime]
]
]
});
let first = search_results.page * search_results.results_per_page;
div![
C!["search-results"],
h1!["Search results"],
view_search_pager(first, summaries.len(), search_results.total),
rows,
@ -534,6 +560,7 @@ fn view_search_results(query: &str, search_results: &shared::SearchResult) -> No
let summaries = &search_results.summary.0;
let rows = summaries.iter().map(|r| {
let tid = r.thread.clone();
let datetime = human_age(r.timestamp as i64);
tr![
td![
C!["from"],
@ -552,7 +579,7 @@ fn view_search_results(query: &str, search_results: &shared::SearchResult) -> No
&r.subject,
]
],
td![C!["date"], &r.date_relative]
td![C!["date"], datetime]
]
});
let first = search_results.page * search_results.results_per_page;