Add padding for responses in comments, to let threads appear

Fixes #144
This commit is contained in:
Bat
2018-07-25 18:18:41 +02:00
parent 4e07fdbd05
commit 44172b67d5
6 changed files with 37 additions and 21 deletions
+5 -1
View File
@@ -69,13 +69,17 @@ impl Comment {
.len()
}
pub fn to_json(&self, conn: &PgConnection) -> serde_json::Value {
pub fn to_json(&self, conn: &PgConnection, others: &Vec<Comment>) -> serde_json::Value {
let mut json = serde_json::to_value(self).unwrap();
json["author"] = self.get_author(conn).to_json(conn);
let mentions = Mention::list_for_comment(conn, self.id).into_iter()
.map(|m| m.get_mentioned(conn).map(|u| u.get_fqn(conn)).unwrap_or(String::new()))
.collect::<Vec<String>>();
json["mentions"] = serde_json::to_value(mentions).unwrap();
json["responses"] = json!(others.into_iter()
.filter(|c| c.in_response_to_id.map(|id| id == self.id).unwrap_or(false))
.map(|c| c.to_json(conn, others))
.collect::<Vec<_>>());
json
}