mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-21 08:55:16 +00:00
Can get the list of memberships of a user
This commit is contained in:
@ -9,7 +9,7 @@ use crate::data::group_id::GroupID;
|
||||
use crate::data::group_member::{GroupMember, GroupMembershipLevel};
|
||||
use crate::data::new_group::NewGroup;
|
||||
use crate::data::user::UserID;
|
||||
use crate::helpers::database;
|
||||
use crate::helpers::{database, posts_helper};
|
||||
use crate::utils::date_utils::time;
|
||||
|
||||
impl GroupVisibilityLevel {
|
||||
@ -346,6 +346,24 @@ pub fn check_directory_availability(dir: &str, group_id: Option<GroupID>) -> Res
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the last activity time of a group
|
||||
pub fn get_last_activity(user_id: &UserID, group_id: &GroupID) -> ResultBoxError<u64> {
|
||||
let last_post = posts_helper::PostsQuery::new(user_id.as_option())
|
||||
.set_limit(1)
|
||||
.get_group(group_id)?;
|
||||
|
||||
match last_post.first() {
|
||||
None => {
|
||||
// No post was found
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
Some(p) => {
|
||||
Ok(p.time_create)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Set new settings to the group, except group logo
|
||||
pub fn set_settings(g: &Group) -> ResultBoxError {
|
||||
database::UpdateInfo::new(GROUPS_LIST_TABLE)
|
||||
|
@ -14,4 +14,5 @@ pub mod virtual_directory_helper;
|
||||
pub mod movies_helper;
|
||||
pub mod survey_helper;
|
||||
pub mod comments_helper;
|
||||
pub mod notifications_helper;
|
||||
pub mod notifications_helper;
|
||||
pub mod webapp_helper;
|
34
src/helpers/webapp_helper.rs
Normal file
34
src/helpers/webapp_helper.rs
Normal file
@ -0,0 +1,34 @@
|
||||
//! # Web Application Helper
|
||||
//!
|
||||
//! Contains methods specific to Comunic Web applications
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
|
||||
use crate::data::error::ResultBoxError;
|
||||
use crate::data::user::UserID;
|
||||
use crate::data::user_membership::UserMembership;
|
||||
use crate::helpers::{conversations_helper, friends_helper, groups_helper};
|
||||
|
||||
/// Get all the memberships of a user
|
||||
pub fn get_user_memberships(user_id: &UserID) -> ResultBoxError<Vec<UserMembership>> {
|
||||
let friends = friends_helper::GetFriendsQuery::new(user_id)
|
||||
.exec()?;
|
||||
let groups = groups_helper::get_list_user(user_id, false)?;
|
||||
let conversations_list = conversations_helper::get_list_user(user_id)?;
|
||||
|
||||
let mut list = Vec::new();
|
||||
|
||||
for friend in friends {
|
||||
list.push(UserMembership::Friend(friend));
|
||||
}
|
||||
|
||||
for group in &groups {
|
||||
list.push(UserMembership::Group(group.clone(), groups_helper::get_last_activity(user_id, group)?));
|
||||
}
|
||||
|
||||
for conv in conversations_list {
|
||||
list.push(UserMembership::Conversation(conv))
|
||||
}
|
||||
|
||||
Ok(list)
|
||||
}
|
Reference in New Issue
Block a user