diff options
-rw-r--r-- | migrations/2018-05-25-161939_add_closed_to_index/down.sql | 30 | ||||
-rw-r--r-- | migrations/2018-05-25-161939_add_closed_to_index/up.sql | 35 | ||||
-rw-r--r-- | src/models.rs | 2 | ||||
-rw-r--r-- | src/render.rs | 4 | ||||
-rw-r--r-- | src/schema.rs | 2 |
5 files changed, 73 insertions, 0 deletions
diff --git a/migrations/2018-05-25-161939_add_closed_to_index/down.sql b/migrations/2018-05-25-161939_add_closed_to_index/down.sql new file mode 100644 index 000000000000..1063fdc88224 --- /dev/null +++ b/migrations/2018-05-25-161939_add_closed_to_index/down.sql @@ -0,0 +1,30 @@ +-- Update the index view: +DROP VIEW thread_index; +CREATE VIEW thread_index AS + SELECT t.id AS thread_id, + t.title AS title, + ta.name AS thread_author, + t.posted AS created, + t.sticky AS sticky, + p.id AS post_id, + pa.name AS post_author, + p.posted AS posted + FROM threads t + JOIN (SELECT DISTINCT ON (thread_id) + id, thread_id, user_id, posted + FROM posts + ORDER BY thread_id, id DESC) AS p + ON t.id = p.thread_id + JOIN users ta ON ta.id = t.user_id + JOIN users pa ON pa.id = p.user_id + ORDER BY t.sticky DESC, p.id DESC; + +-- Update the post view: +DROP VIEW simple_posts; +CREATE VIEW simple_posts AS + SELECT p.id AS id, + thread_id, body, posted, user_id, + users.name AS author_name, + users.email AS author_email + FROM posts p + JOIN users ON users.id = p.user_id; diff --git a/migrations/2018-05-25-161939_add_closed_to_index/up.sql b/migrations/2018-05-25-161939_add_closed_to_index/up.sql new file mode 100644 index 000000000000..87580a2f3f9e --- /dev/null +++ b/migrations/2018-05-25-161939_add_closed_to_index/up.sql @@ -0,0 +1,35 @@ +-- Update the index view: +DROP VIEW thread_index; +CREATE VIEW thread_index AS + SELECT t.id AS thread_id, + t.title AS title, + ta.name AS thread_author, + t.posted AS created, + t.sticky AS sticky, + t.closed AS closed, + p.id AS post_id, + pa.name AS post_author, + p.posted AS posted + FROM threads t + JOIN (SELECT DISTINCT ON (thread_id) + id, thread_id, user_id, posted + FROM posts + ORDER BY thread_id, id DESC) AS p + ON t.id = p.thread_id + JOIN users ta ON ta.id = t.user_id + JOIN users pa ON pa.id = p.user_id + ORDER BY t.sticky DESC, p.id DESC; + +-- Update post view: +DROP VIEW simple_posts; +CREATE VIEW simple_posts AS + SELECT p.id AS id, + thread_id, body, + p.posted AS posted, + p.user_id AS user_id, + threads.closed AS closed, + users.name AS author_name, + users.email AS author_email + FROM posts p + JOIN users ON users.id = p.user_id + JOIN threads ON threads.id = p.thread_id; diff --git a/src/models.rs b/src/models.rs index 006596fd8331..eab90b30f601 100644 --- a/src/models.rs +++ b/src/models.rs @@ -63,6 +63,7 @@ pub struct SimplePost { pub body: String, pub posted: DateTime<Utc>, pub user_id: i32, + pub closed: bool, pub author_name: String, pub author_email: String, } @@ -77,6 +78,7 @@ pub struct ThreadIndex { pub thread_author: String, pub created: DateTime<Utc>, pub sticky: bool, + pub closed: bool, pub post_id: i32, pub post_author: String, pub posted: DateTime<Utc>, diff --git a/src/render.rs b/src/render.rs index 223a3bd4524f..c209384b719e 100644 --- a/src/render.rs +++ b/src/render.rs @@ -58,6 +58,7 @@ struct IndexThread { id: i32, title: String, sticky: bool, + closed: bool, posted: FormattedDate, author_name: String, post_author: String, @@ -79,6 +80,7 @@ impl Handler<IndexPage> for Renderer { id: thread.thread_id, title: thread.title, // escape_html(&thread.title), sticky: thread.sticky, + closed: thread.closed, posted: FormattedDate(thread.posted), author_name: thread.thread_author, post_author: thread.post_author, @@ -119,6 +121,7 @@ struct RenderablePost { struct RenderableThreadPage { id: i32, title: String, + closed: bool, posts: Vec<RenderablePost>, } @@ -145,6 +148,7 @@ fn prepare_thread(comrak: &ComrakOptions, page: ThreadPage) -> RenderableThreadP RenderableThreadPage { posts, + closed: page.thread.closed, id: page.thread.id, title: page.thread.title, } diff --git a/src/schema.rs b/src/schema.rs index f163f4b1e7ea..683aa6055d9e 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -54,6 +54,7 @@ table! { body -> Text, posted -> Timestamptz, user_id -> Int4, + closed -> Bool, author_name -> Text, author_email -> Text, } @@ -67,6 +68,7 @@ table! { thread_author -> Text, created -> Timestamptz, sticky -> Bool, + closed -> Bool, post_id -> Int4, post_author -> Text, posted -> Timestamptz, |