2023-01-15 01:11:16 +01:00
|
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
2020-03-27 11:35:03 -06:00
|
|
|
import { toggleNotificationsDrawer } from './notifications.js';
|
|
|
|
|
|
|
|
|
|
Template.notificationsDrawer.onCreated(function() {
|
|
|
|
|
Meteor.subscribe('notificationActivities');
|
|
|
|
|
Meteor.subscribe('notificationCards');
|
|
|
|
|
Meteor.subscribe('notificationUsers');
|
|
|
|
|
Meteor.subscribe('notificationsAttachments');
|
|
|
|
|
Meteor.subscribe('notificationChecklistItems');
|
|
|
|
|
Meteor.subscribe('notificationChecklists');
|
|
|
|
|
Meteor.subscribe('notificationComments');
|
|
|
|
|
Meteor.subscribe('notificationLists');
|
|
|
|
|
Meteor.subscribe('notificationSwimlanes');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Template.notificationsDrawer.helpers({
|
Fix mentions and notifications drawer.
Thanks to xet7 !
Fixes #6062,
fixes #6003,
fixes #5996,
fixes #5720,
fixes #5911,
fixes #5792,
fixes #5163,
fixes #4431,
fixes #4126,
fixes #3363,
fixes #3150
2026-01-14 21:02:10 +02:00
|
|
|
notifications() {
|
|
|
|
|
const user = ReactiveCache.getCurrentUser();
|
|
|
|
|
return user ? user.notifications() : [];
|
|
|
|
|
},
|
2020-03-27 11:35:03 -06:00
|
|
|
transformedProfile() {
|
2023-01-15 01:11:16 +01:00
|
|
|
return ReactiveCache.getCurrentUser();
|
2020-03-27 11:35:03 -06:00
|
|
|
},
|
2020-04-08 13:14:29 -06:00
|
|
|
readNotifications() {
|
Fix mentions and notifications drawer.
Thanks to xet7 !
Fixes #6062,
fixes #6003,
fixes #5996,
fixes #5720,
fixes #5911,
fixes #5792,
fixes #5163,
fixes #4431,
fixes #4126,
fixes #3363,
fixes #3150
2026-01-14 21:02:10 +02:00
|
|
|
const user = ReactiveCache.getCurrentUser();
|
|
|
|
|
const list = user ? user.notifications() : [];
|
|
|
|
|
const readNotifications = _.filter(list, v => !!v.read);
|
2020-04-08 13:14:29 -06:00
|
|
|
return readNotifications.length;
|
|
|
|
|
},
|
2020-03-27 11:35:03 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Template.notificationsDrawer.events({
|
Fix mentions and notifications drawer.
Thanks to xet7 !
Fixes #6062,
fixes #6003,
fixes #5996,
fixes #5720,
fixes #5911,
fixes #5792,
fixes #5163,
fixes #4431,
fixes #4126,
fixes #3363,
fixes #3150
2026-01-14 21:02:10 +02:00
|
|
|
'click .notification-menu-toggle'(event) {
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
Session.set('showNotificationMenu', !Session.get('showNotificationMenu'));
|
|
|
|
|
},
|
|
|
|
|
'click .notification-menu .menu-item'(event) {
|
|
|
|
|
const target = event.currentTarget;
|
|
|
|
|
|
|
|
|
|
if (target.classList.contains('mark-all-read')) {
|
|
|
|
|
const notifications = ReactiveCache.getCurrentUser().profile.notifications;
|
|
|
|
|
for (const index in notifications) {
|
|
|
|
|
if (notifications.hasOwnProperty(index) && !notifications[index].read) {
|
|
|
|
|
const update = {};
|
|
|
|
|
update[`profile.notifications.${index}.read`] = Date.now();
|
|
|
|
|
Users.update(Meteor.userId(), { $set: update });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Session.set('showNotificationMenu', false);
|
|
|
|
|
} else if (target.classList.contains('mark-all-unread')) {
|
|
|
|
|
const notifications = ReactiveCache.getCurrentUser().profile.notifications;
|
|
|
|
|
for (const index in notifications) {
|
|
|
|
|
if (notifications.hasOwnProperty(index) && notifications[index].read) {
|
|
|
|
|
const update = {};
|
|
|
|
|
update[`profile.notifications.${index}.read`] = null;
|
|
|
|
|
Users.update(Meteor.userId(), { $set: update });
|
|
|
|
|
}
|
2020-03-27 11:35:03 -06:00
|
|
|
}
|
Fix mentions and notifications drawer.
Thanks to xet7 !
Fixes #6062,
fixes #6003,
fixes #5996,
fixes #5720,
fixes #5911,
fixes #5792,
fixes #5163,
fixes #4431,
fixes #4126,
fixes #3363,
fixes #3150
2026-01-14 21:02:10 +02:00
|
|
|
Session.set('showNotificationMenu', false);
|
|
|
|
|
} else if (target.classList.contains('delete-read')) {
|
|
|
|
|
const user = ReactiveCache.getCurrentUser();
|
|
|
|
|
for (const notification of user.profile.notifications) {
|
|
|
|
|
if (notification.read) {
|
|
|
|
|
user.removeNotification(notification.activity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Session.set('showNotificationMenu', false);
|
|
|
|
|
} else if (target.classList.contains('delete-all')) {
|
|
|
|
|
if (confirm(TAPi18n.__('delete-all-notifications-confirm'))) {
|
|
|
|
|
const user = ReactiveCache.getCurrentUser();
|
|
|
|
|
const notificationsCopy = [...user.profile.notifications];
|
|
|
|
|
for (const notification of notificationsCopy) {
|
|
|
|
|
user.removeNotification(notification.activity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Session.set('showNotificationMenu', false);
|
|
|
|
|
} else if (target.classList.contains('selected')) {
|
|
|
|
|
// Already selected, do nothing
|
|
|
|
|
Session.set('showNotificationMenu', false);
|
|
|
|
|
} else {
|
|
|
|
|
// Toggle view
|
|
|
|
|
Session.set('showReadNotifications', !Session.get('showReadNotifications'));
|
|
|
|
|
Session.set('showNotificationMenu', false);
|
2020-03-27 11:35:03 -06:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
'click .close'() {
|
Fix mentions and notifications drawer.
Thanks to xet7 !
Fixes #6062,
fixes #6003,
fixes #5996,
fixes #5720,
fixes #5911,
fixes #5792,
fixes #5163,
fixes #4431,
fixes #4126,
fixes #3363,
fixes #3150
2026-01-14 21:02:10 +02:00
|
|
|
Session.set('showNotificationMenu', false);
|
2020-03-27 11:35:03 -06:00
|
|
|
toggleNotificationsDrawer();
|
|
|
|
|
},
|
Fix mentions and notifications drawer.
Thanks to xet7 !
Fixes #6062,
fixes #6003,
fixes #5996,
fixes #5720,
fixes #5911,
fixes #5792,
fixes #5163,
fixes #4431,
fixes #4126,
fixes #3363,
fixes #3150
2026-01-14 21:02:10 +02:00
|
|
|
'click'(event) {
|
|
|
|
|
// Close menu when clicking outside
|
|
|
|
|
if (!event.target.closest('.notification-menu') && !event.target.closest('.notification-menu-toggle')) {
|
|
|
|
|
Session.set('showNotificationMenu', false);
|
2020-04-08 13:14:29 -06:00
|
|
|
}
|
|
|
|
|
},
|
2020-03-27 11:35:03 -06:00
|
|
|
});
|