mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-21 17:05:16 +00:00
Load post comments
This commit is contained in:
29
src/helpers/comments_helper.rs
Normal file
29
src/helpers/comments_helper.rs
Normal file
@ -0,0 +1,29 @@
|
||||
//! # Comments helper
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
|
||||
use crate::constants::database_tables_names::COMMENTS_TABLE;
|
||||
use crate::data::comment::Comment;
|
||||
use crate::data::error::ResultBoxError;
|
||||
use crate::helpers::database;
|
||||
|
||||
/// Get the comments of a post
|
||||
pub fn get(post_id: u64) -> ResultBoxError<Vec<Comment>> {
|
||||
database::QueryInfo::new(COMMENTS_TABLE)
|
||||
.cond_u64("ID_texte", post_id)
|
||||
.set_order("ID")
|
||||
.exec(db_to_comment)
|
||||
}
|
||||
|
||||
|
||||
/// Turn a database entry into a comment object
|
||||
fn db_to_comment(row: &database::RowResult) -> ResultBoxError<Comment> {
|
||||
Ok(Comment {
|
||||
id: row.get_u64("ID")?,
|
||||
time_sent: row.get_u64("time_insert").unwrap_or(0),
|
||||
user_id: row.get_user_id("ID_personne")?,
|
||||
post_id: row.get_u64("ID_texte")?,
|
||||
content: row.get_str("commentaire")?,
|
||||
image_path: row.get_optional_str("image_commentaire")?,
|
||||
})
|
||||
}
|
@ -12,4 +12,5 @@ pub mod posts_helper;
|
||||
pub mod conversations_helper;
|
||||
pub mod virtual_directory_helper;
|
||||
pub mod movies_helper;
|
||||
pub mod survey_helper;
|
||||
pub mod survey_helper;
|
||||
pub mod comments_helper;
|
@ -177,6 +177,13 @@ pub fn get_access_level(p: &Post, user_id: &Option<UserID>) -> ResultBoxError<Po
|
||||
}
|
||||
}
|
||||
|
||||
/// Check out whether it is possible to create comments on a post or not
|
||||
pub fn allow_comments_on_post(p: &Post) -> ResultBoxError<bool> {
|
||||
Ok(
|
||||
!p.is_on_user_page() ||
|
||||
user_helper::allow_comments(p.user_page_id().unwrap_or(&UserID::invalid()))?)
|
||||
}
|
||||
|
||||
/// Turn a post into a database entry
|
||||
fn db_to_post(res: &database::RowResult) -> ResultBoxError<Post> {
|
||||
let user_id = if res.get_u64("ID_amis")? == 0 {
|
||||
|
@ -111,6 +111,12 @@ pub fn allow_posts_on_his_page(user_id: &UserID) -> ResultBoxError<bool> {
|
||||
Ok(find_user_by_id(user_id)?.allow_posts_from_friends)
|
||||
}
|
||||
|
||||
/// Check out whether a user has blocked comments on his / her page
|
||||
pub fn allow_comments(user_id: &UserID) -> ResultBoxError<bool> {
|
||||
Ok(!find_user_by_id(user_id)?.block_comments_on_his_page)
|
||||
}
|
||||
|
||||
|
||||
/// Check out whether the friends list of a user is public or not
|
||||
pub fn is_user_friends_list_public(user_id: &UserID) -> ResultBoxError<bool> {
|
||||
Ok(find_user_by_id(user_id)?.public_friends_list)
|
||||
|
Reference in New Issue
Block a user