Skip to content

Commit

Permalink
Fix badge on ios (#93)
Browse files Browse the repository at this point in the history
* Fix badge

* Update use-messagereceiver.ts
  • Loading branch information
K0IN authored Aug 28, 2023
1 parent 53036ba commit cb09e9f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/frontend/src/components/messages/messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useLastOpenTime } from '../../hooks/use-lastopen';
import { useMessageReceiver } from '../../hooks/use-messagereceiver';
import Message from '../message/message';
import style from './messages.css';
import { useEffect } from 'preact/hooks';

const Messages: FunctionalComponent = () => {
const messages = useMessageReceiver();
Expand All @@ -12,6 +13,12 @@ const Messages: FunctionalComponent = () => {
const newMessages = messages.filter(e => !(e.receivedAt <= lastOpenTime));
const oldMessages = messages.filter(e => e.receivedAt <= lastOpenTime);

useEffect(() => {
if (navigator && navigator.clearAppBadge) {
navigator.clearAppBadge();
}
}, [messages]);

return (<div class={style.content}>
<div class={style.main}>
<ul class={style.messagelist}>
Expand Down
1 change: 1 addition & 0 deletions app/frontend/src/hooks/use-messagereceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const useMessageReceiver = () => {
useEffect(() => {
database && database.getAll('messages').then(savedMessages => setMessages(sortMessages(savedMessages))).catch(console.warn);
database && setAllMessagesAsRead(database as unknown as NotifyDatabase);
navigator.clearAppBadge && navigator.clearAppBadge();
}, [database, setMessages]);

useEffect(() => {
Expand Down
3 changes: 3 additions & 0 deletions app/frontend/src/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ self.addEventListener('push', (event) => {
self.addEventListener('notificationclick', (e) => {
const notification = e.notification;
const load = async () => {
if (navigator && navigator.clearAppBadge) {
navigator.clearAppBadge();
}
try {
const clientList = await clients.matchAll();
if (clientList.length > 0) {
Expand Down

0 comments on commit cb09e9f

Please sign in to comment.