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,
|
||||
pot: PotId,
|
||||
},
|
||||
SetElement {
|
||||
UpdateElement {
|
||||
id: ElementId,
|
||||
content: ElementContent,
|
||||
},
|
||||
|
|
|
@ -8,17 +8,19 @@ pub struct Element {
|
|||
pub id: ElementId,
|
||||
pub pot: Option<PotId>,
|
||||
pub content: ElementContent,
|
||||
pub update_strategy: ElementUpdateStrategy,
|
||||
pub latest_message: Option<MessageId>,
|
||||
pub local_changes: bool,
|
||||
}
|
||||
|
||||
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
|
||||
Element {
|
||||
id: id,
|
||||
pot: None,
|
||||
content,
|
||||
update_strategy,
|
||||
latest_message: None,
|
||||
local_changes: true,
|
||||
}
|
||||
|
@ -40,3 +42,10 @@ impl Element {
|
|||
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");
|
||||
}
|
||||
MessageContent::SetElement { id, content } => {
|
||||
MessageContent::UpdateElement { id, content } => {
|
||||
state
|
||||
.update_element_content(id.to_owned(), content.to_owned(), message.id().to_owned())
|
||||
.expect("State failed");
|
||||
|
|
|
@ -88,7 +88,7 @@ impl State {
|
|||
.inspect(|_| {
|
||||
//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(
|
||||
MessageContent::SetElement {
|
||||
MessageContent::UpdateElement {
|
||||
id: element_id.clone(),
|
||||
content: content.clone(),
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue