Prevent to load more archived notifications when reached end

pull/1/head
ClemDee 5 years ago
parent fc9414b094
commit 6961509f76

@ -190,7 +190,8 @@ define([
if (data.txid !== txid) { return; } if (data.txid !== txid) { return; }
if (data.complete) { if (data.complete) {
onHistory = function () {}; onHistory = function () {};
cb(null, messages); var end = messages.length < count;
cb(null, messages, end);
historyState = false; historyState = false;
return; return;
} }
@ -207,12 +208,13 @@ define([
}; };
}; };
mailbox.getNotificationsHistory = function (type, count, lastKnownHash, cb) { 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) { messages.forEach(function (data) {
data.content.archived = true; data.content.archived = true;
Notifications.add(Common, data); Notifications.add(Common, data);
}); });
cb(err, messages); cb(err, messages, end);
}); });
}; };

@ -108,14 +108,20 @@ define([
$(dismissAll).remove(); $(dismissAll).remove();
loadmore = h("div.cp-app-notification-loadmore.cp-clickable", Messages.loadMore || "Load more ..."); loadmore = h("div.cp-app-notification-loadmore.cp-clickable", Messages.loadMore || "Load more ...");
$(loadmore).click(function () { $(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 // display archived notifs from most recent to oldest
for (var i = messages.length - 1 ; i >= 0 ; i--) { for (var i = messages.length - 1 ; i >= 0 ; i--) {
var data = messages[i]; var data = messages[i];
data.content.archived = true; data.content.archived = true;
addArchivedNotification(data); addArchivedNotification(data);
} }
if (end) {
$(loadmore).hide();
}
else {
lastKnownHash = messages[0].content.hash; lastKnownHash = messages[0].content.hash;
}
}); });
}); });
notifsList.before(loadmore); notifsList.before(loadmore);

Loading…
Cancel
Save