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

Work progress on post deletion

This commit is contained in:
Pierre HUBERT 2020-07-09 10:59:46 +02:00
parent a071d33efd
commit 584ecbf49b

View File

@ -11,9 +11,10 @@ use crate::data::group_member::GroupMembershipLevel;
use crate::data::post::{Post, PostAccessLevel, PostFile, PostKind, PostPageKind, PostVisibilityLevel, PostWebLink};
use crate::data::post::PostKind::{POST_KIND_COUNTDOWN, POST_KIND_IMAGE, POST_KIND_MOVIE, POST_KIND_PDF, POST_KIND_SURVEY, POST_KIND_WEBLINK, POST_KIND_YOUTUBE};
use crate::data::user::UserID;
use crate::helpers::{database, friends_helper, groups_helper, likes_helper, user_helper, comments_helper};
use crate::helpers::{comments_helper, database, friends_helper, groups_helper, likes_helper, user_helper};
use crate::helpers::likes_helper::LikeType;
use crate::utils::date_utils::{mysql_date, time};
use crate::utils::user_data_utils::user_data_path;
impl PostVisibilityLevel {
pub fn to_db(&self) -> u32 {
@ -410,6 +411,20 @@ pub fn delete(p: &Post) -> ResultBoxError {
// Delete all the comments associated to the post
comments_helper::delete_all(p.id)?;
// Delete associated file / resource (if any)
match &p.kind {
// Image / PDF
PostKind::POST_KIND_IMAGE(file) | PostKind::POST_KIND_PDF(file) => {
let path = user_data_path(file.path.as_ref());
if path.exists() {
std::fs::remove_file(path)?;
}
}
_ => { /* Nothing to be done */ }
}
Ok(())
}