Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/notifications.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2017-09-04 13:57:28 +0300
committerJoas Schilling <coding@schilljs.com>2017-09-04 13:57:28 +0300
commit23b0b293b385ee8033ed9b4458d8e4ad16388188 (patch)
tree13af35b0d0063d2e75c1799079b30f69ee365c82
parent3cf8526a7b278abb0a74970be26528e5cc4dd378 (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.js23
1 files changed, 14 insertions, 9 deletions
diff --git a/js/app.js b/js/app.js
index 3c0811a..7d16292 100644
--- a/js/app.js
+++ b/js/app.js
@@ -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);
},
/**