mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-25 23:09:22 +00:00
Returns the list of conversations for a group in the API
This commit is contained in:
parent
fbc1a59829
commit
16ba9486f7
@ -3,11 +3,12 @@
|
|||||||
//! @author Pierre Hubert
|
//! @author Pierre Hubert
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use crate::api_data::conversation_api::ConversationAPI;
|
||||||
use crate::api_data::group_api::GroupApi;
|
use crate::api_data::group_api::GroupApi;
|
||||||
use crate::data::error::ResultBoxError;
|
use crate::data::error::ResultBoxError;
|
||||||
use crate::data::group::Group;
|
use crate::data::group::Group;
|
||||||
use crate::data::user::UserID;
|
use crate::data::user::UserID;
|
||||||
use crate::helpers::likes_helper;
|
use crate::helpers::{conversations_helper, groups_helper, likes_helper};
|
||||||
use crate::helpers::likes_helper::LikeType;
|
use crate::helpers::likes_helper::LikeType;
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
@ -21,19 +22,28 @@ pub struct AdvancedGroupApi {
|
|||||||
url: String,
|
url: String,
|
||||||
number_likes: u64,
|
number_likes: u64,
|
||||||
is_liking: bool,
|
is_liking: bool,
|
||||||
|
conversations: Vec<ConversationAPI>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AdvancedGroupApi {
|
impl AdvancedGroupApi {
|
||||||
/// Construct a new advanced group membership instance
|
/// Construct a new advanced group membership instance
|
||||||
pub fn new(g: &Group, user_id: Option<UserID>) -> ResultBoxError<AdvancedGroupApi> {
|
pub fn new(g: &Group, user_id: Option<UserID>) -> ResultBoxError<AdvancedGroupApi> {
|
||||||
|
let membership = groups_helper::get_membership(&g.id, user_id.clone())?;
|
||||||
|
|
||||||
|
let conversations = conversations_helper::get_list_group(&g.id)?
|
||||||
|
.into_iter()
|
||||||
|
.filter(|p| p.min_group_membership_level.as_ref().unwrap() >= &membership.level)
|
||||||
|
.collect();
|
||||||
|
|
||||||
Ok(AdvancedGroupApi {
|
Ok(AdvancedGroupApi {
|
||||||
base_info: GroupApi::new(g, user_id.clone())?,
|
base_info: GroupApi::new_with_level(g, &membership)?,
|
||||||
is_members_list_public: g.is_members_list_public,
|
is_members_list_public: g.is_members_list_public,
|
||||||
time_create: g.time_create,
|
time_create: g.time_create,
|
||||||
description: g.description.clone().unwrap_or("null".to_string()),
|
description: g.description.clone().unwrap_or("null".to_string()),
|
||||||
url: g.url.clone().unwrap_or("null".to_string()),
|
url: g.url.clone().unwrap_or("null".to_string()),
|
||||||
number_likes: likes_helper::count(g.id.id(), LikeType::GROUP)? as u64,
|
number_likes: likes_helper::count(g.id.id(), LikeType::GROUP)? as u64,
|
||||||
is_liking: likes_helper::is_liking(&user_id.unwrap_or(UserID::invalid()), g.id.id(), LikeType::GROUP)?,
|
is_liking: likes_helper::is_liking(&user_id.unwrap_or(UserID::invalid()), g.id.id(), LikeType::GROUP)?,
|
||||||
|
conversations: ConversationAPI::for_list(&conversations),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,8 +3,9 @@
|
|||||||
//! @author Pierre Hubert
|
//! @author Pierre Hubert
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::data::error::ResultBoxError;
|
use crate::data::error::Res;
|
||||||
use crate::data::group::Group;
|
use crate::data::group::Group;
|
||||||
|
use crate::data::group_member::GroupMember;
|
||||||
use crate::data::user::UserID;
|
use crate::data::user::UserID;
|
||||||
use crate::helpers::groups_helper;
|
use crate::helpers::groups_helper;
|
||||||
|
|
||||||
@ -24,9 +25,14 @@ pub struct GroupApi {
|
|||||||
|
|
||||||
impl GroupApi {
|
impl GroupApi {
|
||||||
/// Construct a new group membership instance
|
/// Construct a new group membership instance
|
||||||
pub fn new(g: &Group, user_id: Option<UserID>) -> ResultBoxError<GroupApi> {
|
pub fn new(g: &Group, user_id: Option<UserID>) -> Res<GroupApi> {
|
||||||
let membership = groups_helper::get_membership(&g.id, user_id)?;
|
let membership = groups_helper::get_membership(&g.id, user_id)?;
|
||||||
|
|
||||||
|
Self::new_with_level(g, &membership)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Construct a new group membership instance
|
||||||
|
pub fn new_with_level(g: &Group, membership: &GroupMember) -> Res<GroupApi> {
|
||||||
Ok(GroupApi {
|
Ok(GroupApi {
|
||||||
id: g.id.id(),
|
id: g.id.id(),
|
||||||
name: g.name.clone(),
|
name: g.name.clone(),
|
||||||
|
Loading…
Reference in New Issue
Block a user