use chrono::{DateTime, Utc};
#[derive(Deserialize, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum GithubType {
Org,
Repo,
#[serde(rename = "ONETOONE")]
OneToOne,
OrgChannel,
RepoChannel,
UserChannel,
}
#[derive(Deserialize, Debug)]
pub struct Room {
pub id: String,
pub name: String,
pub topic: String,
pub uri: Option<String>,
#[serde(rename = "oneToOne")]
pub one_to_one: bool,
#[serde(rename = "userCount")]
pub user_count: i32,
#[serde(rename = "unreadItems")]
pub unread_items: i32,
pub mentions: i32,
#[serde(rename = "lastAccessTime")]
pub last_access_time: Option<DateTime<Utc>>,
pub lurk: bool,
pub url: String,
#[serde(rename = "githubType")]
pub github_type: GithubType,
pub tags: Option<Vec<String>>,
#[serde(rename = "roomMember")]
pub room_member: bool,
#[serde(rename = "v")]
pub version: Option<i32>,
}
#[derive(Serialize, Debug)]
pub struct JoinRoom {
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub uri: Option<String>,
}
impl JoinRoom {
pub fn from_id<S>(id: S) -> JoinRoom
where S: AsRef<str>
{
JoinRoom {
id: Some(id.as_ref().to_string()),
uri: None,
}
}
pub fn from_uri<S>(uri: S) -> JoinRoom
where S: AsRef<str>
{
JoinRoom {
id: None,
uri: Some(uri.as_ref().to_string()),
}
}
}
#[derive(Serialize, Debug)]
pub struct UpdateRoom {
#[serde(skip_serializing_if = "Option::is_none")]
pub topic: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub noindex: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<String>
}
impl UpdateRoom {
pub fn from_topic<S>(topic: S) -> UpdateRoom
where S: AsRef<str>
{
UpdateRoom {
topic: Some(topic.as_ref().to_string()),
noindex: None,
tags: None
}
}
pub fn from_noindex(noindex: bool) -> UpdateRoom {
UpdateRoom {
topic: None,
noindex: Some(noindex),
tags: None
}
}
pub fn from_tags<S>(tags: S) -> UpdateRoom
where S: AsRef<str>
{
UpdateRoom {
topic: None,
noindex: None,
tags: Some(tags.as_ref().to_string()),
}
}
}
#[derive(Deserialize, Debug, Clone)]
pub struct User {
pub id: String,
pub username: String,
#[serde(rename = "displayName")]
pub display_name: String,
pub url: String,
#[serde(rename = "avatarUrl")]
pub avatar_url: Option<String>,
#[serde(rename = "avatarUrlSmall")]
pub avatar_url_small: Option<String>,
#[serde(rename = "avatarUrlMedium")]
pub avatar_url_medium: Option<String>,
#[serde(rename = "v")]
pub version: Option<i32>,
}
#[derive(Deserialize, Debug)]
pub struct Message {
pub id: String,
pub text: String,
pub html: String,
pub sent: DateTime<Utc>,
#[serde(rename = "editedAt")]
pub edited_at: Option<DateTime<Utc>>,
#[serde(rename = "fromUser")]
pub from: User,
pub unread: bool,
#[serde(rename = "readBy")]
pub read_by: i32,
pub urls: Vec<Url>,
pub mentions: Vec<Mention>,
pub issues: Vec<Issue>,
#[serde(rename = "v")]
pub version: Option<i32>,
}
#[derive(Serialize, Debug)]
pub struct OutMessage<'a> {
pub text: &'a str,
}
#[derive(Deserialize, Debug)]
pub struct Mention {
#[serde(rename = "screenName")]
pub screen_name: String,
#[serde(rename = "userId")]
pub user_id: String,
pub announcement: Option<bool>,
pub group: Option<bool>,
}
#[derive(Deserialize, Debug)]
pub struct Issue {
pub number: String,
}
#[derive(Deserialize, Debug)]
pub struct Url {
pub url: String,
}
#[derive(Deserialize, Debug)]
pub struct SearchResult {
#[serde(rename = "results")]
pub rooms: Vec<Room>,
}
#[derive(Deserialize, Debug)]
pub struct Group {
pub id: String,
pub name: String,
pub uri: String,
#[serde(rename = "backedBy")]
pub backed_by: BackedBy,
#[serde(rename = "avatarUrl")]
pub avatar_url: String,
}
#[derive(Deserialize, Debug)]
pub struct BackedBy {
#[serde(rename = "type")]
pub group_type: Option<GroupType>,
#[serde(rename = "linkPath")]
pub link_path: Option<String>,
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum GroupType {
OneToOne,
GhRepo,
GhOrg,
GhUser,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct UnreadItems {
pub chat: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub mention: Option<Vec<String>>,
}
impl UnreadItems {
pub fn from_msg_ids(msg_ids: &[String]) -> UnreadItems {
UnreadItems {
chat: Some(msg_ids.to_owned()),
mention: None,
}
}
}
#[derive(Deserialize, Debug)]
pub struct Organization {
pub id: u64,
pub name: String,
#[serde(rename = "avatarUrl")]
pub avatar_url: Option<String>,
pub room: Option<Room>,
}
#[derive(Deserialize, Debug)]
pub struct Repository {
pub id: u64,
pub name: String,
pub uri: String,
pub private: bool,
pub room: Option<Room>,
}
#[derive(Deserialize, Debug)]
pub struct Channel {
pub id: String,
pub name: String,
pub topic: String,
pub uri: Option<String>,
#[serde(rename = "oneToOne")]
pub one_to_one: bool,
#[serde(rename = "unreadItems")]
pub unread_items: i32,
pub mentions: i32,
#[serde(rename = "lastAccessTime")]
pub last_access_time: Option<DateTime<Utc>>,
pub lurk: bool,
pub url: String,
#[serde(rename = "githubType")]
pub github_type: GithubType,
pub security: String,
}