diff --git a/client/components/notifications/notificationsDrawer.jade b/client/components/notifications/notificationsDrawer.jade index fee6aef67..2fd2bb229 100644 --- a/client/components/notifications/notificationsDrawer.jade +++ b/client/components/notifications/notificationsDrawer.jade @@ -11,7 +11,7 @@ template(name='notificationsDrawer') a.fa.fa-times-thin.close ul.notifications each transformedProfile.notifications - +notification(activityData=activity index=dbIndex read=read) + +notification(activityData=activityObj index=dbIndex read=read) if($gt unreadNotifications 0) a.all-read {{_ 'mark-all-as-read'}} if ($and ($.Session.get 'showReadNotifications') ($gt readNotifications 0)) diff --git a/imports/reactiveCache.js b/imports/reactiveCache.js index bac446a22..0ac95c92f 100644 --- a/imports/reactiveCache.js +++ b/imports/reactiveCache.js @@ -1410,6 +1410,28 @@ ReactiveMiniMongoIndex = { } } return ret; + }, + getActivityWithId(activityId, addSelect = {}, options) { + let ret = [] + if (activityId) { + const select = {addSelect, options} + if (!this.__activityWithId) { + this.__activityWithId = new DataCache(_select => { + const __select = EJSON.parse(_select); + const _activities = ReactiveCache.getActivities( + { _id: { $exists: true }, + ...__select.addSelect, + }, __select.options); + const _ret = _.indexBy(_activities, '_id') + return _ret; + }); + } + ret = this.__activityWithId.get(EJSON.stringify(select)); + if (ret) { + ret = ret[activityId]; + } + } + return ret; } } diff --git a/models/users.js b/models/users.js index 9afd266c0..d50c402df 100644 --- a/models/users.js +++ b/models/users.js @@ -1,4 +1,4 @@ -import { ReactiveCache } from '/imports/reactiveCache'; +import { ReactiveCache, ReactiveMiniMongoIndex } from '/imports/reactiveCache'; import { SyncedCron } from 'meteor/percolate:synced-cron'; import { TAPi18n } from '/imports/i18n'; import ImpersonatedUsers from './impersonatedUsers'; @@ -852,11 +852,13 @@ Users.helpers({ const notification = notifications[index]; // this preserves their db sort order for editing notification.dbIndex = index; - notification.activity = ReactiveCache.getActivity(notification.activity); + if (!notification.activityObj && typeof(notification.activity) === 'string') { + notification.activityObj = ReactiveMiniMongoIndex.getActivityWithId(notification.activity); + } } - // this sorts them newest to oldest to match Trello's behavior - notifications.reverse(); - return notifications; + // newest first. don't use reverse() because it changes the array inplace, so sometimes the array is reversed twice and oldest items at top again + const ret = notifications.toReversed(); + return ret; }, hasShowDesktopDragHandles() {