mirror of
				https://gitlab.com/comunic/comunicapiv3
				synced 2025-10-31 15:44:05 +00:00 
			
		
		
		
	Can change the visibility level of a post
This commit is contained in:
		| @@ -114,7 +114,7 @@ pub fn create_post(r: &mut HttpRequestHandler) -> RequestResult { | ||||
|         time_create: time(), | ||||
|         target_page, | ||||
|         content: Some(r.post_string_opt("content", 0, false)?), | ||||
|         visibility: PostVisibilityLevel::VISIBILITY_PUBLIC, | ||||
|         visibility: PostVisibilityLevel::VISIBILITY_PUBLIC, // TODO : fix | ||||
|         kind: PostKind::POST_KIND_TEXT, | ||||
|     }; | ||||
|  | ||||
| @@ -235,4 +235,16 @@ pub fn create_post(r: &mut HttpRequestHandler) -> RequestResult { | ||||
|  | ||||
|     // TODO : create a notification | ||||
|     r.set_response(ResCreatePost::new(post_id)) | ||||
| } | ||||
|  | ||||
| /// Change the visibility level of a post | ||||
| pub fn set_visibility_level(r: &mut HttpRequestHandler) -> RequestResult { | ||||
|     let post = r.post_post_with_access("postID", PostAccessLevel::FULL_ACCESS)?; | ||||
|     let new_visibility = PostVisibilityLevel::from_api(&r.post_string("new_level")?); | ||||
|  | ||||
|     posts_helper::set_level(post.id, new_visibility)?; | ||||
|  | ||||
|     // TODO : Depending on new level, delete (or not) notifications about the post | ||||
|  | ||||
|     r.success("Visibility level updated") | ||||
| } | ||||
| @@ -208,6 +208,8 @@ pub fn get_routes() -> Vec<Route> { | ||||
|  | ||||
|         Route::post("/posts/create", Box::new(posts_controller::create_post)), | ||||
|  | ||||
|         Route::post("/posts/set_visibility_level", Box::new(posts_controller::set_visibility_level)), | ||||
|  | ||||
|  | ||||
|         // Movies controller | ||||
|         Route::post("/movies/get_list", Box::new(movies_controller::get_list)), | ||||
|   | ||||
| @@ -30,6 +30,16 @@ impl PostVisibilityLevel { | ||||
|             PostVisibilityLevel::VISIBILITY_GROUP_MEMBERS => "members", | ||||
|         }.to_string() | ||||
|     } | ||||
|  | ||||
|     pub fn from_api(level: &str) -> PostVisibilityLevel { | ||||
|         match level { | ||||
|             "private" => PostVisibilityLevel::VISIBILITY_USER, | ||||
|             "friends" => PostVisibilityLevel::VISIBILITY_FRIENDS, | ||||
|             "members" => PostVisibilityLevel::VISIBILITY_GROUP_MEMBERS, | ||||
|             "public" => PostVisibilityLevel::VISIBILITY_PUBLIC, | ||||
|             _ => PostVisibilityLevel::VISIBILITY_PUBLIC, | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| /// Post access level (for a given user) | ||||
|   | ||||
| @@ -383,6 +383,14 @@ pub fn allow_comments_on_post(p: &Post) -> ResultBoxError<bool> { | ||||
|             user_helper::allow_comments(p.user_page_id().unwrap_or(&UserID::invalid()))?) | ||||
| } | ||||
|  | ||||
| /// Set a new visibility level to a post | ||||
| pub fn set_level(post_id: u64, level: PostVisibilityLevel) -> ResultBoxError { | ||||
|     database::UpdateInfo::new(POSTS_TABLE) | ||||
|         .cond_u64("ID", post_id) | ||||
|         .set_u32("niveau_visibilite", level.to_db()) | ||||
|         .exec() | ||||
| } | ||||
|  | ||||
| /// 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 { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user