1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-26 15:29:21 +00:00

Can check if a user is a moderator of a conversation or not

This commit is contained in:
Pierre HUBERT 2020-06-12 11:26:12 +02:00
parent f3a96ffad1
commit fad9300771
2 changed files with 13 additions and 0 deletions

View File

@ -63,5 +63,10 @@ pub fn get_single(r: &mut HttpRequestHandler) -> RequestResult {
/// Update the settings of a conversation /// Update the settings of a conversation
pub fn update_settings(r: &mut HttpRequestHandler) -> RequestResult { pub fn update_settings(r: &mut HttpRequestHandler) -> RequestResult {
let conv_id = r.post_conv_id("conversationID")?;
let is_moderator = conversations_helper::is_user_moderator(r.user_id()?, conv_id)?;
println!("conv id: {} / is moderator: {}", conv_id, is_moderator);
r.success("implement it") r.success("implement it")
} }

View File

@ -107,6 +107,14 @@ pub fn does_user_belongs_to(user_id: UserID, conv_id: u64) -> ResultBoxError<boo
.exec_count()? > 0) .exec_count()? > 0)
} }
/// Check out wheter a user is the moderator of a conversation or not
pub fn is_user_moderator(user_id: UserID, conv_id: u64) -> ResultBoxError<bool> {
Ok(database::QueryInfo::new(CONV_LIST_TABLE)
.cond_u64("id", conv_id)
.cond_user_id("user_id", user_id)
.exec_count()? > 0)
}
/// Turn a database entry into a ConversationInfo object /// Turn a database entry into a ConversationInfo object
fn db_to_conversation_info(row: &database::RowResult) -> ResultBoxError<Conversation> { fn db_to_conversation_info(row: &database::RowResult) -> ResultBoxError<Conversation> {
let conv_id = row.get_u64("id")?; let conv_id = row.get_u64("id")?;