From 1a4890a7a52ac34ca54c84b4e8b014ec7928632d Mon Sep 17 00:00:00 2001 From: Vijay A Date: Thu, 23 Sep 2021 20:18:53 +0530 Subject: fix: implement unread count badge for 'stackoverflow-chat' --- recipes/stackoverflow-chat/package.json | 2 +- recipes/stackoverflow-chat/webview.js | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'recipes') diff --git a/recipes/stackoverflow-chat/package.json b/recipes/stackoverflow-chat/package.json index 688db65..4cbddeb 100644 --- a/recipes/stackoverflow-chat/package.json +++ b/recipes/stackoverflow-chat/package.json @@ -1,7 +1,7 @@ { "id": "stackoverflow-chat", "name": "Stackoverflow chat", - "version": "1.0.0", + "version": "1.0.1", "license": "MIT", "config": { "serviceURL": "https://chat.stackoverflow.com/", diff --git a/recipes/stackoverflow-chat/webview.js b/recipes/stackoverflow-chat/webview.js index 044c773..cf487b5 100644 --- a/recipes/stackoverflow-chat/webview.js +++ b/recipes/stackoverflow-chat/webview.js @@ -3,12 +3,15 @@ var _path = _interopRequireDefault(require('path')); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } module.exports = Ferdi => { - // TODO: If your stackoverflow-chat service has unread messages, uncomment these lines to implement the logic for updating the badges - // const getMessages = () => { - // // TODO: Insert your notification-finding code here - // Ferdi.setBadge(0, 0); - // }; - // Ferdi.loop(getMessages); + const getMessages = () => { + const unreadSpan = document.querySelector('span.flag-count.message-count.unread-count'); + let directCount = 0; + if (unreadSpan) { + directCount = Ferdi.safeParseInt(unreadSpan.innerText); + } + Ferdi.setBadge(directCount); + }; + Ferdi.loop(getMessages); Ferdi.injectCSS(_path.default.join(__dirname, 'service.css')); }; -- cgit v1.2.3-54-g00ecf