From 58befce95be00104e2f189dbb920879fbcf80ee6 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 29 Nov 2021 16:22:17 +0100 Subject: [PATCH] Set the unread counter on page load --- .../Core/Ui/User/Menu/Data/Notification.ts | 15 +++++++++++++++ .../Core/Ui/User/Menu/Data/Notification.js | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/ts/WoltLabSuite/Core/Ui/User/Menu/Data/Notification.ts b/ts/WoltLabSuite/Core/Ui/User/Menu/Data/Notification.ts index 2e231c43b7..658f5518a1 100644 --- a/ts/WoltLabSuite/Core/Ui/User/Menu/Data/Notification.ts +++ b/ts/WoltLabSuite/Core/Ui/User/Menu/Data/Notification.ts @@ -102,8 +102,23 @@ function drawCounter(ctx: CanvasRenderingContext2D, counter: string): void { } export class UserMenuDataNotification implements UserMenuProvider { + private readonly button: HTMLElement | null; private view: UserMenuView | undefined = undefined; + constructor() { + this.button = document.getElementById("userNotifications"); + + if (this.button) { + const badge = this.button.querySelector(".badge"); + if (badge) { + const counter = parseInt(badge.textContent!.trim()); + if (counter) { + updateUnreadCounter(counter); + } + } + } + } + getButtons(): UserMenuButton[] { return [ { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Menu/Data/Notification.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Menu/Data/Notification.js index 6b4d23e095..a824f2f067 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Menu/Data/Notification.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Menu/Data/Notification.js @@ -88,6 +88,16 @@ define(["require", "exports", "tslib", "../../../../Ajax", "../View"], function class UserMenuDataNotification { constructor() { this.view = undefined; + this.button = document.getElementById("userNotifications"); + if (this.button) { + const badge = this.button.querySelector(".badge"); + if (badge) { + const counter = parseInt(badge.textContent.trim()); + if (counter) { + updateUnreadCounter(counter); + } + } + } } getButtons() { return [ -- 2.20.1