Display existing dismissed notifs in archived

pull/1/head
ClemDee 5 years ago
parent c586d9170a
commit 95959b60c6

@ -80,7 +80,7 @@ define([
onViewedHandlers.push(function (data) { onViewedHandlers.push(function (data) {
var hash = data.hash.replace(/"/g, '\\\"'); var hash = data.hash.replace(/"/g, '\\\"');
var $notif = $('.cp-notification[data-hash="'+hash+'"]'); var $notif = $('.cp-notification[data-hash="'+hash+'"]:not(.cp-app-notification-archived)');
if ($notif.length) { if ($notif.length) {
$notif.remove(); $notif.remove();
} }

@ -85,14 +85,15 @@ define([
var addArchivedNotification = function (data) { var addArchivedNotification = function (data) {
var isDataUnread = unreadData.findIndex(function (ud) { var isDataUnread = unreadData.findIndex(function (ud) {
return ud.content.hash === data.content.hash; return ud.content.hash === data.content.hash;
}) === -1; }) !== -1;
if (data.content.archived && isDataUnread) { if (data.content.archived) {
notifsData.push(data); notifsData.push(data);
var el = common.mailbox.createElement(data); var el = common.mailbox.createElement(data);
var time = new Date(data.content.time); var time = new Date(data.content.time);
$(el).find(".cp-notification-content").append(h("span.notification-time", time.toLocaleDateString() + " - " + time.toLocaleTimeString())); $(el).find(".cp-notification-content").append(h("span.notification-time", time.toLocaleDateString() + " - " + time.toLocaleTimeString()));
$(el).addClass("cp-app-notification-archived"); $(el).addClass("cp-app-notification-archived");
$(notifsList).prepend(el); $(el).toggle(!isDataUnread);
$(notifsList).append(el);
} }
}; };
@ -105,11 +106,12 @@ define([
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', 5, lastKnownHash, function (err, messages) { common.mailbox.getNotificationsHistory('notifications', 5, lastKnownHash, function (err, messages) {
console.log(messages); // display archived notifs from most recent to oldest
messages.forEach(function (data) { for (var i = messages.length - 1 ; i >= 0 ; i--) {
var data = messages[i];
data.content.archived = true; data.content.archived = true;
addArchivedNotification(data); addArchivedNotification(data);
}); }
lastKnownHash = messages[0].content.hash; lastKnownHash = messages[0].content.hash;
}); });
}); });
@ -119,10 +121,11 @@ define([
common.mailbox.subscribe(["notifications"], { common.mailbox.subscribe(["notifications"], {
onMessage: function (data, el) { onMessage: function (data, el) {
console.log(data);
addNotification(data, el); addNotification(data, el);
}, },
onViewed: function () {} onViewed: function (data) {
$('.cp-app-notification-archived[data-hash="' + data.hash + '"]').show();
}
}); });
$(dismissAll).click(function () { $(dismissAll).click(function () {

Loading…
Cancel
Save