mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-20 08:25:16 +00:00
Complete information
This commit is contained in:
@ -2,6 +2,9 @@
|
||||
//!
|
||||
//! @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
|
||||
@ -17,6 +20,46 @@ pub enum PostVisibilityLevel {
|
||||
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 Post {
|
||||
pub id: u64
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user