Fix new post read/unread handling

This commit is contained in:
Bill Thiede 2024-08-31 13:49:03 -07:00
parent a9e6120f81
commit e73f70af8f
5 changed files with 21 additions and 3 deletions

View File

@ -41,6 +41,7 @@ pub enum Thread {
#[derive(Debug, SimpleObject)] #[derive(Debug, SimpleObject)]
pub struct NewsPost { pub struct NewsPost {
pub thread_id: String, pub thread_id: String,
pub is_read: bool,
pub slug: String, pub slug: String,
pub site: String, pub site: String,
pub title: String, pub title: String,

View File

@ -207,6 +207,7 @@ pub async fn thread(pool: &PgPool, thread_id: String) -> Result<Thread, ServerEr
} }
} }
let title = clean_title(&r.title.unwrap_or("NO TITLE".to_string())).await?; let title = clean_title(&r.title.unwrap_or("NO TITLE".to_string())).await?;
let is_read = r.is_read.unwrap_or(false);
let timestamp = r let timestamp = r
.date .date
.expect("post missing date") .expect("post missing date")
@ -214,6 +215,7 @@ pub async fn thread(pool: &PgPool, thread_id: String) -> Result<Thread, ServerEr
.unix_timestamp(); .unix_timestamp();
Ok(Thread::News(NewsPost { Ok(Thread::News(NewsPost {
thread_id, thread_id,
is_read,
slug, slug,
site, site,
title, title,

View File

@ -878,6 +878,22 @@
} }
} }
}, },
{
"args": [],
"deprecationReason": null,
"description": null,
"isDeprecated": false,
"name": "isRead",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Boolean",
"ofType": null
}
}
},
{ {
"args": [], "args": [],
"deprecationReason": null, "deprecationReason": null,

View File

@ -2,6 +2,7 @@ query ShowThreadQuery($threadId: String!) {
thread(threadId: $threadId) { thread(threadId: $threadId) {
__typename ... on NewsPost{ __typename ... on NewsPost{
threadId threadId
isRead
slug slug
site site
title title

View File

@ -1131,9 +1131,7 @@ fn render_news_post_header(post: &ShowThreadQueryThreadOnNewsPost) -> Node<Msg>
let avatar: Option<String> = None; let avatar: Option<String> = None;
//let avatar: Option<String> = Some(String::from("https://bulma.io/images/placeholders/64x64.png")); //let avatar: Option<String> = Some(String::from("https://bulma.io/images/placeholders/64x64.png"));
let id = post.thread_id.clone(); let id = post.thread_id.clone();
// TODO: plumb this through let is_unread = !post.is_read;
//let is_unread = has_unread(&msg.tags);
let is_unread = true;
let img = render_avatar(avatar, &from); let img = render_avatar(avatar, &from);
article![ article![
C!["media"], C!["media"],