From 604358d5dc0179679e6d727c4eba87db39a418cc Mon Sep 17 00:00:00 2001 From: ClemDee Date: Mon, 1 Jul 2019 11:12:16 +0200 Subject: [PATCH] Do not create notification elements from two different places --- www/common/sframe-common-mailbox.js | 2 +- www/notifications/app-notifications.less | 4 +-- www/notifications/inner.js | 39 ++++++------------------ 3 files changed, 12 insertions(+), 33 deletions(-) diff --git a/www/common/sframe-common-mailbox.js b/www/common/sframe-common-mailbox.js index 975e88443..24d495ac9 100644 --- a/www/common/sframe-common-mailbox.js +++ b/www/common/sframe-common-mailbox.js @@ -47,7 +47,7 @@ define([ var formatData = function (data) { return JSON.stringify(data.content.msg.content); }; - var createElement = function (data) { + var createElement = mailbox.createElement = function (data) { var notif; notif = h('div.cp-notification', { 'data-hash': data.content.hash diff --git a/www/notifications/app-notifications.less b/www/notifications/app-notifications.less index c7de33087..372816df7 100644 --- a/www/notifications/app-notifications.less +++ b/www/notifications/app-notifications.less @@ -32,7 +32,7 @@ flex-direction: row; justify-content: flex-start; align-items: center; - border-radius: 5px 5px 0 0; +// border-radius: 5px 5px 0 0; background-color: #888; color: #fff; @@ -68,7 +68,7 @@ align-items: stretch; border: 1px solid #ccc; border-top: none; - border-radius: 0 0 5px 5px; +// border-radius: 0 0 5px 5px; overflow: hidden; .cp-notification { diff --git a/www/notifications/inner.js b/www/notifications/inner.js index 9f657b49e..ce6b1a9a4 100644 --- a/www/notifications/inner.js +++ b/www/notifications/inner.js @@ -46,34 +46,7 @@ define([ var create = {}; - var formatData = function (data) { - return JSON.stringify(data.content.msg.content); - }; - var createElement = function (data) { - var notif; - notif = h('div.cp-notification', { - 'data-hash': data.content.hash - }, [h('div.cp-notification-content', h('p', formatData(data)))]); - - if (data.content.getFormatText) { - $(notif).find('.cp-notification-content p').html(data.content.getFormatText()); - } - - if (data.content.isClickable) { - $(notif).find('.cp-notification-content').addClass("cp-clickable") - .click(data.content.handler); - } - if (data.content.isDismissible) { - var dismissIcon = h('span.fa.fa-times'); - var dismiss = h('div.cp-notification-dismiss', { - title: Messages.notifications_dismiss - }, dismissIcon); - $(dismiss).addClass("cp-clickable").click(data.content.dismissHandler); - $(notif).append(dismiss); - } - return notif; - }; - + var unreadData; // create the list of notifications // show only notifs with type in filterTypes array. If filterTypes empty, don't filter. @@ -83,6 +56,9 @@ define([ var categoryName = Messages['notification_cat_' + safeKey] || safeKey; var notifsData = []; + if (key === "all") { + unreadData = notifsData; + } var $div = $('
', {'class': 'cp-notifications-' + key + ' cp-sidebarlayout-element'}); var notifsPanel, notifsList, dismissAll; notifsPanel = h("div.cp-app-notifications-panel", [ @@ -107,9 +83,12 @@ define([ } } function addArchivedNotification (data) { - if (data.content.archived) { + var isDataUnread = unreadData.findIndex(function (ud) { + return ud.content.hash === data.content.hash; + }) === -1; + if (data.content.archived && isDataUnread) { notifsData.push(data); - var el = createElement(data); + var el = common.mailbox.createElement(data); $(el).addClass("cp-app-notification-archived"); $(notifsList).prepend(el); }