cob: Use semilattice rules for commenting

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
Alexis Sellier 2022-11-25 11:51:55 +01:00
parent fa9a89caa3
commit cc64c1d80b
No known key found for this signature in database
1 changed files with 12 additions and 11 deletions

View File

@ -1,3 +1,4 @@
use std::collections::btree_map::Entry;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::ops::{ControlFlow, Deref, DerefMut}; use std::ops::{ControlFlow, Deref, DerefMut};
use std::str::FromStr; use std::str::FromStr;
@ -121,22 +122,22 @@ impl Thread {
match change.action { match change.action {
Action::Comment { comment } => { Action::Comment { comment } => {
match self.comments.get(&id) { let present = Redactable::Present(comment);
Some(Redactable::Present(_)) => {
// Do nothing, the action was already processed, match self.comments.entry(id) {
// since a change with the same content-id as this Entry::Vacant(e) => {
// one exists already. e.insert(present);
} }
Some(Redactable::Redacted) => { Entry::Occupied(mut e) => {
// Do nothing, the action was redacted. e.get_mut().merge(present);
}
None => {
self.comments.insert(id, Redactable::Present(comment));
} }
} }
} }
Action::Redact { id } => { Action::Redact { id } => {
self.comments.insert(id, Redactable::Redacted); self.comments
.entry(id)
.and_modify(|e| e.merge(Redactable::Redacted))
.or_insert(Redactable::Redacted);
} }
Action::Tag { tag } => { Action::Tag { tag } => {
self.tags self.tags