From 30ca63d84ccf7fbc378ebf7101f09e10deaf0eaa Mon Sep 17 00:00:00 2001 From: Vijay A Date: Tue, 14 Sep 2021 13:37:47 +0530 Subject: refactor: defensive programming to avoid javascript error for unread badges --- src/webview/badge.ts | 12 ++++++------ src/webview/lib/RecipeWebview.js | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/webview/badge.ts b/src/webview/badge.ts index 753e90fef..024e29b3f 100644 --- a/src/webview/badge.ts +++ b/src/webview/badge.ts @@ -26,17 +26,17 @@ export class BadgeHandler { return Math.max(adjustedNumber, 0); } - setBadge(direct: string | number, indirect: string | number) { - if (this.countCache.direct.toString() === direct.toString() - && this.countCache.indirect.toString() === indirect.toString()) { - return; - } - + setBadge(direct: string | number | undefined | null, indirect: string | number | undefined | null) { const count = { direct: this.safeParseInt(direct), indirect: this.safeParseInt(indirect), }; + if (this.countCache.direct.toString() === count.direct.toString() + && this.countCache.indirect.toString() === count.indirect.toString()) { + return; + } + debug('Sending badge count to host', count); ipcRenderer.sendToHost('message-counts', count); diff --git a/src/webview/lib/RecipeWebview.js b/src/webview/lib/RecipeWebview.js index 2bd6bad8d..157da7693 100644 --- a/src/webview/lib/RecipeWebview.js +++ b/src/webview/lib/RecipeWebview.js @@ -35,12 +35,12 @@ class RecipeWebview { /** * Set the unread message badge * - * @param {int} direct Set the count of direct messages - * eg. Slack direct mentions, or a - * message to @channel - * @param {int} indirect Set a badge that defines there are - * new messages but they do not involve - * me directly to me eg. in a channel + * @param {string | number | undefined | null} direct Set the count of direct messages + * eg. Slack direct mentions, or a + * message to @channel + * @param {string | number | undefined | null} indirect Set a badge that defines there are + * new messages but they do not involve + * me directly to me eg. in a channel */ setBadge(direct = 0, indirect = 0) { this.badgeHandler.setBadge(direct, indirect); -- cgit v1.2.3-70-g09d2