diff options
author | Lauri Ojansivu <x@xet7.org> | 2020-04-02 01:09:35 +0300 |
---|---|---|
committer | Lauri Ojansivu <x@xet7.org> | 2020-04-02 01:09:35 +0300 |
commit | e34f240c35b6eaec3e3ac2830129ddf914de5feb (patch) | |
tree | 9185e821c0e24cd1c9ae55da416d30b974035c31 /models/users.js | |
parent | 56667112d7fd146a9847794207e9a2224b1115d7 (diff) | |
parent | 8ea86ae0b9e4351b935fde45c77f37d09778739d (diff) | |
download | wekan-e34f240c35b6eaec3e3ac2830129ddf914de5feb.tar.gz wekan-e34f240c35b6eaec3e3ac2830129ddf914de5feb.tar.bz2 wekan-e34f240c35b6eaec3e3ac2830129ddf914de5feb.zip |
Merge branch 'jtbairdsr-master'
Diffstat (limited to 'models/users.js')
-rw-r--r-- | models/users.js | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/models/users.js b/models/users.js index d56f14ff..20581e65 100644 --- a/models/users.js +++ b/models/users.js @@ -165,7 +165,20 @@ Users.attachSchema( /** * enabled notifications for the user */ - type: [String], + type: [Object], + optional: true, + }, + 'profile.notifications.$.activity': { + /** + * The id of the activity this notification references + */ + type: String, + }, + 'profile.notifications.$.read': { + /** + * the date on which this notification was read + */ + type: Date, optional: true, }, 'profile.showCardsCountAt': { @@ -429,6 +442,20 @@ Users.helpers({ return _.contains(notifications, activityId); }, + notifications() { + const { notifications = [] } = this.profile || {}; + for (const index in notifications) { + if (!notifications.hasOwnProperty(index)) continue; + const notification = notifications[index]; + // this preserves their db sort order for editing + notification.dbIndex = index; + notification.activity = Activities.findOne(notification.activity); + } + // this sorts them newest to oldest to match Trello's behavior + notifications.reverse(); + return notifications; + }, + hasShowDesktopDragHandles() { const profile = this.profile || {}; return profile.showDesktopDragHandles || false; @@ -573,7 +600,7 @@ Users.mutations({ addNotification(activityId) { return { $addToSet: { - 'profile.notifications': activityId, + 'profile.notifications': { activity: activityId }, }, }; }, @@ -581,7 +608,7 @@ Users.mutations({ removeNotification(activityId) { return { $pull: { - 'profile.notifications': activityId, + 'profile.notifications': { activity: activityId }, }, }; }, |