Added ElementUpdateStrategy
, renamed SetElement
message to UpdateElement
. Fixes #12
This commit is contained in:
parent
0f3ea0f52a
commit
941cb8e6ab
4 changed files with 13 additions and 4 deletions
|
@ -24,7 +24,7 @@ pub enum MessageContent {
|
||||||
content: ElementContent,
|
content: ElementContent,
|
||||||
pot: PotId,
|
pot: PotId,
|
||||||
},
|
},
|
||||||
SetElement {
|
UpdateElement {
|
||||||
id: ElementId,
|
id: ElementId,
|
||||||
content: ElementContent,
|
content: ElementContent,
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,17 +8,19 @@ 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 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) -> Self {
|
pub fn new(id: ElementId, content: ElementContent, update_strategy: ElementUpdateStrategy) -> 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,
|
||||||
pot: None,
|
pot: None,
|
||||||
content,
|
content,
|
||||||
|
update_strategy,
|
||||||
latest_message: None,
|
latest_message: None,
|
||||||
local_changes: true,
|
local_changes: true,
|
||||||
}
|
}
|
||||||
|
@ -40,3 +42,10 @@ impl Element {
|
||||||
self.local_changes
|
self.local_changes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||||
|
pub enum ElementUpdateStrategy {
|
||||||
|
Overwrite
|
||||||
|
}
|
|
@ -25,7 +25,7 @@ pub fn handle(state: &CommState, peer: &PeerId, message: Message) {
|
||||||
)
|
)
|
||||||
.expect("State failed");
|
.expect("State failed");
|
||||||
}
|
}
|
||||||
MessageContent::SetElement { id, content } => {
|
MessageContent::UpdateElement { id, content } => {
|
||||||
state
|
state
|
||||||
.update_element_content(id.to_owned(), content.to_owned(), message.id().to_owned())
|
.update_element_content(id.to_owned(), content.to_owned(), message.id().to_owned())
|
||||||
.expect("State failed");
|
.expect("State failed");
|
||||||
|
|
|
@ -88,7 +88,7 @@ impl State {
|
||||||
.inspect(|_| {
|
.inspect(|_| {
|
||||||
//TODO: Get all peers interested in the element, e.g. because they subscribe to the element's pot, a share, etc.
|
//TODO: Get all peers interested in the element, e.g. because they subscribe to the element's pot, a share, etc.
|
||||||
self.send_to_peers(
|
self.send_to_peers(
|
||||||
MessageContent::SetElement {
|
MessageContent::UpdateElement {
|
||||||
id: element_id.clone(),
|
id: element_id.clone(),
|
||||||
content: content.clone(),
|
content: content.clone(),
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue