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

65 lines
1.6 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-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,
}
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
}