diff --git a/src/data/post.rs b/src/data/post.rs index 77339ab..e906de3 100644 --- a/src/data/post.rs +++ b/src/data/post.rs @@ -119,8 +119,10 @@ impl PostKind { } } +pub type PostID = u64; + pub struct Post { - pub id: u64, + pub id: PostID, pub user_id: UserID, pub time_create: u64, pub target_page: PostPageKind, diff --git a/src/helpers/notifications_helper.rs b/src/helpers/notifications_helper.rs index 668e86e..0ab5378 100644 --- a/src/helpers/notifications_helper.rs +++ b/src/helpers/notifications_helper.rs @@ -8,7 +8,7 @@ use crate::constants::database_tables_names::NOTIFICATIONS_TABLE; use crate::data::error::ResultBoxError; use crate::data::group_id::GroupID; use crate::data::notification::{NotifElemType, NotifEventType, NotifEventVisibility, Notification, PartialNotification}; -use crate::data::post::{PostPageKind, PostVisibilityLevel}; +use crate::data::post::{PostID, PostPageKind, PostVisibilityLevel}; use crate::data::user::UserID; use crate::helpers::{database, groups_helper, posts_helper}; use crate::helpers::friends_helper::GetFriendsQuery; @@ -285,6 +285,15 @@ pub fn delete_all_related_to_group_membership_notifications(user_id: &UserID, gr Ok(()) } +/// Delete all the notifications related with a post +pub fn delete_all_related_with_post(post_id: PostID) -> ResultBoxError { + let n = PartialNotification::new() + .set_on_elem_type(NotifElemType::POST) + .set_on_elem_id(post_id); + + delete(&n) +} + /// Check out whether a similar notification exists for given specifications pub fn similar_exists(n: &PartialNotification) -> ResultBoxError { database::QueryInfo::new(NOTIFICATIONS_TABLE) diff --git a/src/helpers/posts_helper.rs b/src/helpers/posts_helper.rs index 9557fc2..64c93cb 100644 --- a/src/helpers/posts_helper.rs +++ b/src/helpers/posts_helper.rs @@ -12,7 +12,7 @@ use crate::data::movie::Movie; 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::{comments_helper, database, friends_helper, groups_helper, likes_helper, survey_helper, user_helper}; +use crate::helpers::{comments_helper, database, friends_helper, groups_helper, likes_helper, notifications_helper, survey_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; @@ -420,7 +420,8 @@ pub fn set_content(post_id: u64, new_content: &str) -> ResultBoxError { /// Delete a post pub fn delete(p: &Post) -> ResultBoxError { - // TODO : delete all the notifications related with the post + // Delete all the notifications related with the post + notifications_helper::delete_all_related_with_post(p.id)?; // Delete all the likes associated with the post likes_helper::delete_all(p.id, LikeType::POST)?;