cob: Consistently name these 'ops'
Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
parent
56f9af650e
commit
de0e54a186
|
|
@ -112,8 +112,8 @@ impl store::FromHistory for Issue {
|
||||||
history: &radicle_cob::History,
|
history: &radicle_cob::History,
|
||||||
) -> Result<(Self, clock::Lamport), store::Error> {
|
) -> Result<(Self, clock::Lamport), store::Error> {
|
||||||
let obj = history.traverse(Self::default(), |mut acc, entry| {
|
let obj = history.traverse(Self::default(), |mut acc, entry| {
|
||||||
if let Ok(Ops(changes)) = Ops::try_from(entry) {
|
if let Ok(Ops(ops)) = Ops::try_from(entry) {
|
||||||
if let Err(err) = acc.apply(changes) {
|
if let Err(err) = acc.apply(ops) {
|
||||||
log::warn!("Error applying op to issue state: {err}");
|
log::warn!("Error applying op to issue state: {err}");
|
||||||
return ControlFlow::Break(acc);
|
return ControlFlow::Break(acc);
|
||||||
}
|
}
|
||||||
|
|
@ -155,29 +155,29 @@ impl Issue {
|
||||||
self.thread.comments().map(|(id, comment)| (id, comment))
|
self.thread.comments().map(|(id, comment)| (id, comment))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply(&mut self, changes: impl IntoIterator<Item = Op>) -> Result<(), Error> {
|
pub fn apply(&mut self, ops: impl IntoIterator<Item = Op>) -> Result<(), Error> {
|
||||||
for change in changes {
|
for op in ops {
|
||||||
match change.action {
|
match op.action {
|
||||||
Action::Title { title } => {
|
Action::Title { title } => {
|
||||||
self.title.set(title, change.clock);
|
self.title.set(title, op.clock);
|
||||||
}
|
}
|
||||||
Action::Lifecycle { status } => {
|
Action::Lifecycle { status } => {
|
||||||
self.status.set(status, change.clock);
|
self.status.set(status, op.clock);
|
||||||
}
|
}
|
||||||
Action::Tag { add, remove } => {
|
Action::Tag { add, remove } => {
|
||||||
for tag in add {
|
for tag in add {
|
||||||
self.tags.insert(tag, change.clock);
|
self.tags.insert(tag, op.clock);
|
||||||
}
|
}
|
||||||
for tag in remove {
|
for tag in remove {
|
||||||
self.tags.remove(tag, change.clock);
|
self.tags.remove(tag, op.clock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Action::Thread { action } => {
|
Action::Thread { action } => {
|
||||||
self.thread.apply([cob::Op {
|
self.thread.apply([cob::Op {
|
||||||
action,
|
action,
|
||||||
author: change.author,
|
author: op.author,
|
||||||
clock: change.clock,
|
clock: op.clock,
|
||||||
timestamp: change.timestamp,
|
timestamp: op.timestamp,
|
||||||
}]);
|
}]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -329,8 +329,8 @@ impl store::FromHistory for Patch {
|
||||||
history: &radicle_cob::History,
|
history: &radicle_cob::History,
|
||||||
) -> Result<(Self, clock::Lamport), store::Error> {
|
) -> Result<(Self, clock::Lamport), store::Error> {
|
||||||
let obj = history.traverse(Self::default(), |mut acc, entry| {
|
let obj = history.traverse(Self::default(), |mut acc, entry| {
|
||||||
if let Ok(Ops(changes)) = Ops::try_from(entry) {
|
if let Ok(Ops(ops)) = Ops::try_from(entry) {
|
||||||
if let Err(err) = acc.apply(changes) {
|
if let Err(err) = acc.apply(ops) {
|
||||||
log::warn!("Error applying op to patch state: {err}");
|
log::warn!("Error applying op to patch state: {err}");
|
||||||
return ControlFlow::Break(acc);
|
return ControlFlow::Break(acc);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -167,14 +167,13 @@ impl Thread {
|
||||||
.map(|(a, r)| (a, r))
|
.map(|(a, r)| (a, r))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply(&mut self, changes: impl IntoIterator<Item = Op<Action>>) {
|
pub fn apply(&mut self, ops: impl IntoIterator<Item = Op<Action>>) {
|
||||||
for change in changes.into_iter() {
|
for op in ops.into_iter() {
|
||||||
let id = change.id();
|
let id = op.id();
|
||||||
|
|
||||||
match change.action {
|
match op.action {
|
||||||
Action::Comment { body, reply_to } => {
|
Action::Comment { body, reply_to } => {
|
||||||
let present =
|
let present = Redactable::Present(Comment::new(body, reply_to, op.timestamp));
|
||||||
Redactable::Present(Comment::new(body, reply_to, change.timestamp));
|
|
||||||
self.comments.insert(id, present);
|
self.comments.insert(id, present);
|
||||||
}
|
}
|
||||||
Action::Redact { id } => {
|
Action::Redact { id } => {
|
||||||
|
|
@ -185,12 +184,12 @@ impl Thread {
|
||||||
reaction,
|
reaction,
|
||||||
active,
|
active,
|
||||||
} => {
|
} => {
|
||||||
let key = (change.author, reaction);
|
let key = (op.author, reaction);
|
||||||
let reactions = if active {
|
let reactions = if active {
|
||||||
LWWSet::singleton(key, change.clock)
|
LWWSet::singleton(key, op.clock)
|
||||||
} else {
|
} else {
|
||||||
let mut set = LWWSet::default();
|
let mut set = LWWSet::default();
|
||||||
set.remove(key, change.clock);
|
set.remove(key, op.clock);
|
||||||
set
|
set
|
||||||
};
|
};
|
||||||
self.reactions.insert(to, reactions);
|
self.reactions.insert(to, reactions);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue