From 6961509f760babd800832ccbe7da93c2ded04010 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Tue, 2 Jul 2019 14:35:34 +0200 Subject: [PATCH] Prevent to load more archived notifications when reached end --- www/common/sframe-common-mailbox.js | 8 +++++--- www/notifications/inner.js | 10 ++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/www/common/sframe-common-mailbox.js b/www/common/sframe-common-mailbox.js index 695ea3b6a..cf2ea4516 100644 --- a/www/common/sframe-common-mailbox.js +++ b/www/common/sframe-common-mailbox.js @@ -190,7 +190,8 @@ define([ if (data.txid !== txid) { return; } if (data.complete) { onHistory = function () {}; - cb(null, messages); + var end = messages.length < count; + cb(null, messages, end); historyState = false; return; } @@ -207,12 +208,13 @@ define([ }; }; mailbox.getNotificationsHistory = function (type, count, lastKnownHash, cb) { - mailbox.getMoreHistory(type, count, lastKnownHash, function (err, messages) { + mailbox.getMoreHistory(type, count, lastKnownHash, function (err, messages, end) { + if (!Array.isArray(messages)) { return void cb(err); } messages.forEach(function (data) { data.content.archived = true; Notifications.add(Common, data); }); - cb(err, messages); + cb(err, messages, end); }); }; diff --git a/www/notifications/inner.js b/www/notifications/inner.js index 3d1ca802e..5e2dcd465 100644 --- a/www/notifications/inner.js +++ b/www/notifications/inner.js @@ -108,14 +108,20 @@ define([ $(dismissAll).remove(); loadmore = h("div.cp-app-notification-loadmore.cp-clickable", Messages.loadMore || "Load more ..."); $(loadmore).click(function () { - common.mailbox.getNotificationsHistory('notifications', 20, lastKnownHash, function (err, messages) { + common.mailbox.getNotificationsHistory('notifications', 10, lastKnownHash, function (err, messages, end) { + if (!Array.isArray(messages)) { return; } // display archived notifs from most recent to oldest for (var i = messages.length - 1 ; i >= 0 ; i--) { var data = messages[i]; data.content.archived = true; addArchivedNotification(data); } - lastKnownHash = messages[0].content.hash; + if (end) { + $(loadmore).hide(); + } + else { + lastKnownHash = messages[0].content.hash; + } }); }); notifsList.before(loadmore);