mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 13:29:21 +00:00
Automatically clean old notifications
This commit is contained in:
parent
664824ff48
commit
7876c37330
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
use crate::constants::CLEAN_UP_INTERVAL;
|
use crate::constants::CLEAN_UP_INTERVAL;
|
||||||
use crate::data::error::Res;
|
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
|
/// Start the maintenance thread
|
||||||
pub fn start() -> Res {
|
pub fn start() -> Res {
|
||||||
@ -44,7 +44,8 @@ fn do_clean() -> Res {
|
|||||||
// Clean old likes
|
// Clean old likes
|
||||||
likes_helper::clean_old_user_likes(&user)?;
|
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 std::collections::HashMap;
|
||||||
|
|
||||||
use crate::constants::database_tables_names::NOTIFICATIONS_TABLE;
|
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::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::{PostID, PostPageKind, PostVisibilityLevel};
|
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::{database, events_helper, groups_helper, posts_helper};
|
||||||
use crate::helpers::events_helper::Event;
|
use crate::helpers::events_helper::Event;
|
||||||
use crate::helpers::friends_helper::GetFriendsQuery;
|
use crate::helpers::friends_helper::GetFriendsQuery;
|
||||||
use crate::utils::date_utils;
|
use crate::utils::date_utils;
|
||||||
|
use crate::utils::date_utils::time;
|
||||||
|
|
||||||
/// Create post notification
|
/// Create post notification
|
||||||
pub fn create_post_notification(from_user: &UserID, post_id: u64, action: NotifEventType) -> ResultBoxError {
|
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(())
|
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
|
/// Delete all the notifications related with a group
|
||||||
pub fn delete_all_related_with_group(group_id: &GroupID) -> ResultBoxError {
|
pub fn delete_all_related_with_group(group_id: &GroupID) -> ResultBoxError {
|
||||||
delete(&PartialNotification::new()
|
delete(&PartialNotification::new()
|
||||||
|
Loading…
Reference in New Issue
Block a user