mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-07 15:50:29 +03:00
set app badge
This commit is contained in:
parent
350f3ac2f7
commit
815a0ac7f4
2 changed files with 6 additions and 3 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { Room, RoomEvent, RoomEventHandlerMap } from 'matrix-js-sdk';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { getUnreadInfo } from '../utils/room';
|
||||
|
||||
const getEventReaders = (room: Room, evtId?: string) => {
|
||||
if (!evtId) return [];
|
||||
|
|
@ -21,7 +22,7 @@ const getEventReaders = (room: Room, evtId?: string) => {
|
|||
|
||||
export const useRoomEventReaders = (room: Room, eventId?: string): string[] => {
|
||||
const [readers, setReaders] = useState<string[]>(() => getEventReaders(room, eventId));
|
||||
|
||||
const unreadInfo = getUnreadInfo(room);
|
||||
useEffect(() => {
|
||||
setReaders(getEventReaders(room, eventId));
|
||||
|
||||
|
|
@ -46,11 +47,13 @@ export const useRoomEventReaders = (room: Room, eventId?: string): string[] => {
|
|||
|
||||
room.on(RoomEvent.Receipt, handleReceipt);
|
||||
room.on(RoomEvent.LocalEchoUpdated, handleLocalEcho);
|
||||
|
||||
navigator.setAppBadge(unreadInfo.total);
|
||||
return () => {
|
||||
room.removeListener(RoomEvent.Receipt, handleReceipt);
|
||||
room.removeListener(RoomEvent.LocalEchoUpdated, handleLocalEcho);
|
||||
};
|
||||
}, [room, eventId]);
|
||||
}, [room, eventId, unreadInfo.total]);
|
||||
|
||||
return readers;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ function MessageNotifications() {
|
|||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
navigator.setAppBadge(unreadInfo.total);
|
||||
if (showNotifications && notificationPermission('granted')) {
|
||||
const avatarMxc =
|
||||
room.getAvatarFallbackMember()?.getMxcAvatarUrl() ?? room.getMxcAvatarUrl();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue