cob: Add timestamp to comment state
Since the timestamp is to be retrieved from the commit, we don't add it to the action. Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
parent
63614e9c94
commit
b015b29f34
|
|
@ -220,9 +220,11 @@ impl<'a, 'g> IssueMut<'a, 'g> {
|
||||||
let author = *signer.public_key();
|
let author = *signer.public_key();
|
||||||
let clock = self.clock.tick();
|
let clock = self.clock.tick();
|
||||||
let body = body.into();
|
let body = body.into();
|
||||||
let comment = thread::Comment::new(body, None);
|
|
||||||
let change = Change {
|
let change = Change {
|
||||||
action: Action::from(thread::Action::Comment { comment }),
|
action: Action::from(thread::Action::Comment {
|
||||||
|
body,
|
||||||
|
reply_to: None,
|
||||||
|
}),
|
||||||
author,
|
author,
|
||||||
clock,
|
clock,
|
||||||
};
|
};
|
||||||
|
|
@ -261,9 +263,11 @@ impl<'a, 'g> IssueMut<'a, 'g> {
|
||||||
|
|
||||||
assert!(self.thread.comment(&parent).is_some());
|
assert!(self.thread.comment(&parent).is_some());
|
||||||
|
|
||||||
let comment = thread::Comment::new(body, Some(parent));
|
|
||||||
let change = Change {
|
let change = Change {
|
||||||
action: Action::from(thread::Action::Comment { comment }),
|
action: Action::from(thread::Action::Comment {
|
||||||
|
body,
|
||||||
|
reply_to: Some(parent),
|
||||||
|
}),
|
||||||
author,
|
author,
|
||||||
clock,
|
clock,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::cob::common::{Reaction, Tag};
|
use crate::cob::common::{Reaction, Tag};
|
||||||
use crate::cob::store;
|
use crate::cob::store;
|
||||||
use crate::cob::{History, TypeName};
|
use crate::cob::{History, Timestamp, TypeName};
|
||||||
use crate::crypto::Signer;
|
use crate::crypto::Signer;
|
||||||
|
|
||||||
use crdt::clock::Lamport;
|
use crdt::clock::Lamport;
|
||||||
|
|
@ -33,12 +33,18 @@ pub struct Comment {
|
||||||
pub body: String,
|
pub body: String,
|
||||||
/// Thread or comment this is a reply to.
|
/// Thread or comment this is a reply to.
|
||||||
pub reply_to: Option<ChangeId>,
|
pub reply_to: Option<ChangeId>,
|
||||||
|
/// When the comment was authored.
|
||||||
|
pub timestamp: Timestamp,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Comment {
|
impl Comment {
|
||||||
/// Create a new comment.
|
/// Create a new comment.
|
||||||
pub fn new(body: String, reply_to: Option<ChangeId>) -> Self {
|
pub fn new(body: String, reply_to: Option<ChangeId>, timestamp: Timestamp) -> Self {
|
||||||
Self { body, reply_to }
|
Self {
|
||||||
|
body,
|
||||||
|
reply_to,
|
||||||
|
timestamp,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,7 +62,12 @@ impl PartialOrd for Comment {
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
|
||||||
pub enum Action {
|
pub enum Action {
|
||||||
/// Comment on a thread.
|
/// Comment on a thread.
|
||||||
Comment { comment: Comment },
|
Comment {
|
||||||
|
/// Comment body.
|
||||||
|
body: String,
|
||||||
|
/// Another comment this is a reply to.
|
||||||
|
reply_to: Option<ChangeId>,
|
||||||
|
},
|
||||||
/// Redact a change. Not all changes can be redacted.
|
/// Redact a change. Not all changes can be redacted.
|
||||||
Redact { id: ChangeId },
|
Redact { id: ChangeId },
|
||||||
/// Add tags to the thread.
|
/// Add tags to the thread.
|
||||||
|
|
@ -161,12 +172,15 @@ impl Thread {
|
||||||
changes: impl IntoIterator<Item = Change<Action>>,
|
changes: impl IntoIterator<Item = Change<Action>>,
|
||||||
clock: &mut Lamport,
|
clock: &mut Lamport,
|
||||||
) {
|
) {
|
||||||
|
// FIXME(cloudhead): Use commit timestamp.
|
||||||
|
let timestamp = Timestamp::default();
|
||||||
|
|
||||||
for change in changes.into_iter() {
|
for change in changes.into_iter() {
|
||||||
let id = change.id();
|
let id = change.id();
|
||||||
|
|
||||||
match change.action {
|
match change.action {
|
||||||
Action::Comment { comment } => {
|
Action::Comment { body, reply_to } => {
|
||||||
let present = Redactable::Present(comment);
|
let present = Redactable::Present(Comment::new(body, reply_to, timestamp));
|
||||||
|
|
||||||
match self.comments.entry(id) {
|
match self.comments.entry(id) {
|
||||||
Entry::Vacant(e) => {
|
Entry::Vacant(e) => {
|
||||||
|
|
@ -271,9 +285,10 @@ impl<G: Signer> Actor<G> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new comment.
|
/// Create a new comment.
|
||||||
pub fn comment(&mut self, body: &str, parent: Option<ChangeId>) -> Change<Action> {
|
pub fn comment(&mut self, body: &str, reply_to: Option<ChangeId>) -> Change<Action> {
|
||||||
self.change(Action::Comment {
|
self.change(Action::Comment {
|
||||||
comment: Comment::new(String::from(body), parent),
|
body: String::from(body),
|
||||||
|
reply_to,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -352,10 +367,8 @@ mod tests {
|
||||||
Some((
|
Some((
|
||||||
*clock,
|
*clock,
|
||||||
Action::Comment {
|
Action::Comment {
|
||||||
comment: Comment {
|
body: iter::repeat_with(|| rng.alphabetic()).take(16).collect(),
|
||||||
body: iter::repeat_with(|| rng.alphabetic()).take(16).collect(),
|
reply_to: None,
|
||||||
reply_to: Default::default(),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue