Basic metastate sharing implementation
This commit is contained in:
parent
3589be0a3b
commit
95050d5c61
19 changed files with 458 additions and 26 deletions
|
@ -1,6 +1,6 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::types::{ElementContent, ElementId, Family, MessageId, PotId};
|
||||
use crate::types::{ElementContent, ElementId, Family, MessageId, PotId, Share, ShareId};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Message {
|
||||
|
@ -23,6 +23,7 @@ pub enum MessageContent {
|
|||
JoinFamily,
|
||||
AddedToFamily {
|
||||
family: Family,
|
||||
metastate_share: ShareId,
|
||||
},
|
||||
LeaveFamily,
|
||||
CreateElement {
|
||||
|
@ -41,6 +42,12 @@ pub enum MessageContent {
|
|||
id: PotId,
|
||||
app_type: String,
|
||||
},
|
||||
Get {
|
||||
shares: Vec<ShareId>,
|
||||
},
|
||||
UpdateShare {
|
||||
share: Share
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
|
|
|
@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
|
|||
|
||||
use super::{ElementContent, ElementId, MessageId, PotId};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct Element {
|
||||
// Uuid identifying the element itself
|
||||
pub id: ElementId,
|
||||
|
@ -43,6 +43,11 @@ impl Element {
|
|||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Element {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.id == other.id
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||
|
|
|
@ -1,7 +1,14 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{Family, Pot, Share};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||
pub enum ElementContent {
|
||||
MetaState {
|
||||
family: Family,
|
||||
pots: Vec<Pot>,
|
||||
shares: Vec<Share>,
|
||||
},
|
||||
Text(String),
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default)]
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default, Hash)]
|
||||
pub struct ElementId(Uuid);
|
||||
impl ElementId {
|
||||
pub fn new() -> Self {
|
||||
|
|
|
@ -8,7 +8,7 @@ mod element_id;
|
|||
pub use element_id::ElementId;
|
||||
|
||||
mod element;
|
||||
pub use element::{Element, ContentUpdateStrategy};
|
||||
pub use element::{ContentUpdateStrategy, Element};
|
||||
|
||||
mod family_id;
|
||||
pub use family_id::FamilyId;
|
||||
|
@ -32,7 +32,7 @@ mod pot;
|
|||
pub use pot::Pot;
|
||||
|
||||
mod share;
|
||||
pub use share::{ShareContent, SharePermissions, Share};
|
||||
pub use share::{Share, ShareContent, ShareId, SharePermissions};
|
||||
|
||||
mod tag;
|
||||
pub use tag::Tag;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct PotId(Uuid);
|
||||
impl PotId {
|
||||
pub fn new() -> Self {
|
||||
|
|
|
@ -1,22 +1,52 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::{FamilyId, PotId};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct ShareId(Uuid);
|
||||
impl ShareId {
|
||||
pub fn new() -> Self {
|
||||
ShareId(Uuid::new_v4())
|
||||
}
|
||||
}
|
||||
|
||||
impl ToString for ShareId {
|
||||
fn to_string(&self) -> String {
|
||||
self.0.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&ShareId> for String {
|
||||
fn from(value: &ShareId) -> Self {
|
||||
value.0.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for ShareId {
|
||||
type Error = serde_json::Error;
|
||||
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
||||
serde_json::from_str(value)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||
pub struct ShareContent {
|
||||
pub pots: Vec<PotId>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||
pub enum SharePermissions {
|
||||
Read,
|
||||
ReadWrite,
|
||||
Owner
|
||||
}
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||
pub struct Share {
|
||||
pub id: ShareId,
|
||||
pub content: ShareContent,
|
||||
pub members: HashMap<FamilyId, SharePermissions>,
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue