Add padding for responses in comments, to let threads appear
Fixes #144
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user