diff options
Diffstat (limited to 'src/database')
-rw-r--r-- | src/database/types.rs | 79 |
1 files changed, 75 insertions, 4 deletions
diff --git a/src/database/types.rs b/src/database/types.rs index 96efd7b..4656e49 100644 --- a/src/database/types.rs +++ b/src/database/types.rs @@ -28,26 +28,91 @@ impl std::convert::From<Date> for sqlite::Value { } } +#[derive(Clone, Copy, Debug, Serialize, Deserialize)] +pub enum Status { + Offline, + Online, + Away, + Busy, +} +impl std::convert::From<Status> for i64 { + fn from(s: Status) -> i64 { + match s { + Status::Offline => 0, + Status::Online => 1, + Status::Away => 2, + Status::Busy => 3, + } + } +} +impl std::convert::From<i64> for Status { + fn from(u: i64) -> Status { + match u { + 1 => Status::Online, + 2 => Status::Away, + 3 => Status::Busy, + _ => Status::Offline + } + } +} + +#[derive(Deserialize, Copy, Clone)] +pub enum DataField { + Desc, + StatusText, + DisplayName, +} +impl std::convert::From<DataField> for &str { + fn from(f: DataField) -> &'static str { + match f { + DataField::Desc => "desc", + DataField::StatusText => "statustext", + DataField::DisplayName => "displayname", + } + } +} +impl std::fmt::Display for DataField { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + DataField::Desc => write!(f, "desc"), + DataField::StatusText => write!(f, "statustext"), + DataField::DisplayName => write!(f, "displayname"), + } + } +} + #[derive(Serialize, Clone, Debug)] pub struct User { - username: String, + username: String, //Limit 20 id: UID, deleted: bool, + desc: String, // Limit 500 + displayname: String, // Limit 30 + statustext: String, //Limit 60 + status: Status, } impl User { pub fn new(username: String, id: UID) -> User { User { - username, + username: username.clone(), id, deleted: false, + desc: String::from(""), + displayname: username, + statustext: String::from(""), + status: Status::Offline, } } - pub fn construct(username: String, id: UID, deleted: bool) -> User { + pub fn construct(username: String, id: UID, deleted: bool, desc: String, displayname: String, statustext: String, status: i64) -> User { User { username, id, deleted, + desc, + displayname, + statustext, + status: Status::from(status), } } @@ -163,4 +228,10 @@ impl ReceiveMessage { date: Date::now(), } } -}
\ No newline at end of file +} + +#[derive(Deserialize, Clone)] +pub struct ReceiveUpdateField {pub user: UID, pub field: DataField, pub data: String} + +#[derive(Deserialize, Clone)] +pub struct ReceiveStatus {pub user: UID, pub status: Status}
\ No newline at end of file |