summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorJonathan Baird <jonathan@smithbox.com>2020-04-08 11:54:00 -0600
committerJonathan Baird <jonathan@smithbox.com>2020-04-08 11:54:00 -0600
commit1e20e2601fa9c2951d811861ff97f3f555aac6af (patch)
treef91bd28d690643fb5cc2f25a84678b1a93bca015 /models
parent4d066b1f3095326c6ef085ccc405bb1e19f0dd03 (diff)
downloadwekan-1e20e2601fa9c2951d811861ff97f3f555aac6af.tar.gz
wekan-1e20e2601fa9c2951d811861ff97f3f555aac6af.tar.bz2
wekan-1e20e2601fa9c2951d811861ff97f3f555aac6af.zip
add a scheduled notification cleanup job
Diffstat (limited to 'models')
-rw-r--r--models/users.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/models/users.js b/models/users.js
index 20581e65..9b2a5465 100644
--- a/models/users.js
+++ b/models/users.js
@@ -1,3 +1,5 @@
+import { SyncedCron } from 'meteor/percolate:synced-cron';
+
// Sandstorm context is detected using the METEOR_SETTINGS environment variable
// in the package definition.
const isSandstorm =
@@ -926,6 +928,37 @@ if (Meteor.isServer) {
});
}
+const addCronJob = _.debounce(
+ Meteor.bindEnvironment(function notificationCleanupDebounced() {
+ // passed in the removeAge has to be a number standing for the number of days after a notification is read before we remove it
+ const envRemoveAge = process.env.NOTIFICATION_REMOVAL_AGE;
+ // default notifications will be removed 2 days after they are read
+ const defaultRemoveAge = 2;
+ const removeAge = parseInt(envRemoveAge, 10) || defaultRemoveAge;
+
+ SyncedCron.add({
+ name: 'notification_cleanup',
+ schedule: parser => parser.text('every 1 days'),
+ job: () => {
+ for (const user of Users.find()) {
+ for (const notification of user.profile.notifications) {
+ if (notification.read) {
+ const removeDate = new Date(notification.read);
+ removeDate.setDate(removeDate.getDate() + removeAge);
+ if (removeDate <= new Date()) {
+ user.removeNotification(notification.activity);
+ }
+ }
+ }
+ }
+ },
+ });
+
+ SyncedCron.start();
+ }),
+ 500,
+);
+
if (Meteor.isServer) {
// Let mongoDB ensure username unicity
Meteor.startup(() => {
@@ -939,6 +972,9 @@ if (Meteor.isServer) {
},
{ unique: true },
);
+ Meteor.defer(() => {
+ addCronJob();
+ });
});
// OLD WAY THIS CODE DID WORK: When user is last admin of board,