2020-07-02 16:19:04 +00:00
|
|
|
//! # Post
|
|
|
|
//!
|
|
|
|
//! @author Pierre Hubert
|
|
|
|
|
2020-07-02 17:05:05 +00:00
|
|
|
use crate::data::group_id::GroupID;
|
|
|
|
use crate::data::user::UserID;
|
|
|
|
|
2020-07-02 16:19:04 +00:00
|
|
|
#[allow(non_camel_case_types)]
|
|
|
|
pub enum PostVisibilityLevel {
|
|
|
|
//Posts that can be seen by anyone
|
|
|
|
VISIBILITY_PUBLIC = 1,
|
|
|
|
|
|
|
|
//Posts that can be seen by the friends of the user
|
|
|
|
VISIBILITY_FRIENDS = 2,
|
|
|
|
|
|
|
|
//Posts that can be seen by the user only
|
|
|
|
VISIBILITY_USER = 3,
|
|
|
|
|
|
|
|
//Posts that can be seen by the members of a group (same as friends)
|
|
|
|
VISIBILITY_GROUP_MEMBERS = 50,
|
|
|
|
}
|
|
|
|
|
2020-07-02 17:05:05 +00:00
|
|
|
impl PostVisibilityLevel {
|
|
|
|
pub fn to_api(&self) -> String {
|
|
|
|
match self {
|
|
|
|
PostVisibilityLevel::VISIBILITY_PUBLIC => "public",
|
|
|
|
PostVisibilityLevel::VISIBILITY_FRIENDS => "friends",
|
|
|
|
PostVisibilityLevel::VISIBILITY_USER => "private",
|
|
|
|
PostVisibilityLevel::VISIBILITY_GROUP_MEMBERS => "members",
|
|
|
|
}.to_string()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(non_camel_case_types)]
|
|
|
|
pub enum PostPageKind {
|
|
|
|
PAGE_KIND_USER(UserID),
|
|
|
|
PAGE_KIND_GROUP(GroupID),
|
|
|
|
}
|
|
|
|
|
2020-07-03 08:06:24 +00:00
|
|
|
#[allow(non_camel_case_types)]
|
|
|
|
pub enum PostKind {
|
|
|
|
POST_KIND_TEXT,
|
|
|
|
POST_KIND_IMAGE(PostFile),
|
|
|
|
POST_KIND_WEBLINK,
|
|
|
|
POST_KIND_PDF,
|
|
|
|
POST_KIND_MOVIE,
|
|
|
|
POST_KIND_COUNTDOWN,
|
|
|
|
POST_KIND_SURVEY,
|
|
|
|
POST_KIND_YOUTUBE,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PostKind {
|
|
|
|
pub fn to_api(&self) -> String {
|
|
|
|
match self {
|
|
|
|
PostKind::POST_KIND_TEXT => "text",
|
|
|
|
PostKind::POST_KIND_IMAGE(_) => "image",
|
|
|
|
PostKind::POST_KIND_WEBLINK => "weblink",
|
|
|
|
PostKind::POST_KIND_PDF => "pdf",
|
|
|
|
PostKind::POST_KIND_MOVIE => "movie",
|
|
|
|
PostKind::POST_KIND_COUNTDOWN => "countdown",
|
|
|
|
PostKind::POST_KIND_SURVEY => "survey",
|
|
|
|
PostKind::POST_KIND_YOUTUBE => "youtube",
|
|
|
|
}.to_string()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct PostFile {
|
|
|
|
pub path: String,
|
|
|
|
pub size: usize,
|
|
|
|
pub file_type: Option<String>,
|
|
|
|
}
|
|
|
|
|
2020-07-02 16:19:04 +00:00
|
|
|
pub struct Post {
|
2020-07-02 17:05:05 +00:00
|
|
|
pub id: u64,
|
|
|
|
pub user_id: UserID,
|
|
|
|
pub time_create: u64,
|
|
|
|
pub target_page: PostPageKind,
|
|
|
|
pub content: Option<String>,
|
|
|
|
pub visibility: PostVisibilityLevel,
|
2020-07-03 08:06:24 +00:00
|
|
|
pub kind: PostKind,
|
2020-07-02 17:05:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Post {
|
|
|
|
/// Get the ID of the target user page, if any
|
|
|
|
pub fn user_page_id(&self) -> Option<&UserID> {
|
|
|
|
match &self.target_page {
|
|
|
|
PostPageKind::PAGE_KIND_USER(id) => Some(id),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the ID of the target group page, if any
|
|
|
|
pub fn group_id(&self) -> Option<&GroupID> {
|
|
|
|
match &self.target_page {
|
|
|
|
PostPageKind::PAGE_KIND_GROUP(id) => Some(id),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
2020-07-02 16:19:04 +00:00
|
|
|
}
|