diff --git a/bin/commands/patch.rs b/bin/commands/patch.rs index e0f2da8c..c1e0c650 100644 --- a/bin/commands/patch.rs +++ b/bin/commands/patch.rs @@ -343,7 +343,7 @@ mod interface { return Ok(()); }; - let (review_id, review) = if let Some((id, review)) = patch + let (review_id, _) = if let Some((id, review)) = patch .clone() .reviews_of(revision.id()) .find(|(_, review)| review.author().public_key() == signer.public_key()) @@ -376,6 +376,15 @@ mod interface { }; loop { + // Reload review + let (review_id, review) = match patch + .reviews_of(revision.id()) + .find(|(_, review)| review.author().public_key() == signer.public_key()) + { + Some((id, review)) => (id.clone(), review.clone()), + None => anyhow::bail!("Could not find review {}", review_id), + }; + log::info!( "Found comments for {review_id}: {:?}", review.comments().collect::>() diff --git a/bin/commands/patch/review.rs b/bin/commands/patch/review.rs index cf5877d8..370846c4 100644 --- a/bin/commands/patch/review.rs +++ b/bin/commands/patch/review.rs @@ -161,14 +161,14 @@ impl<'a> App<'a> { pub fn new( profile: Profile, rid: RepoId, - _review: Review, + review: Review, queue: ReviewQueue, ) -> Result { let repository = profile.storage.repository(rid)?; let queue = queue .iter() - .map(|item| HunkItem::from((&repository, item))) + .map(|item| HunkItem::from((&repository, &review, item))) .collect::>(); let mut items = HashMap::new(); diff --git a/bin/ui/items.rs b/bin/ui/items.rs index b4193474..a2e98045 100644 --- a/bin/ui/items.rs +++ b/bin/ui/items.rs @@ -10,14 +10,14 @@ use nom::{IResult, Parser}; use ansi_to_tui::IntoText; use radicle::cob::thread::{Comment, CommentId}; -use radicle::cob::{Label, ObjectId, Timestamp, TypedId}; +use radicle::cob::{CodeLocation, EntryId, Label, ObjectId, Timestamp, TypedId}; use radicle::git::Oid; use radicle::identity::{Did, Identity}; use radicle::issue; use radicle::issue::{CloseReason, Issue, IssueId, Issues}; use radicle::node::notifications::{Notification, NotificationId, NotificationKind}; use radicle::node::{Alias, AliasStore, NodeId}; -use radicle::patch; +use radicle::patch::{self, Review}; use radicle::patch::{Patch, PatchId, Patches}; use radicle::storage::git::Repository; use radicle::storage::{ReadRepository, ReadStorage, RefUpdate, WriteRepository}; @@ -1043,18 +1043,35 @@ impl<'a> Into> for TermLine { pub struct HunkItem<'a> { pub inner: IndexedHunkItem, pub highlighted: Blobs>>, + pub comments: Vec<(EntryId, Comment)>, } -impl<'a> From<(&Repository, &IndexedHunkItem)> for HunkItem<'a> { - fn from(value: (&Repository, &IndexedHunkItem)) -> Self { - let (repo, item) = value; +impl<'a> From<(&Repository, &Review, &IndexedHunkItem)> for HunkItem<'a> { + fn from(value: (&Repository, &Review, &IndexedHunkItem)) -> Self { + let (repo, review, item) = value; let hi = Highlighter::default(); + let path = match &item.1 { + crate::cob::HunkItem::FileAdded { path, .. } => path, + crate::cob::HunkItem::FileModified { path, .. } => path, + crate::cob::HunkItem::FileDeleted { path, .. } => path, + crate::cob::HunkItem::FileCopied { copied } => &copied.new_path, + crate::cob::HunkItem::FileMoved { moved } => &moved.new_path, + crate::cob::HunkItem::FileModeChanged { path, .. } => path, + crate::cob::HunkItem::FileEofChanged { path, .. } => path, + }; + let blobs = item.1.clone().blobs(repo.raw()); let highlighted = blobs.highlight(hi); Self { inner: item.clone(), highlighted, + comments: review + .comments() + .filter(|(_, comment)| comment.location().is_some()) + .filter(|(_, comment)| comment.location().unwrap().path == *path) + .map(|(id, comment)| (id.clone(), comment.clone())) + .collect::>(), } } } @@ -1444,7 +1461,7 @@ impl<'a> HunkItem<'a> { } pub fn hunk_text(&'a self) -> Option> { - match &self.inner { + let mut hunk = match &self.inner { ( _, crate::cob::HunkItem::FileAdded { @@ -1480,7 +1497,21 @@ impl<'a> HunkItem<'a> { .as_ref() .map(|hunk| Text::from(hunk.to_text(&self.highlighted))), _ => None, + }; + + let comments = self + .comments + .iter() + .fold(Text::raw(""), |mut comments, comment| { + comments.extend(Text::from(comment.1.body())); + comments + }); + + if let Some(ref mut hunk) = hunk { + hunk.extend(comments); } + + hunk } }