mirror of
				https://gitlab.com/comunic/comunicapiv3
				synced 2025-11-04 01:24:04 +00:00 
			
		
		
		
	Can delete all the notifications related with a post
This commit is contained in:
		@@ -119,8 +119,10 @@ impl PostKind {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub type PostID = u64;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub struct Post {
 | 
					pub struct Post {
 | 
				
			||||||
    pub id: u64,
 | 
					    pub id: PostID,
 | 
				
			||||||
    pub user_id: UserID,
 | 
					    pub user_id: UserID,
 | 
				
			||||||
    pub time_create: u64,
 | 
					    pub time_create: u64,
 | 
				
			||||||
    pub target_page: PostPageKind,
 | 
					    pub target_page: PostPageKind,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,7 +8,7 @@ use crate::constants::database_tables_names::NOTIFICATIONS_TABLE;
 | 
				
			|||||||
use crate::data::error::ResultBoxError;
 | 
					use crate::data::error::ResultBoxError;
 | 
				
			||||||
use crate::data::group_id::GroupID;
 | 
					use crate::data::group_id::GroupID;
 | 
				
			||||||
use crate::data::notification::{NotifElemType, NotifEventType, NotifEventVisibility, Notification, PartialNotification};
 | 
					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::data::user::UserID;
 | 
				
			||||||
use crate::helpers::{database, groups_helper, posts_helper};
 | 
					use crate::helpers::{database, groups_helper, posts_helper};
 | 
				
			||||||
use crate::helpers::friends_helper::GetFriendsQuery;
 | 
					use crate::helpers::friends_helper::GetFriendsQuery;
 | 
				
			||||||
@@ -285,6 +285,15 @@ pub fn delete_all_related_to_group_membership_notifications(user_id: &UserID, gr
 | 
				
			|||||||
    Ok(())
 | 
					    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
 | 
					/// Check out whether a similar notification exists for given specifications
 | 
				
			||||||
pub fn similar_exists(n: &PartialNotification) -> ResultBoxError<bool> {
 | 
					pub fn similar_exists(n: &PartialNotification) -> ResultBoxError<bool> {
 | 
				
			||||||
    database::QueryInfo::new(NOTIFICATIONS_TABLE)
 | 
					    database::QueryInfo::new(NOTIFICATIONS_TABLE)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,7 +12,7 @@ use crate::data::movie::Movie;
 | 
				
			|||||||
use crate::data::post::{Post, PostAccessLevel, PostFile, PostKind, PostPageKind, PostVisibilityLevel, PostWebLink};
 | 
					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::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::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::helpers::likes_helper::LikeType;
 | 
				
			||||||
use crate::utils::date_utils::{mysql_date, time};
 | 
					use crate::utils::date_utils::{mysql_date, time};
 | 
				
			||||||
use crate::utils::user_data_utils::user_data_path;
 | 
					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
 | 
					/// Delete a post
 | 
				
			||||||
pub fn delete(p: &Post) -> ResultBoxError {
 | 
					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
 | 
					    // Delete all the likes associated with the post
 | 
				
			||||||
    likes_helper::delete_all(p.id, LikeType::POST)?;
 | 
					    likes_helper::delete_all(p.id, LikeType::POST)?;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user