summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Reeder <colin@vpzom.click>2020-10-28 09:37:33 -0600
committerColin Reeder <colin@vpzom.click>2020-10-28 09:37:33 -0600
commitecc07534b643c8554b2e82c658c16728678c8d7c (patch)
treea1eb8367390b1671d3d8f0fa338450f8fcd7615f
parent4dc802727bf8e1f7570406373143a4883d773d86 (diff)
Include comment scores in output (#117)
-rw-r--r--src/routes/api/comments.rs3
-rw-r--r--src/routes/api/mod.rs6
-rw-r--r--src/routes/api/posts.rs5
3 files changed, 9 insertions, 5 deletions
diff --git a/src/routes/api/comments.rs b/src/routes/api/comments.rs
index 0c91b97..34b1de4 100644
--- a/src/routes/api/comments.rs
+++ b/src/routes/api/comments.rs
@@ -39,7 +39,7 @@ async fn route_unstable_comments_get(
let (row, your_vote) = futures::future::try_join(
db.query_opt(
- "SELECT reply.author, reply.post, reply.content_text, reply.created, reply.local, reply.content_html, person.username, person.local, person.ap_id, post.title, reply.deleted, reply.parent, person.avatar, reply.attachment_href FROM reply INNER JOIN post ON (reply.post = post.id) LEFT OUTER JOIN person ON (reply.author = person.id) WHERE reply.id = $1",
+ "SELECT reply.author, reply.post, reply.content_text, reply.created, reply.local, reply.content_html, person.username, person.local, person.ap_id, post.title, reply.deleted, reply.parent, person.avatar, reply.attachment_href, (SELECT COUNT(*) FROM reply_like WHERE reply = reply.id) FROM reply INNER JOIN post ON (reply.post = post.id) LEFT OUTER JOIN person ON (reply.author = person.id) WHERE reply.id = $1",
&[&comment_id],
)
.map_err(crate::Error::from),
@@ -122,6 +122,7 @@ async fn route_unstable_comments_get(
local: row.get(4),
has_replies: !replies.is_empty(),
replies: Some(replies),
+ score: row.get(14),
your_vote,
},
parent: row.get::<_, Option<_>>(11).map(|id| super::JustID {
diff --git a/src/routes/api/mod.rs b/src/routes/api/mod.rs
index e6f41e5..13fbd33 100644
--- a/src/routes/api/mod.rs
+++ b/src/routes/api/mod.rs
@@ -134,6 +134,7 @@ struct RespPostCommentInfo<'a> {
local: bool,
replies: Option<Vec<RespPostCommentInfo<'a>>>,
has_replies: bool,
+ score: i64,
#[serde(skip_serializing_if = "Option::is_none")]
your_vote: Option<Option<crate::Empty>>,
}
@@ -636,7 +637,7 @@ async fn get_comments_replies<'a>(
) -> Result<HashMap<CommentLocalID, Vec<RespPostCommentInfo<'a>>>, crate::Error> {
use futures::TryStreamExt;
- let sql1 = "SELECT reply.id, reply.author, reply.content_text, reply.created, reply.parent, reply.content_html, person.username, person.local, person.ap_id, reply.deleted, person.avatar, reply.attachment_href, reply.local";
+ let sql1 = "SELECT reply.id, reply.author, reply.content_text, reply.created, reply.parent, reply.content_html, person.username, person.local, person.ap_id, reply.deleted, person.avatar, reply.attachment_href, reply.local, (SELECT COUNT(*) FROM reply_like WHERE reply = reply.id)";
let (sql2, values): (_, Vec<&(dyn tokio_postgres::types::ToSql + Sync)>) =
if include_your_for.is_some() {
(
@@ -705,9 +706,10 @@ async fn get_comments_replies<'a>(
local: row.get(12),
replies: None,
has_replies: false,
+ score: row.get(13),
your_vote: match include_your_for {
None => None,
- Some(_) => Some(if row.get(13) {
+ Some(_) => Some(if row.get(14) {
Some(crate::Empty {})
} else {
None
diff --git a/src/routes/api/posts.rs b/src/routes/api/posts.rs
index 0ca17da..731b979 100644
--- a/src/routes/api/posts.rs
+++ b/src/routes/api/posts.rs
@@ -16,7 +16,7 @@ async fn get_post_comments<'a>(
) -> Result<Vec<RespPostCommentInfo<'a>>, crate::Error> {
use futures::TryStreamExt;
- let sql1 = "SELECT reply.id, reply.author, reply.content_text, reply.created, reply.content_html, person.username, person.local, person.ap_id, reply.deleted, person.avatar, attachment_href, reply.local";
+ let sql1 = "SELECT reply.id, reply.author, reply.content_text, reply.created, reply.content_html, person.username, person.local, person.ap_id, reply.deleted, person.avatar, attachment_href, reply.local, (SELECT COUNT(*) FROM reply_like WHERE reply = reply.id)";
let (sql2, values): (_, Vec<&(dyn tokio_postgres::types::ToSql + Sync)>) =
if include_your_for.is_some() {
(
@@ -84,9 +84,10 @@ async fn get_post_comments<'a>(
local: row.get(11),
replies: None,
has_replies: false,
+ score: row.get(12),
your_vote: match include_your_for {
None => None,
- Some(_) => Some(if row.get(12) {
+ Some(_) => Some(if row.get(13) {
Some(crate::Empty {})
} else {
None