1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-01-03 17:38:50 +00:00
comunicapiv3/src/data/post.rs

106 lines
2.7 KiB
Rust
Raw Normal View History

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:18:26 +00:00
pub struct PostFile {
pub path: String,
pub size: usize,
pub file_type: Option<String>,
}
pub struct PostWebLink {
pub url: String,
pub title: Option<String>,
pub description: Option<String>,
pub image: Option<String>,
}
2020-07-03 08:06:24 +00:00
#[allow(non_camel_case_types)]
pub enum PostKind {
POST_KIND_TEXT,
POST_KIND_IMAGE(PostFile),
2020-07-03 08:18:26 +00:00
POST_KIND_WEBLINK(PostWebLink),
2020-07-03 08:27:09 +00:00
POST_KIND_PDF(PostFile),
2020-07-03 14:41:14 +00:00
POST_KIND_MOVIE(u64), // The ID of the movie
2020-07-03 08:06:24 +00:00
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",
2020-07-03 08:18:26 +00:00
PostKind::POST_KIND_WEBLINK(_) => "weblink",
2020-07-03 08:27:09 +00:00
PostKind::POST_KIND_PDF(_) => "pdf",
2020-07-03 14:41:14 +00:00
PostKind::POST_KIND_MOVIE(_) => "movie",
2020-07-03 08:06:24 +00:00
PostKind::POST_KIND_COUNTDOWN => "countdown",
PostKind::POST_KIND_SURVEY => "survey",
PostKind::POST_KIND_YOUTUBE => "youtube",
}.to_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
}