mirror of
				https://gitlab.com/comunic/comunicapiv3
				synced 2025-10-30 23:24:42 +00:00 
			
		
		
		
	Automatically clean old notifications
This commit is contained in:
		| @@ -6,7 +6,7 @@ | ||||
|  | ||||
| use crate::constants::CLEAN_UP_INTERVAL; | ||||
| use crate::data::error::Res; | ||||
| use crate::helpers::{account_helper, user_helper, likes_helper}; | ||||
| use crate::helpers::{account_helper, likes_helper, notifications_helper, user_helper}; | ||||
|  | ||||
| /// Start the maintenance thread | ||||
| pub fn start() -> Res { | ||||
| @@ -44,7 +44,8 @@ fn do_clean() -> Res { | ||||
|         // Clean old likes | ||||
|         likes_helper::clean_old_user_likes(&user)?; | ||||
|  | ||||
|  | ||||
|         // Clean old notifications | ||||
|         notifications_helper::clean_old_user_notifications(&user)?; | ||||
|     } | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -5,15 +5,16 @@ | ||||
| use std::collections::HashMap; | ||||
|  | ||||
| use crate::constants::database_tables_names::NOTIFICATIONS_TABLE; | ||||
| use crate::data::error::{ExecError, ResultBoxError}; | ||||
| use crate::data::error::{ExecError, Res, ResultBoxError}; | ||||
| use crate::data::group_id::GroupID; | ||||
| use crate::data::notification::{NotifElemType, NotifEventType, NotifEventVisibility, Notification, PartialNotification}; | ||||
| use crate::data::post::{PostID, PostPageKind, PostVisibilityLevel}; | ||||
| use crate::data::user::UserID; | ||||
| use crate::data::user::{User, UserID}; | ||||
| use crate::helpers::{database, events_helper, groups_helper, posts_helper}; | ||||
| use crate::helpers::events_helper::Event; | ||||
| use crate::helpers::friends_helper::GetFriendsQuery; | ||||
| use crate::utils::date_utils; | ||||
| use crate::utils::date_utils::time; | ||||
|  | ||||
| /// Create post notification | ||||
| pub fn create_post_notification(from_user: &UserID, post_id: u64, action: NotifEventType) -> ResultBoxError { | ||||
| @@ -272,6 +273,19 @@ pub fn delete_all_related_with_user(user_id: &UserID) -> ResultBoxError { | ||||
|     Ok(()) | ||||
| } | ||||
|  | ||||
| /// Delete all the old notifications of a user | ||||
| pub fn clean_old_user_notifications(user: &User) -> Res { | ||||
|     if user.delete_notifications_after < 1 { | ||||
|         return Ok(()); | ||||
|     } | ||||
|  | ||||
|     database::DeleteQuery::new(NOTIFICATIONS_TABLE) | ||||
|         .cond_user_id("dest_user_id", &user.id) | ||||
|         .set_custom_where("time_create < ?") | ||||
|         .add_custom_where_arg_u64(time() - user.delete_notifications_after) | ||||
|         .exec() | ||||
| } | ||||
|  | ||||
| /// Delete all the notifications related with a group | ||||
| pub fn delete_all_related_with_group(group_id: &GroupID) -> ResultBoxError { | ||||
|     delete(&PartialNotification::new() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user