Merge pull request #5189 from mfilser/notifications_are_now_displayed_correctly_again

Notifications are now displayed correctly again
This commit is contained in:
Lauri Ojansivu 2023-11-09 07:03:32 +02:00 committed by GitHub
commit fe6b94e539
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 6 deletions

View file

@ -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))

View file

@ -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;
}
}

View file

@ -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() {