diff --git a/radicle/src/cob/issue.rs b/radicle/src/cob/issue.rs index 6aca2d75..58cc6a83 100644 --- a/radicle/src/cob/issue.rs +++ b/radicle/src/cob/issue.rs @@ -220,9 +220,11 @@ impl<'a, 'g> IssueMut<'a, 'g> { let author = *signer.public_key(); let clock = self.clock.tick(); let body = body.into(); - let comment = thread::Comment::new(body, None); let change = Change { - action: Action::from(thread::Action::Comment { comment }), + action: Action::from(thread::Action::Comment { + body, + reply_to: None, + }), author, clock, }; @@ -261,9 +263,11 @@ impl<'a, 'g> IssueMut<'a, 'g> { assert!(self.thread.comment(&parent).is_some()); - let comment = thread::Comment::new(body, Some(parent)); let change = Change { - action: Action::from(thread::Action::Comment { comment }), + action: Action::from(thread::Action::Comment { + body, + reply_to: Some(parent), + }), author, clock, }; diff --git a/radicle/src/cob/thread.rs b/radicle/src/cob/thread.rs index c4192204..9f5aa112 100644 --- a/radicle/src/cob/thread.rs +++ b/radicle/src/cob/thread.rs @@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize}; use crate::cob::common::{Reaction, Tag}; use crate::cob::store; -use crate::cob::{History, TypeName}; +use crate::cob::{History, Timestamp, TypeName}; use crate::crypto::Signer; use crdt::clock::Lamport; @@ -33,12 +33,18 @@ pub struct Comment { pub body: String, /// Thread or comment this is a reply to. pub reply_to: Option, + /// When the comment was authored. + pub timestamp: Timestamp, } impl Comment { /// Create a new comment. - pub fn new(body: String, reply_to: Option) -> Self { - Self { body, reply_to } + pub fn new(body: String, reply_to: Option, timestamp: Timestamp) -> Self { + Self { + body, + reply_to, + timestamp, + } } } @@ -56,7 +62,12 @@ impl PartialOrd for Comment { #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] pub enum Action { /// Comment on a thread. - Comment { comment: Comment }, + Comment { + /// Comment body. + body: String, + /// Another comment this is a reply to. + reply_to: Option, + }, /// Redact a change. Not all changes can be redacted. Redact { id: ChangeId }, /// Add tags to the thread. @@ -161,12 +172,15 @@ impl Thread { changes: impl IntoIterator>, clock: &mut Lamport, ) { + // FIXME(cloudhead): Use commit timestamp. + let timestamp = Timestamp::default(); + for change in changes.into_iter() { let id = change.id(); match change.action { - Action::Comment { comment } => { - let present = Redactable::Present(comment); + Action::Comment { body, reply_to } => { + let present = Redactable::Present(Comment::new(body, reply_to, timestamp)); match self.comments.entry(id) { Entry::Vacant(e) => { @@ -271,9 +285,10 @@ impl Actor { } /// Create a new comment. - pub fn comment(&mut self, body: &str, parent: Option) -> Change { + pub fn comment(&mut self, body: &str, reply_to: Option) -> Change { self.change(Action::Comment { - comment: Comment::new(String::from(body), parent), + body: String::from(body), + reply_to, }) } @@ -352,10 +367,8 @@ mod tests { Some(( *clock, Action::Comment { - comment: Comment { - body: iter::repeat_with(|| rng.alphabetic()).take(16).collect(), - reply_to: Default::default(), - }, + body: iter::repeat_with(|| rng.alphabetic()).take(16).collect(), + reply_to: None, }, )) })