Renamed ElementUpdateStrategy
to more accurate ContentUpdateStrategy
This commit is contained in:
parent
25570765d7
commit
29d76032cc
7 changed files with 26 additions and 26 deletions
|
@ -8,13 +8,13 @@ pub struct Element {
|
||||||
pub id: ElementId,
|
pub id: ElementId,
|
||||||
pub pot: Option<PotId>,
|
pub pot: Option<PotId>,
|
||||||
pub content: ElementContent,
|
pub content: ElementContent,
|
||||||
pub update_strategy: ElementUpdateStrategy,
|
pub update_strategy: ContentUpdateStrategy,
|
||||||
pub latest_message: Option<MessageId>,
|
pub latest_message: Option<MessageId>,
|
||||||
pub local_changes: bool,
|
pub local_changes: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Element {
|
impl Element {
|
||||||
pub fn new(id: ElementId, content: ElementContent, update_strategy: ElementUpdateStrategy) -> Self {
|
pub fn new(id: ElementId, content: ElementContent, update_strategy: ContentUpdateStrategy) -> Self {
|
||||||
// A new element with no latest message must have local changes
|
// A new element with no latest message must have local changes
|
||||||
Element {
|
Element {
|
||||||
id: id,
|
id: id,
|
||||||
|
@ -46,11 +46,11 @@ impl Element {
|
||||||
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||||
pub enum ElementUpdateStrategy {
|
pub enum ContentUpdateStrategy {
|
||||||
Overwrite
|
Overwrite
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ElementUpdateStrategy {
|
impl ContentUpdateStrategy {
|
||||||
pub fn default_by_content(&self, content: &ElementContent) -> Self {
|
pub fn default_by_content(&self, content: &ElementContent) -> Self {
|
||||||
match content {
|
match content {
|
||||||
_ => Self::Overwrite,
|
_ => Self::Overwrite,
|
||||||
|
@ -58,7 +58,7 @@ impl ElementUpdateStrategy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ElementUpdateStrategy {
|
impl Default for ContentUpdateStrategy {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::Overwrite
|
Self::Overwrite
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ mod element_id;
|
||||||
pub use element_id::ElementId;
|
pub use element_id::ElementId;
|
||||||
|
|
||||||
mod element;
|
mod element;
|
||||||
pub use element::{Element, ElementUpdateStrategy};
|
pub use element::{Element, ContentUpdateStrategy};
|
||||||
|
|
||||||
mod family_id;
|
mod family_id;
|
||||||
pub use family_id::FamilyId;
|
pub use family_id::FamilyId;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
use ubisync_lib::peer::Peer;
|
use ubisync_lib::peer::Peer;
|
||||||
use ubisync_lib::types::{ElementUpdateStrategy, PeerId};
|
use ubisync_lib::types::{ContentUpdateStrategy, PeerId};
|
||||||
|
|
||||||
use ubisync_lib::messages::{Message, MessageContent};
|
use ubisync_lib::messages::{Message, MessageContent};
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ pub fn handle(state: &CommState, peer: &PeerId, message: Message) {
|
||||||
.add_received_element(
|
.add_received_element(
|
||||||
id.to_owned(),
|
id.to_owned(),
|
||||||
content.to_owned(),
|
content.to_owned(),
|
||||||
ElementUpdateStrategy::Overwrite,
|
ContentUpdateStrategy::Overwrite,
|
||||||
Some(message.id().to_owned()),
|
Some(message.id().to_owned()),
|
||||||
pot.to_owned(),
|
pot.to_owned(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,7 +6,7 @@ use tracing::debug;
|
||||||
use ubisync_lib::{
|
use ubisync_lib::{
|
||||||
api::events::AppEvent,
|
api::events::AppEvent,
|
||||||
messages::MessageContent,
|
messages::MessageContent,
|
||||||
types::{AppId, Element, ElementContent, ElementId, ElementUpdateStrategy, Pot, PotId},
|
types::{AppId, Element, ElementContent, ElementId, ContentUpdateStrategy, Pot, PotId},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::api::v0::app::App;
|
use crate::api::v0::app::App;
|
||||||
|
@ -60,7 +60,7 @@ impl ApiState {
|
||||||
pub fn create_element(&self, content: ElementContent, pot: PotId) -> anyhow::Result<ElementId> {
|
pub fn create_element(&self, content: ElementContent, pot: PotId) -> anyhow::Result<ElementId> {
|
||||||
let id = ElementId::new();
|
let id = ElementId::new();
|
||||||
self.db()
|
self.db()
|
||||||
.add_element(id.clone(), content.clone(), ElementUpdateStrategy::Overwrite, None, false, pot.clone())?;
|
.add_element(id.clone(), content.clone(), ContentUpdateStrategy::Overwrite, None, false, pot.clone())?;
|
||||||
debug!("Added element {{{}}}", id.to_string());
|
debug!("Added element {{{}}}", id.to_string());
|
||||||
|
|
||||||
self.state.send_to_peers(
|
self.state.send_to_peers(
|
||||||
|
|
|
@ -5,7 +5,7 @@ use tracing::debug;
|
||||||
use ubisync_lib::{
|
use ubisync_lib::{
|
||||||
api::events::AppEvent,
|
api::events::AppEvent,
|
||||||
peer::Peer,
|
peer::Peer,
|
||||||
types::{Element, ElementContent, ElementId, ElementUpdateStrategy, MessageId, PotId},
|
types::{Element, ElementContent, ElementId, ContentUpdateStrategy, MessageId, PotId},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::node_events::UbisyncNodeEvent;
|
use crate::node_events::UbisyncNodeEvent;
|
||||||
|
@ -25,7 +25,7 @@ impl CommState {
|
||||||
&self,
|
&self,
|
||||||
id: ElementId,
|
id: ElementId,
|
||||||
content: ElementContent,
|
content: ElementContent,
|
||||||
update_strategy: ElementUpdateStrategy,
|
update_strategy: ContentUpdateStrategy,
|
||||||
latest_message: Option<MessageId>,
|
latest_message: Option<MessageId>,
|
||||||
pot_id: PotId,
|
pot_id: PotId,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
|
@ -110,7 +110,7 @@ mod tests {
|
||||||
use super::CommState;
|
use super::CommState;
|
||||||
|
|
||||||
use tracing::Level;
|
use tracing::Level;
|
||||||
use ubisync_lib::types::{ElementContent, ElementId, ElementUpdateStrategy, MessageId, PotId};
|
use ubisync_lib::types::{ElementContent, ElementId, ContentUpdateStrategy, MessageId, PotId};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial_test::serial]
|
#[serial_test::serial]
|
||||||
|
@ -127,7 +127,7 @@ mod tests {
|
||||||
.add_received_element(
|
.add_received_element(
|
||||||
id.clone(),
|
id.clone(),
|
||||||
ElementContent::Text("Test-text".to_string()),
|
ElementContent::Text("Test-text".to_string()),
|
||||||
ElementUpdateStrategy::Overwrite,
|
ContentUpdateStrategy::Overwrite,
|
||||||
Some(MessageId::new()),
|
Some(MessageId::new()),
|
||||||
pot_id,
|
pot_id,
|
||||||
)
|
)
|
||||||
|
@ -154,7 +154,7 @@ mod tests {
|
||||||
.add_received_element(
|
.add_received_element(
|
||||||
id.clone(),
|
id.clone(),
|
||||||
ElementContent::Text("Test-text".to_string()),
|
ElementContent::Text("Test-text".to_string()),
|
||||||
ElementUpdateStrategy::Overwrite,
|
ContentUpdateStrategy::Overwrite,
|
||||||
Some(MessageId::new()),
|
Some(MessageId::new()),
|
||||||
pot_id,
|
pot_id,
|
||||||
)
|
)
|
||||||
|
|
|
@ -113,7 +113,7 @@ impl StateDB {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use ubisync_lib::types::{AppId, ElementContent, ElementId, ElementUpdateStrategy, Pot, PotId};
|
use ubisync_lib::types::{AppId, ElementContent, ElementId, ContentUpdateStrategy, Pot, PotId};
|
||||||
|
|
||||||
use crate::{api::v0::app::App, state::database::StateDB};
|
use crate::{api::v0::app::App, state::database::StateDB};
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ mod tests {
|
||||||
db.add_element(
|
db.add_element(
|
||||||
element_id.clone(),
|
element_id.clone(),
|
||||||
ElementContent::Text("Text".to_string()),
|
ElementContent::Text("Text".to_string()),
|
||||||
ElementUpdateStrategy::Overwrite,
|
ContentUpdateStrategy::Overwrite,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
pot_id.clone(),
|
pot_id.clone(),
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use anyhow::{anyhow, Error};
|
use anyhow::{anyhow, Error};
|
||||||
use bonsaidb::core::schema::{Collection, SerializedCollection};
|
use bonsaidb::core::schema::{Collection, SerializedCollection};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use ubisync_lib::types::{Element, ElementContent, ElementId, ElementUpdateStrategy, MessageId, PotId};
|
use ubisync_lib::types::{Element, ElementContent, ElementId, ContentUpdateStrategy, MessageId, PotId};
|
||||||
|
|
||||||
use crate::state::database::{as_key::AsKey, StateDB};
|
use crate::state::database::{as_key::AsKey, StateDB};
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ pub(super) struct DbElement {
|
||||||
#[natural_id]
|
#[natural_id]
|
||||||
pub(super) id: AsKey<ElementId>,
|
pub(super) id: AsKey<ElementId>,
|
||||||
pub(super) content: ElementContent,
|
pub(super) content: ElementContent,
|
||||||
pub(super) update_strategy: ElementUpdateStrategy,
|
pub(super) update_strategy: ContentUpdateStrategy,
|
||||||
pub(super) latest_message: Option<MessageId>,
|
pub(super) latest_message: Option<MessageId>,
|
||||||
pub(super) local_changes: bool,
|
pub(super) local_changes: bool,
|
||||||
pub(super) pot: PotId,
|
pub(super) pot: PotId,
|
||||||
|
@ -35,7 +35,7 @@ impl StateDB {
|
||||||
&self,
|
&self,
|
||||||
id: ElementId,
|
id: ElementId,
|
||||||
content: ElementContent,
|
content: ElementContent,
|
||||||
update_strategy: ElementUpdateStrategy,
|
update_strategy: ContentUpdateStrategy,
|
||||||
latest_message: Option<MessageId>,
|
latest_message: Option<MessageId>,
|
||||||
local_changes: bool,
|
local_changes: bool,
|
||||||
pot: PotId,
|
pot: PotId,
|
||||||
|
@ -108,7 +108,7 @@ impl StateDB {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use ubisync_lib::types::{Element, ElementContent, ElementId, ElementUpdateStrategy, MessageId, PotId};
|
use ubisync_lib::types::{Element, ElementContent, ElementId, ContentUpdateStrategy, MessageId, PotId};
|
||||||
|
|
||||||
use crate::state::database::StateDB;
|
use crate::state::database::StateDB;
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ mod tests {
|
||||||
db.add_element(
|
db.add_element(
|
||||||
element_id.clone(),
|
element_id.clone(),
|
||||||
ElementContent::Text("Content!!!".to_string()),
|
ElementContent::Text("Content!!!".to_string()),
|
||||||
ElementUpdateStrategy::default(),
|
ContentUpdateStrategy::default(),
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
pot_id.clone(),
|
pot_id.clone(),
|
||||||
|
@ -134,7 +134,7 @@ mod tests {
|
||||||
Element {
|
Element {
|
||||||
id: element_id,
|
id: element_id,
|
||||||
content: ElementContent::Text("Content!!!".to_string()),
|
content: ElementContent::Text("Content!!!".to_string()),
|
||||||
update_strategy: ElementUpdateStrategy::default(),
|
update_strategy: ContentUpdateStrategy::default(),
|
||||||
latest_message: None,
|
latest_message: None,
|
||||||
local_changes: false,
|
local_changes: false,
|
||||||
pot: Some(pot_id),
|
pot: Some(pot_id),
|
||||||
|
@ -151,7 +151,7 @@ mod tests {
|
||||||
db.add_element(
|
db.add_element(
|
||||||
element_id.clone(),
|
element_id.clone(),
|
||||||
ElementContent::Text("Content!!!".to_string()),
|
ElementContent::Text("Content!!!".to_string()),
|
||||||
ElementUpdateStrategy::default(),
|
ContentUpdateStrategy::default(),
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
PotId::new(),
|
PotId::new(),
|
||||||
|
@ -177,7 +177,7 @@ mod tests {
|
||||||
db.add_element(
|
db.add_element(
|
||||||
element_id.clone(),
|
element_id.clone(),
|
||||||
ElementContent::Text("Content!!!".to_string()),
|
ElementContent::Text("Content!!!".to_string()),
|
||||||
ElementUpdateStrategy::default(),
|
ContentUpdateStrategy::default(),
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
PotId::new(),
|
PotId::new(),
|
||||||
|
@ -213,7 +213,7 @@ mod tests {
|
||||||
db.add_element(
|
db.add_element(
|
||||||
element_id.clone(),
|
element_id.clone(),
|
||||||
ElementContent::Text("Content!!!".to_string()),
|
ElementContent::Text("Content!!!".to_string()),
|
||||||
ElementUpdateStrategy::default(),
|
ContentUpdateStrategy::default(),
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
PotId::new(),
|
PotId::new(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue