10 changed files with 157 additions and 127 deletions
@ -0,0 +1,12 @@
|
||||
extern crate serde_json; |
||||
|
||||
use self::serde_json::Value as JsonValue; |
||||
|
||||
#[derive(Debug)] |
||||
pub struct Event { |
||||
pub sender: String, |
||||
pub stype: String, |
||||
pub room: String, |
||||
pub id: String, |
||||
pub content: JsonValue, |
||||
} |
||||
@ -0,0 +1,20 @@
|
||||
use std::collections::HashMap; |
||||
|
||||
#[derive(Debug)] |
||||
pub struct Member { |
||||
pub alias: String, |
||||
pub uid: String, |
||||
pub avatar: String, |
||||
} |
||||
|
||||
impl Member { |
||||
pub fn get_alias(&self) -> String { |
||||
match self.alias { |
||||
ref a if a.is_empty() => self.uid.clone(), |
||||
ref a => a.clone(), |
||||
} |
||||
} |
||||
} |
||||
|
||||
// hashmap userid -> Member
|
||||
pub type MemberList = HashMap<String, Member>; |
||||
@ -0,0 +1,32 @@
|
||||
extern crate chrono; |
||||
|
||||
use self::chrono::prelude::*; |
||||
|
||||
#[derive(Debug)] |
||||
#[derive(PartialEq, PartialOrd)] |
||||
pub struct Message { |
||||
pub sender: String, |
||||
pub mtype: String, |
||||
pub body: String, |
||||
pub date: DateTime<Local>, |
||||
pub room: String, |
||||
pub thumb: String, |
||||
pub url: String, |
||||
pub id: String, |
||||
} |
||||
|
||||
impl Clone for Message { |
||||
fn clone(&self) -> Message { |
||||
Message { |
||||
sender: self.sender.clone(), |
||||
mtype: self.mtype.clone(), |
||||
body: self.body.clone(), |
||||
date: self.date.clone(), |
||||
room: self.room.clone(), |
||||
thumb: self.thumb.clone(), |
||||
url: self.url.clone(), |
||||
id: self.id.clone(), |
||||
} |
||||
} |
||||
} |
||||
|
||||
@ -0,0 +1,5 @@
|
||||
pub mod member; |
||||
pub mod room; |
||||
pub mod protocol; |
||||
pub mod event; |
||||
pub mod message; |
||||
@ -0,0 +1,5 @@
|
||||
#[derive(Debug)] |
||||
pub struct Protocol { |
||||
pub id: String, |
||||
pub desc: String, |
||||
} |
||||
@ -0,0 +1,44 @@
|
||||
#[derive(Debug)] |
||||
pub struct Room { |
||||
pub id: String, |
||||
pub avatar: String, |
||||
pub name: String, |
||||
pub topic: String, |
||||
pub alias: String, |
||||
pub guest_can_join: bool, |
||||
pub world_readable: bool, |
||||
pub members: i32, |
||||
pub notifications: i32, |
||||
} |
||||
|
||||
impl Room { |
||||
pub fn new(id: String, name: String) -> Room { |
||||
Room { |
||||
id: id, |
||||
name: name, |
||||
avatar: String::new(), |
||||
topic: String::new(), |
||||
alias: String::new(), |
||||
guest_can_join: true, |
||||
world_readable: true, |
||||
members: 0, |
||||
notifications: 0, |
||||
} |
||||
} |
||||
} |
||||
|
||||
impl Clone for Room { |
||||
fn clone(&self) -> Room { |
||||
Room { |
||||
id: self.id.clone(), |
||||
name: self.name.clone(), |
||||
avatar: self.avatar.clone(), |
||||
topic: self.topic.clone(), |
||||
alias: self.alias.clone(), |
||||
guest_can_join: self.guest_can_join, |
||||
world_readable: self.world_readable, |
||||
members: self.members, |
||||
notifications: self.notifications, |
||||
} |
||||
} |
||||
} |
||||
@ -1,109 +1,6 @@
|
||||
extern crate chrono; |
||||
extern crate serde_json; |
||||
|
||||
use self::chrono::prelude::*; |
||||
use self::serde_json::Value as JsonValue; |
||||
|
||||
#[derive(Debug)] |
||||
#[derive(PartialEq, PartialOrd)] |
||||
pub struct Message { |
||||
pub sender: String, |
||||
pub mtype: String, |
||||
pub body: String, |
||||
pub date: DateTime<Local>, |
||||
pub room: String, |
||||
pub thumb: String, |
||||
pub url: String, |
||||
pub id: String, |
||||
} |
||||
|
||||
impl Clone for Message { |
||||
fn clone(&self) -> Message { |
||||
Message { |
||||
sender: self.sender.clone(), |
||||
mtype: self.mtype.clone(), |
||||
body: self.body.clone(), |
||||
date: self.date.clone(), |
||||
room: self.room.clone(), |
||||
thumb: self.thumb.clone(), |
||||
url: self.url.clone(), |
||||
id: self.id.clone(), |
||||
} |
||||
} |
||||
} |
||||
|
||||
#[derive(Debug)] |
||||
pub struct Member { |
||||
pub alias: String, |
||||
pub uid: String, |
||||
pub avatar: String, |
||||
} |
||||
|
||||
impl Member { |
||||
pub fn get_alias(&self) -> String { |
||||
match self.alias { |
||||
ref a if a.is_empty() => self.uid.clone(), |
||||
ref a => a.clone(), |
||||
} |
||||
} |
||||
} |
||||
|
||||
#[derive(Debug)] |
||||
pub struct Protocol { |
||||
pub id: String, |
||||
pub desc: String, |
||||
} |
||||
|
||||
#[derive(Debug)] |
||||
pub struct Room { |
||||
pub id: String, |
||||
pub avatar: String, |
||||
pub name: String, |
||||
pub topic: String, |
||||
pub alias: String, |
||||
pub guest_can_join: bool, |
||||
pub world_readable: bool, |
||||
pub members: i32, |
||||
pub notifications: i32, |
||||
} |
||||
|
||||
impl Room { |
||||
pub fn new(id: String, name: String) -> Room { |
||||
Room { |
||||
id: id, |
||||
name: name, |
||||
avatar: String::new(), |
||||
topic: String::new(), |
||||
alias: String::new(), |
||||
guest_can_join: true, |
||||
world_readable: true, |
||||
members: 0, |
||||
notifications: 0, |
||||
} |
||||
} |
||||
} |
||||
|
||||
impl Clone for Room { |
||||
fn clone(&self) -> Room { |
||||
Room { |
||||
id: self.id.clone(), |
||||
name: self.name.clone(), |
||||
avatar: self.avatar.clone(), |
||||
topic: self.topic.clone(), |
||||
alias: self.alias.clone(), |
||||
guest_can_join: self.guest_can_join, |
||||
world_readable: self.world_readable, |
||||
members: self.members, |
||||
notifications: self.notifications, |
||||
} |
||||
} |
||||
} |
||||
|
||||
#[derive(Debug)] |
||||
pub struct Event { |
||||
pub sender: String, |
||||
pub stype: String, |
||||
pub room: String, |
||||
pub id: String, |
||||
pub content: JsonValue, |
||||
} |
||||
pub use model::event::Event; |
||||
pub use model::room::Room; |
||||
pub use model::protocol::Protocol; |
||||
pub use model::message::Message; |
||||
pub use model::member::Member; |
||||
pub use model::member::MemberList; |
||||
|
||||
Loading…
Reference in new issue