mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 13:29:21 +00:00
Automatically update conversations membership based on group membership update
This commit is contained in:
parent
7f81bc21c6
commit
fbc1a59829
@ -314,8 +314,6 @@ pub fn send_request(r: &mut HttpRequestHandler) -> RequestResult {
|
|||||||
following: true,
|
following: true,
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
// TODO : if the user has already the "member" level, gives him access to conversations
|
|
||||||
|
|
||||||
// Send a notification, if required
|
// Send a notification, if required
|
||||||
if matches!(group.registration_level, GroupRegistrationLevel::MODERATED_REGISTRATION) {
|
if matches!(group.registration_level, GroupRegistrationLevel::MODERATED_REGISTRATION) {
|
||||||
notifications_helper::create_group_membership_notification(r.user_id_ref()?, None,
|
notifications_helper::create_group_membership_notification(r.user_id_ref()?, None,
|
||||||
|
@ -132,6 +132,13 @@ pub fn get_list_user(user_id: &UserID) -> ResultBoxError<Vec<Conversation>> {
|
|||||||
.exec(db_to_conversation_info)
|
.exec(db_to_conversation_info)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the list of conversations of a group
|
||||||
|
pub fn get_list_group(group_id: &GroupID) -> Res<Vec<Conversation>> {
|
||||||
|
database::QueryInfo::new(CONV_LIST_TABLE)
|
||||||
|
.cond_group_id("group_id", group_id)
|
||||||
|
.exec(db_to_conversation_info)
|
||||||
|
}
|
||||||
|
|
||||||
/// Get information about a single conversation
|
/// Get information about a single conversation
|
||||||
pub fn get_single(conv_id: ConvID) -> ResultBoxError<Conversation> {
|
pub fn get_single(conv_id: ConvID) -> ResultBoxError<Conversation> {
|
||||||
// Tables
|
// Tables
|
||||||
@ -469,6 +476,15 @@ pub fn remove_user_from_conversation(user_id: &UserID, conv: &Conversation, remo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Update members list for all the conversations of a given group
|
||||||
|
pub fn update_members_list_for_group_conversations(group_id: &GroupID) -> Res {
|
||||||
|
for conv in get_list_group(group_id)? {
|
||||||
|
update_members_list_for_group_conversation(conv.id)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Update the list of members for a group conversation
|
/// Update the list of members for a group conversation
|
||||||
pub fn update_members_list_for_group_conversation(conv_id: ConvID) -> Res {
|
pub fn update_members_list_for_group_conversation(conv_id: ConvID) -> Res {
|
||||||
let conv = get_single(conv_id)?;
|
let conv = get_single(conv_id)?;
|
||||||
@ -537,6 +553,15 @@ pub fn delete_conversation(conv: &Conversation) -> ResultBoxError<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Delete all the conversations of a group
|
||||||
|
pub fn delete_all_group_conversations(group_id: &GroupID) -> Res {
|
||||||
|
for conv in get_list_group(group_id)? {
|
||||||
|
delete_conversation(&conv)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Delete a conversation membership
|
/// Delete a conversation membership
|
||||||
pub fn remove_member(user_id: &UserID, conv_id: ConvID, remover: Option<&UserID>) -> ResultBoxError<()> {
|
pub fn remove_member(user_id: &UserID, conv_id: ConvID, remover: Option<&UserID>) -> ResultBoxError<()> {
|
||||||
for msg in get_user_messages_for_conversations(conv_id, user_id)? {
|
for msg in get_user_messages_for_conversations(conv_id, user_id)? {
|
||||||
|
@ -9,7 +9,7 @@ use crate::data::group_id::GroupID;
|
|||||||
use crate::data::group_member::{GroupMember, GroupMembershipLevel};
|
use crate::data::group_member::{GroupMember, GroupMembershipLevel};
|
||||||
use crate::data::new_group::NewGroup;
|
use crate::data::new_group::NewGroup;
|
||||||
use crate::data::user::UserID;
|
use crate::data::user::UserID;
|
||||||
use crate::helpers::{database, likes_helper, notifications_helper, posts_helper};
|
use crate::helpers::{database, likes_helper, notifications_helper, posts_helper, conversations_helper};
|
||||||
use crate::helpers::likes_helper::LikeType;
|
use crate::helpers::likes_helper::LikeType;
|
||||||
use crate::utils::date_utils::time;
|
use crate::utils::date_utils::time;
|
||||||
|
|
||||||
@ -123,7 +123,13 @@ pub fn insert_member(m: &GroupMember) -> ResultBoxError<()> {
|
|||||||
.add_user_id("user_id", &m.user_id)
|
.add_user_id("user_id", &m.user_id)
|
||||||
.add_u64("time_create", m.time_create)
|
.add_u64("time_create", m.time_create)
|
||||||
.add_u32("level", m.level.to_db())
|
.add_u32("level", m.level.to_db())
|
||||||
.insert_drop_result()
|
.insert_drop_result()?;
|
||||||
|
|
||||||
|
if m.level.is_at_least_member() {
|
||||||
|
conversations_helper::update_members_list_for_group_conversations(&m.group_id)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove a user's membership
|
/// Remove a user's membership
|
||||||
@ -131,9 +137,12 @@ pub fn delete_member(group_id: &GroupID, user_id: &UserID) -> ResultBoxError {
|
|||||||
database::DeleteQuery::new(GROUPS_MEMBERS_TABLE)
|
database::DeleteQuery::new(GROUPS_MEMBERS_TABLE)
|
||||||
.cond_group_id("groups_id", group_id)
|
.cond_group_id("groups_id", group_id)
|
||||||
.cond_user_id("user_id", user_id)
|
.cond_user_id("user_id", user_id)
|
||||||
.exec()
|
.exec()?;
|
||||||
|
|
||||||
// TODO : Update access to group's conversations
|
// Update access to group's conversations
|
||||||
|
conversations_helper::update_members_list_for_group_conversations(&group_id)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update a user's membership level
|
/// Update a user's membership level
|
||||||
@ -142,9 +151,12 @@ pub fn update_membership_level(group_id: &GroupID, user_id: &UserID, new_level:
|
|||||||
.cond_user_id("user_id", user_id)
|
.cond_user_id("user_id", user_id)
|
||||||
.cond_group_id("groups_id", group_id)
|
.cond_group_id("groups_id", group_id)
|
||||||
.set_u32("level", new_level.to_db())
|
.set_u32("level", new_level.to_db())
|
||||||
.exec()
|
.exec()?;
|
||||||
|
|
||||||
// TODO : Update access to group's conversations
|
// Update access to group's conversations
|
||||||
|
conversations_helper::update_members_list_for_group_conversations(&group_id)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update following status of a user
|
/// Update following status of a user
|
||||||
@ -491,7 +503,8 @@ pub fn delete(group_id: &GroupID) -> ResultBoxError {
|
|||||||
// Delete all group related notifications
|
// Delete all group related notifications
|
||||||
notifications_helper::delete_all_related_with_group(group_id)?;
|
notifications_helper::delete_all_related_with_group(group_id)?;
|
||||||
|
|
||||||
// TODO : delete all conversations related with the group
|
// Delete all conversations related with the group
|
||||||
|
conversations_helper::delete_all_group_conversations(group_id)?;
|
||||||
|
|
||||||
// Delete all group members
|
// Delete all group members
|
||||||
database::DeleteQuery::new(GROUPS_MEMBERS_TABLE)
|
database::DeleteQuery::new(GROUPS_MEMBERS_TABLE)
|
||||||
|
Loading…
Reference in New Issue
Block a user