Support for comment nesting with a tree structure
This commit is contained in:
parent
eda3567c1a
commit
5e0c84aec7
|
@ -577,6 +577,12 @@ dependencies = [
|
|||
"subtle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
|
||||
|
||||
[[package]]
|
||||
name = "encoding_rs"
|
||||
version = "0.8.32"
|
||||
|
@ -1322,6 +1328,15 @@ dependencies = [
|
|||
"phf 0.11.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.6"
|
||||
|
@ -1444,6 +1459,7 @@ version = "0.2.0"
|
|||
dependencies = [
|
||||
"chrono",
|
||||
"html2pango",
|
||||
"itertools",
|
||||
"lemmy_api_common",
|
||||
"markdown",
|
||||
"mime_guess",
|
||||
|
|
|
@ -16,3 +16,4 @@ rand = "0.8.5"
|
|||
mime_guess = "2.0.4"
|
||||
chrono = "0.4.26"
|
||||
timeago = "0.4.1"
|
||||
itertools = "0.11.0"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use crate::settings;
|
||||
use itertools::Itertools;
|
||||
use lemmy_api_common::{
|
||||
comment::{GetComments, GetCommentsResponse},
|
||||
lemmy_db_schema::{
|
||||
|
@ -10,8 +12,6 @@ use lemmy_api_common::{
|
|||
},
|
||||
};
|
||||
|
||||
use crate::settings;
|
||||
|
||||
pub fn get_post(id: PostId) -> Result<GetPostResponse, reqwest::Error> {
|
||||
let params = GetPost {
|
||||
id: Some(id),
|
||||
|
@ -27,6 +27,7 @@ pub fn get_comments(post_id: PostId) -> Result<Vec<CommentView>, reqwest::Error>
|
|||
post_id: Some(post_id),
|
||||
sort: Some(CommentSortType::Hot),
|
||||
type_: Some(ListingType::All),
|
||||
max_depth: Some(8),
|
||||
auth: settings::get_current_account().jwt,
|
||||
..Default::default()
|
||||
};
|
||||
|
@ -36,7 +37,20 @@ pub fn get_comments(post_id: PostId) -> Result<Vec<CommentView>, reqwest::Error>
|
|||
// hide removed and deleted comments
|
||||
comments.retain(|c| !c.comment.deleted && !c.comment.removed);
|
||||
|
||||
Ok(comments)
|
||||
// group comments by their parent and generate the tree structure known from the web interface
|
||||
let mut grouped_comments: Vec<CommentView> = vec![];
|
||||
for (_, comments_group) in &comments
|
||||
.iter()
|
||||
.group_by(|a| a.comment.path.split(".").collect::<Vec<&str>>()[1].to_owned())
|
||||
{
|
||||
let mut group = comments_group.collect::<Vec<&CommentView>>();
|
||||
group.sort_by(|a, b| a.comment.path.partial_cmp(&b.comment.path).unwrap());
|
||||
for c in group {
|
||||
grouped_comments.push(c.clone());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(grouped_comments)
|
||||
}
|
||||
|
||||
pub fn default_post() -> GetPostResponse {
|
||||
|
|
|
@ -48,9 +48,11 @@ impl FactoryComponent for CommentRow {
|
|||
set_orientation: gtk::Orientation::Vertical,
|
||||
set_spacing: 10,
|
||||
set_margin_end: 10,
|
||||
set_margin_start: 10,
|
||||
set_margin_start: ((self.comment.comment.path.matches('.').count() - 1) * 20 + 10) as i32,
|
||||
set_margin_top: 10,
|
||||
|
||||
gtk::Separator {},
|
||||
|
||||
gtk::Box {
|
||||
set_orientation: gtk::Orientation::Horizontal,
|
||||
set_spacing: 10,
|
||||
|
@ -107,8 +109,6 @@ impl FactoryComponent for CommentRow {
|
|||
set_visible: self.comment.creator.id.0 == settings::get_current_account().id,
|
||||
}
|
||||
},
|
||||
|
||||
gtk::Separator {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -176,8 +176,6 @@ impl SimpleComponent for PostPage {
|
|||
}
|
||||
},
|
||||
|
||||
gtk::Separator {},
|
||||
|
||||
#[local_ref]
|
||||
comments -> gtk::Box {
|
||||
set_orientation: gtk::Orientation::Vertical,
|
||||
|
|
Loading…
Reference in New Issue