mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-21 17:05:16 +00:00
Return group information to API
This commit is contained in:
@ -2,7 +2,9 @@
|
||||
//!
|
||||
//! Group visibility level
|
||||
|
||||
use crate::constants::DEFAULT_GROUP_LOGO;
|
||||
use crate::data::group_id::GroupID;
|
||||
use crate::utils::user_data_utils::user_data_url;
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Eq, PartialEq, Hash, Debug)]
|
||||
@ -12,6 +14,16 @@ pub enum GroupVisibilityLevel {
|
||||
SECRETE_GROUP,
|
||||
}
|
||||
|
||||
impl GroupVisibilityLevel {
|
||||
pub fn to_api(&self) -> String {
|
||||
match self {
|
||||
GroupVisibilityLevel::OPEN_GROUP => "open",
|
||||
GroupVisibilityLevel::PRIVATE_GROUP => "private",
|
||||
GroupVisibilityLevel::SECRETE_GROUP => "secrete",
|
||||
}.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Eq, PartialEq, Hash, Debug)]
|
||||
pub enum GroupRegistrationLevel {
|
||||
@ -20,6 +32,16 @@ pub enum GroupRegistrationLevel {
|
||||
CLOSED_REGISTRATION = 2,
|
||||
}
|
||||
|
||||
impl GroupRegistrationLevel {
|
||||
pub fn to_api(&self) -> String {
|
||||
match self {
|
||||
GroupRegistrationLevel::OPEN_REGISTRATION => "open",
|
||||
GroupRegistrationLevel::MODERATED_REGISTRATION => "moderated",
|
||||
GroupRegistrationLevel::CLOSED_REGISTRATION => "closed",
|
||||
}.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Eq, PartialEq, Hash, Debug)]
|
||||
pub enum GroupPostsCreationLevel {
|
||||
@ -30,6 +52,15 @@ pub enum GroupPostsCreationLevel {
|
||||
POSTS_LEVEL_ALL_MEMBERS = 1,
|
||||
}
|
||||
|
||||
impl GroupPostsCreationLevel {
|
||||
pub fn to_api(&self) -> String {
|
||||
match self {
|
||||
GroupPostsCreationLevel::POSTS_LEVEL_MODERATORS => "moderators",
|
||||
GroupPostsCreationLevel::POSTS_LEVEL_ALL_MEMBERS => "members",
|
||||
}.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Eq, PartialEq, Hash, Debug, PartialOrd)]
|
||||
pub enum GroupAccessLevel {
|
||||
@ -57,7 +88,6 @@ pub enum GroupAccessLevel {
|
||||
pub struct Group {
|
||||
pub id: GroupID,
|
||||
pub name: String,
|
||||
pub members_count: u64,
|
||||
pub visibility: GroupVisibilityLevel,
|
||||
pub registration_level: GroupRegistrationLevel,
|
||||
pub posts_creation_level: GroupPostsCreationLevel,
|
||||
@ -68,6 +98,21 @@ pub struct Group {
|
||||
pub url: Option<String>,
|
||||
}
|
||||
|
||||
impl Group {
|
||||
/// Determine the path of the logo to use for this group
|
||||
pub fn get_logo_path(&self) -> &str {
|
||||
match &self.logo {
|
||||
None => DEFAULT_GROUP_LOGO,
|
||||
Some(l) => l,
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the current URL for the logo of this group
|
||||
pub fn get_logo_url(&self) -> String {
|
||||
user_data_url(self.get_logo_path())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::data::group::GroupAccessLevel;
|
||||
|
@ -15,6 +15,19 @@ pub enum GroupMembershipLevel {
|
||||
VISITOR = 5, //Simple visit
|
||||
}
|
||||
|
||||
impl GroupMembershipLevel {
|
||||
pub fn to_api(&self) -> String {
|
||||
match self {
|
||||
GroupMembershipLevel::ADMINISTRATOR => "administrator",
|
||||
GroupMembershipLevel::MODERATOR => "moderator",
|
||||
GroupMembershipLevel::MEMBER => "member",
|
||||
GroupMembershipLevel::INVITED => "invited",
|
||||
GroupMembershipLevel::PENDING => "pending",
|
||||
GroupMembershipLevel::VISITOR => "visitor",
|
||||
}.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GroupMember {
|
||||
pub id: u64,
|
||||
pub user_id: UserID,
|
||||
|
Reference in New Issue
Block a user