fix: pwa app badge (#4117)

* fix: clear app badge at zero without notification

* fix: correct users check sometimes failing when searching push subs
This commit is contained in:
Brandon Cohen
2025-04-19 18:50:17 -05:00
committed by GitHub
parent 8cd53cdc3c
commit 208d31180c
2 changed files with 26 additions and 12 deletions

View File

@@ -241,7 +241,7 @@ class WebPushAgent
const allSubs = await userPushSubRepository
.createQueryBuilder('pushSub')
.leftJoinAndSelect('pushSub.user', 'user')
.where('pushSub.userId IN (:users)', {
.where('pushSub.userId IN (:...users)', {
users: manageUsers.map((user) => user.id),
})
.getMany();

View File

@@ -143,18 +143,32 @@ const CoreApp: Omit<NextAppComponentType, 'origGetInitialProps'> = ({
clearAppBadge?: () => Promise<void>;
};
if ('setAppBadge' in navigator) {
const handleBadgeUpdate = () => {
if ('setAppBadge' in newNavigator) {
if (
!router.pathname.match(/(login|setup|resetpassword)/) &&
hasPermission(Permission.ADMIN)
) {
requestsCount().then((data) =>
newNavigator?.setAppBadge?.(data.pending)
);
requestsCount().then((data) => {
if (data.pending > 0) {
newNavigator.setAppBadge?.(data.pending);
} else {
newNavigator?.clearAppBadge?.();
newNavigator.clearAppBadge?.();
}
});
} else {
newNavigator.clearAppBadge?.();
}
}
};
handleBadgeUpdate();
window.addEventListener('focus', handleBadgeUpdate);
return () => {
window.removeEventListener('focus', handleBadgeUpdate);
};
}, [hasPermission, router.pathname]);
if (router.pathname.match(/(login|setup|resetpassword)/)) {