Prechádzať zdrojové kódy

Merge pull request #5189 from mfilser/notifications_are_now_displayed_correctly_again

Notifications are now displayed correctly again
Lauri Ojansivu 1 rok pred
rodič
commit
fe6b94e539

+ 1 - 1
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))

+ 22 - 0
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;
   }
 }
 

+ 7 - 5
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() {