import { AjaxCallbackSetup } from "../Ajax/Data";
import * as Core from "../Core";
import * as EventHandler from "../Event/Handler";
+import { updateCounter } from "WoltLabSuite/Core/Ui/User/Menu/Manager";
interface NotificationHandlerOptions {
icon: string;
interface AjaxResponse {
returnValues: {
- keepAliveData: unknown;
+ keepAliveData: {
+ userNotificationCount: number;
+ };
lastRequestTimestamp: number;
pollData: PollingResult;
};
const pollData = data.returnValues.pollData;
// forward keep alive data
- window.WCF.System.PushNotification.executeCallbacks({ returnValues: keepAliveData });
+ updateCounter("com.woltlab.wcf.notifications", keepAliveData.userNotificationCount);
// store response data in local storage
let abort = false;
import { dboAction } from "../../../../Ajax";
import UserMenuView from "../View";
-import { UserMenuButton, UserMenuData, UserMenuFooter, UserMenuProvider } from "./Provider";
+import { EventUpdateCounter, UserMenuButton, UserMenuData, UserMenuFooter, UserMenuProvider } from "./Provider";
import { registerProvider } from "../Manager";
type Options = {
this.counter = counter;
}
}
+ this.button.addEventListener("updateCounter", (event: CustomEvent<EventUpdateCounter>) => {
+ this.updateCounter(event.detail.counter);
+
+ this.stale = true;
+ });
}
getPanelButton(): HTMLElement {
import { dboAction } from "../../../../Ajax";
import UserMenuView from "../View";
-import { UserMenuButton, UserMenuData, UserMenuFooter, UserMenuProvider } from "./Provider";
+import { EventUpdateCounter, UserMenuButton, UserMenuData, UserMenuFooter, UserMenuProvider } from "./Provider";
import { registerProvider } from "../Manager";
import * as Language from "../../../../Language";
import { enableNotifications } from "../../../../Notification/Handler";
setFaviconCounter(this.counter);
}
- window.WCF.System.PushNotification.addCallback("userNotificationCount", (count: number) => {
- this.updateCounter(count);
+ this.button.addEventListener("updateCounter", (event: CustomEvent<EventUpdateCounter>) => {
+ this.updateCounter(event.detail.counter);
this.stale = true;
});
time: number;
usernames: string[];
};
+
+export type EventUpdateCounter = {
+ counter: number;
+};
* @woltlabExcludeBundle tiny
*/
-import { UserMenuProvider } from "./Data/Provider";
+import { EventUpdateCounter, UserMenuProvider } from "./Data/Provider";
import UserMenuView from "./View";
import * as Alignment from "../../Alignment";
import CloseOverlay from "../../CloseOverlay";
return providers;
}
+export function updateCounter(identifier: string, counter: number) {
+ Array.from(providers)
+ .filter((provider) => provider.getIdentifier() === identifier)
+ .forEach((provider) => {
+ provider.getPanelButton().dispatchEvent(
+ new CustomEvent<EventUpdateCounter>("updateCounter", {
+ detail: { counter: counter },
+ }),
+ );
+ });
+}
+
export function getContainer(): HTMLElement {
if (container === undefined) {
container = document.createElement("div");
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @woltlabExcludeBundle tiny
*/
-define(["require", "exports", "tslib", "../Ajax", "../Core", "../Event/Handler"], function (require, exports, tslib_1, Ajax, Core, EventHandler) {
+define(["require", "exports", "tslib", "../Ajax", "../Core", "../Event/Handler", "WoltLabSuite/Core/Ui/User/Menu/Manager"], function (require, exports, tslib_1, Ajax, Core, EventHandler, Manager_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.poll = exports.enableNotifications = exports.setup = void 0;
const keepAliveData = data.returnValues.keepAliveData;
const pollData = data.returnValues.pollData;
// forward keep alive data
- window.WCF.System.PushNotification.executeCallbacks({ returnValues: keepAliveData });
+ (0, Manager_1.updateCounter)("com.woltlab.wcf.notifications", keepAliveData.userNotificationCount);
// store response data in local storage
let abort = false;
try {
this.counter = counter;
}
}
+ this.button.addEventListener("updateCounter", (event) => {
+ this.updateCounter(event.detail.counter);
+ this.stale = true;
+ });
}
getPanelButton() {
return this.button;
if (this.counter > 0) {
setFaviconCounter(this.counter);
}
- window.WCF.System.PushNotification.addCallback("userNotificationCount", (count) => {
- this.updateCounter(count);
+ this.button.addEventListener("updateCounter", (event) => {
+ this.updateCounter(event.detail.counter);
this.stale = true;
});
}
define(["require", "exports", "tslib", "../../Alignment", "../../CloseOverlay", "../../../Event/Handler", "../../../Dom/Util", "../../Screen", "../../../Helper/PageOverlay"], function (require, exports, tslib_1, Alignment, CloseOverlay_1, EventHandler, Util_1, UiScreen, PageOverlay_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
- exports.registerProvider = exports.getContainer = exports.getUserMenuProviders = void 0;
+ exports.registerProvider = exports.getContainer = exports.updateCounter = exports.getUserMenuProviders = void 0;
Alignment = tslib_1.__importStar(Alignment);
CloseOverlay_1 = tslib_1.__importDefault(CloseOverlay_1);
EventHandler = tslib_1.__importStar(EventHandler);
return providers;
}
exports.getUserMenuProviders = getUserMenuProviders;
+ function updateCounter(identifier, counter) {
+ Array.from(providers)
+ .filter((provider) => provider.getIdentifier() === identifier)
+ .forEach((provider) => {
+ provider.getPanelButton().dispatchEvent(new CustomEvent("updateCounter", {
+ detail: { counter: counter },
+ }));
+ });
+ }
+ exports.updateCounter = updateCounter;
function getContainer() {
if (container === undefined) {
container = document.createElement("div");