//! # Post //! //! @author Pierre Hubert use crate::data::group_id::GroupID; use crate::data::user::UserID; #[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, } 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), } pub struct PostFile { pub path: String, pub size: usize, pub file_type: Option, } pub struct PostWebLink { pub url: String, pub title: Option, pub description: Option, pub image: Option, } #[allow(non_camel_case_types)] pub enum PostKind { POST_KIND_TEXT, POST_KIND_IMAGE(PostFile), POST_KIND_WEBLINK(PostWebLink), POST_KIND_PDF(PostFile), 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 Post { pub id: u64, pub user_id: UserID, pub time_create: u64, pub target_page: PostPageKind, pub content: Option, pub visibility: PostVisibilityLevel, pub kind: PostKind, } 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, } } }