diff options
author | Joas Schilling <coding@schilljs.com> | 2017-09-04 13:57:28 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2017-09-04 13:57:28 +0300 |
commit | 23b0b293b385ee8033ed9b4458d8e4ad16388188 (patch) | |
tree | 13af35b0d0063d2e75c1799079b30f69ee365c82 | |
parent | 3cf8526a7b278abb0a74970be26528e5cc4dd378 (diff) |
Resort the list by timestamp after adding new items on the fly
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | js/app.js | 23 |
1 files changed, 14 insertions, 9 deletions
@@ -204,7 +204,7 @@ _.each(data, function(notification) { var n = new self.Notification(notification); self.notifications[n.getId()] = n; - self._addToUI(n, true); + self._addToUI(n); }); // Check if we have any, and notify the UI @@ -227,7 +227,8 @@ this._fetch( function(data) { var inJson = [], - oldNum = self.numNotifications(); + oldNum = self.numNotifications(), + resort = false; _.each(data, function(notification) { var n = new self.Notification(notification); @@ -235,9 +236,18 @@ if (!self.getNotification(n.getId())) { // New notification! self._onNewNotification(n); + resort = true; } }); + if (resort) { + self.$container.find('.notification').sort(function (prev, next) { + return parseInt(next.dataset.timestamp) - parseInt(prev.dataset.timestamp); + }).each(function() { + $(self.$container.find('.notification-wrapper')).append(this); + }); + } + _.each(self.getNotifications(), function(n) { if (inJson.indexOf(n.getId()) === -1) { // Not in JSON, remove from UI @@ -353,7 +363,7 @@ * Adds the notification to the UI * @param {OCA.Notifications.Notification} notification */ - _addToUI: function(notification, append) { + _addToUI: function(notification) { var $element = $(notification.renderElement(this.notificationTemplate)); $element.find('.avatar').each(function() { @@ -381,14 +391,9 @@ var $fullMessage = $(this).parent().find('.notification-full-message'); $(this).addClass('hidden'); $fullMessage.removeClass('hidden'); - }); - if (append) { - this.$container.find('.notification-wrapper').append($element); - } else { - this.$container.find('.notification-wrapper').prepend($element); - } + this.$container.find('.notification-wrapper').append($element); }, /** |