cob: Refactor `Thread` methods
This commit is contained in:
parent
e01838a70a
commit
bb3787258a
|
|
@ -97,9 +97,10 @@ fn comment(
|
||||||
store::Error::NotFound(_, _) => anyhow::anyhow!("Could not find issue {}", options.id),
|
store::Error::NotFound(_, _) => anyhow::anyhow!("Could not find issue {}", options.id),
|
||||||
_ => e.into(),
|
_ => e.into(),
|
||||||
})?;
|
})?;
|
||||||
let (comment_id, _) = issue.root().expect("root comment always exists");
|
let (comment_id, _) = issue.comments().next().expect("root comment always exists");
|
||||||
|
|
||||||
issue.comment(message, *comment_id, &signer)?;
|
issue.comment(message, *comment_id, &signer)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -353,7 +353,7 @@ impl Revision {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn description(&self) -> Option<&str> {
|
pub fn description(&self) -> Option<&str> {
|
||||||
let (_, comment) = self.discussion.root()?;
|
let (_, comment) = self.discussion.first()?;
|
||||||
Some(comment.body())
|
Some(comment.body())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -203,11 +203,12 @@ impl Thread {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn root(&self) -> Option<(&CommentId, &Comment)> {
|
pub fn first(&self) -> Option<(&CommentId, &Comment)> {
|
||||||
self.comments
|
self.comments().next()
|
||||||
.iter()
|
}
|
||||||
.filter_map(|(id, r)| r.get().map(|comment| (id, comment)))
|
|
||||||
.next()
|
pub fn last(&self) -> Option<(&CommentId, &Comment)> {
|
||||||
|
self.comments().next_back()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn replies<'a>(
|
pub fn replies<'a>(
|
||||||
|
|
@ -235,14 +236,10 @@ impl Thread {
|
||||||
.map(|(a, r)| (a, r))
|
.map(|(a, r)| (a, r))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn comments(&self) -> impl Iterator<Item = (&CommentId, &Comment)> + '_ {
|
pub fn comments(&self) -> impl DoubleEndedIterator<Item = (&CommentId, &Comment)> + '_ {
|
||||||
self.comments.iter().filter_map(|(id, comment)| {
|
self.comments
|
||||||
if let Redactable::Present(c) = comment {
|
.iter()
|
||||||
Some((id, c))
|
.filter_map(|(id, comment)| comment.get().map(|comment| (id, comment)))
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue