From 465bf9bdc0efee3fbde230687e95913b5dca9912 Mon Sep 17 00:00:00 2001 From: Hakadao Date: Sat, 29 Jul 2023 19:55:44 +0800 Subject: [PATCH] fix: message counting issue --- src/components/Topbar/Topbar.vue | 36 +++++++++++++------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/src/components/Topbar/Topbar.vue b/src/components/Topbar/Topbar.vue index 76fcc18b..f77a3454 100644 --- a/src/components/Topbar/Topbar.vue +++ b/src/components/Topbar/Topbar.vue @@ -127,32 +127,24 @@ async function getUnreadMessageCount() { res = await browser.runtime.sendMessage({ contentScriptQuery: 'getUnreadMsg', }) - Object.assign(unReadMessage, res.data) - try { - res = await browser.runtime.sendMessage({ - contentScriptQuery: 'getUnreadDm', - }) + res = await browser.runtime.sendMessage({ + contentScriptQuery: 'getUnreadDm', + }) + Object.assign(unReadDm, res.data) - Object.assign(unReadDm, res.data) + unReadMessageCount.value = 0 - unReadMessageCount.value = 0 - - Object.keys(unReadMessage).forEach((key) => { - if (key !== 'up') { - unReadMessageCount.value - += unReadMessage[key as keyof typeof unReadMessage] - } - }) - - Object.keys(unReadDm).forEach((key) => { - unReadMessageCount.value += unReadDm[key as keyof typeof unReadDm] - }) - } - catch (error) { - unReadMessageCount.value = 0 - } + Object.keys(unReadMessage).forEach((key) => { + if (key !== 'up') { + unReadMessageCount.value + += unReadMessage[key as keyof typeof unReadMessage] ?? 0 + } + }) + Object.keys(unReadDm).forEach((key) => { + unReadMessageCount.value += unReadDm[key as keyof typeof unReadDm] ?? 0 + }) } catch (error) { unReadMessageCount.value = 0