From 5a836c9573de9cc2734c92cc039c2de22f37a7dc Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Wed, 3 Feb 2016 23:35:12 +0900 Subject: [PATCH] Revert mention count with ignoring 'badge-notify' 'badge-notify' counts also unread channels. --- src/browser/webview/mattermost.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/browser/webview/mattermost.js b/src/browser/webview/mattermost.js index eecbe3ea..6f1c2c98 100644 --- a/src/browser/webview/mattermost.js +++ b/src/browser/webview/mattermost.js @@ -4,6 +4,14 @@ const electron = require('electron'); const ipc = electron.ipcRenderer; const NativeNotification = Notification; +var hasClass = function(element, className) { + var rclass = /[\t\r\n\f]/g; + if ((' ' + element.className + ' ').replace(rclass, ' ').indexOf(className) > -1) { + return true; + } + return false; +}; + var unreadCountTimer = setInterval(function() { if (!this.unreadCount) { this.unreadCount = 0; @@ -15,11 +23,13 @@ var unreadCountTimer = setInterval(function() { // unreadCount in sidebar // Note: the active channel doesn't have '.unread-title'. var unreadCount = document.getElementsByClassName('unread-title').length; - // mentionCount in mobile navbar-toggle - var mentionBadge = document.getElementsByClassName('badge-notify'); + // mentionCount in sidebar + var elem = document.getElementsByClassName('badge') var mentionCount = 0; - if (mentionBadge.length > 0) { // older mattermost doesn't have badges. - mentionCount = Number(mentionBadge[0].innerHTML); + for (var i = 0; i < elem.length; i++) { + if (isElementVisible(elem[i]) && !hasClass(elem[i], 'badge-notify')) { + mentionCount += Number(elem[i].innerHTML); + } } var postAttrName = 'data-reactid';