From c176fb9a3d2d6649b7fb6fd88f167eaf87cb5898 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 22 Nov 2024 10:49:13 +0100 Subject: [PATCH] Take a `&identity::Did` for the `Author` constructor --- crates/radicle-types/src/cobs.rs | 6 +++--- crates/radicle-types/src/cobs/issue.rs | 4 ++-- crates/radicle-types/src/cobs/patch.rs | 12 ++++++------ crates/radicle-types/src/cobs/thread.rs | 24 +++++++++++++++++------- crates/radicle-types/src/traits/cobs.rs | 2 +- crates/radicle-types/src/traits/repo.rs | 5 ++--- 6 files changed, 31 insertions(+), 22 deletions(-) diff --git a/crates/radicle-types/src/cobs.rs b/crates/radicle-types/src/cobs.rs index 5894d785e..6b39f4376 100644 --- a/crates/radicle-types/src/cobs.rs +++ b/crates/radicle-types/src/cobs.rs @@ -22,10 +22,10 @@ pub struct Author { } impl Author { - pub fn new(did: identity::Did, aliases: &impl AliasStore) -> Self { + pub fn new(did: &identity::Did, aliases: &impl AliasStore) -> Self { Self { - did, - alias: aliases.alias(&did), + did: *did, + alias: aliases.alias(did), } } } diff --git a/crates/radicle-types/src/cobs/issue.rs b/crates/radicle-types/src/cobs/issue.rs index f51060b6a..85e65b842 100644 --- a/crates/radicle-types/src/cobs/issue.rs +++ b/crates/radicle-types/src/cobs/issue.rs @@ -36,12 +36,12 @@ impl Issue { Self { id: id.to_string(), - author: cobs::Author::new(*issue.author().id(), aliases), + author: cobs::Author::new(issue.author().id(), aliases), title: issue.title().to_string(), state: (*issue.state()).into(), assignees: issue .assignees() - .map(|did| cobs::Author::new(*did, aliases)) + .map(|did| cobs::Author::new(did, aliases)) .collect::>(), body: cobs::thread::Comment::::new( *root_oid, diff --git a/crates/radicle-types/src/cobs/patch.rs b/crates/radicle-types/src/cobs/patch.rs index b1a306ee9..48e54061a 100644 --- a/crates/radicle-types/src/cobs/patch.rs +++ b/crates/radicle-types/src/cobs/patch.rs @@ -37,14 +37,14 @@ impl Patch { pub fn new(id: patch::PatchId, patch: &patch::Patch, aliases: &impl AliasStore) -> Self { Self { id: id.to_string(), - author: cobs::Author::new(*patch.author().id(), aliases), + author: cobs::Author::new(patch.author().id(), aliases), title: patch.title().to_string(), state: patch.state().clone().into(), base: *patch.base(), head: *patch.head(), assignees: patch .assignees() - .map(|did| cobs::Author::new(did, aliases)) + .map(|did| cobs::Author::new(&did, aliases)) .collect::>(), labels: patch.labels().cloned().collect::>(), timestamp: patch.timestamp(), @@ -142,7 +142,7 @@ impl Revision { pub fn new(value: cob::patch::Revision, aliases: &impl AliasStore) -> Self { Self { id: value.id(), - author: cobs::Author::new(*value.author().id(), aliases), + author: cobs::Author::new(value.author().id(), aliases), description: value .edits() .map(|e| Edit::new(e, aliases)) @@ -181,7 +181,7 @@ impl Revision { .map(|(emoji, authors)| { cobs::thread::Reaction::new( *emoji, - authors, + authors.into_iter().map(|a| a.into()).collect::>(), location .as_ref() .map(|l| cobs::thread::CodeLocation::new(l.clone())), @@ -211,7 +211,7 @@ pub struct Edit { impl Edit { pub fn new(edit: &cob::thread::Edit, aliases: &impl AliasStore) -> Self { Self { - author: cobs::Author::new(edit.author.into(), aliases), + author: cobs::Author::new(&edit.author.into(), aliases), timestamp: edit.timestamp, body: edit.body.clone(), embeds: edit @@ -251,7 +251,7 @@ impl Review { ) -> Self { Self { id, - author: cobs::Author::new(review.author().id, aliases), + author: cobs::Author::new(&review.author().id, aliases), verdict: review.verdict(), summary: review.summary().map(|s| s.to_string()), comments: review diff --git a/crates/radicle-types/src/cobs/thread.rs b/crates/radicle-types/src/cobs/thread.rs index a86285100..d4a4d50c8 100644 --- a/crates/radicle-types/src/cobs/thread.rs +++ b/crates/radicle-types/src/cobs/thread.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use ts_rs::TS; use radicle::node::AliasStore; -use radicle::{cob, crypto, git}; +use radicle::{cob, git, identity}; use crate::cobs; @@ -59,7 +59,7 @@ impl Comment { ) -> Self { Self { id, - author: cobs::Author::new(comment.author().into(), aliases), + author: cobs::Author::new(&comment.author().into(), aliases), edits: comment .edits() .map(|e| cobs::patch::Edit::new(e, aliases)) @@ -68,7 +68,12 @@ impl Comment { .reactions() .into_iter() .map(|(reaction, authors)| { - cobs::thread::Reaction::new(*reaction, authors, None, aliases) + cobs::thread::Reaction::new( + *reaction, + authors.into_iter().map(|s| s.into()).collect(), + None, + aliases, + ) }) .collect::>(), reply_to: comment.reply_to(), @@ -92,7 +97,7 @@ impl Comment { ) -> Self { Self { id, - author: cobs::Author::new(comment.author().into(), aliases), + author: cobs::Author::new(&comment.author().into(), aliases), edits: comment .edits() .map(|e| cobs::patch::Edit::new(e, aliases)) @@ -101,7 +106,12 @@ impl Comment { .reactions() .into_iter() .map(|(reaction, authors)| { - cobs::thread::Reaction::new(*reaction, authors, None, aliases) + cobs::thread::Reaction::new( + *reaction, + authors.into_iter().map(|m| m.into()).collect::>(), + None, + aliases, + ) }) .collect::>(), reply_to: comment.reply_to(), @@ -132,7 +142,7 @@ pub struct Reaction { impl Reaction { pub fn new( emoji: cob::Reaction, - authors: Vec<&crypto::PublicKey>, + authors: Vec, location: Option, aliases: &impl AliasStore, ) -> Self { @@ -140,7 +150,7 @@ impl Reaction { emoji, authors: authors .into_iter() - .map(|a| cobs::Author::new(a.into(), aliases)) + .map(|did| cobs::Author::new(&did, aliases)) .collect::>(), location, } diff --git a/crates/radicle-types/src/traits/cobs.rs b/crates/radicle-types/src/traits/cobs.rs index 2463394a5..593565947 100644 --- a/crates/radicle-types/src/traits/cobs.rs +++ b/crates/radicle-types/src/traits/cobs.rs @@ -28,7 +28,7 @@ pub trait Cobs: Profile { Some(crate::cobs::issue::Operation { entry_id: op.id, action, - author: crate::cobs::Author::new(op.author.into(), &aliases), + author: crate::cobs::Author::new(&op.author.into(), &aliases), timestamp: op.timestamp, }) }, diff --git a/crates/radicle-types/src/traits/repo.rs b/crates/radicle-types/src/traits/repo.rs index 7114491ed..0b711cc7c 100644 --- a/crates/radicle-types/src/traits/repo.rs +++ b/crates/radicle-types/src/traits/repo.rs @@ -92,9 +92,8 @@ pub trait Repo: Profile { let profile = self.profile(); let aliases = profile.aliases(); let delegates = doc - .delegates - .clone() - .into_iter() + .delegates() + .iter() .map(|did| cobs::Author::new(did, &aliases)) .collect::>(); let db = profile.database()?;