mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-01-18 19:56:01 +01:00
fix notification, favicon and sound (#1802)
This commit is contained in:
parent
4f09e6bbb5
commit
e058a9ae6c
1 changed files with 18 additions and 8 deletions
|
@ -6,6 +6,8 @@ import { roomToUnreadAtom, unreadEqual, unreadInfoToUnread } from '../../state/r
|
||||||
import LogoSVG from '../../../../public/res/svg/cinny.svg';
|
import LogoSVG from '../../../../public/res/svg/cinny.svg';
|
||||||
import LogoUnreadSVG from '../../../../public/res/svg/cinny-unread.svg';
|
import LogoUnreadSVG from '../../../../public/res/svg/cinny-unread.svg';
|
||||||
import LogoHighlightSVG from '../../../../public/res/svg/cinny-highlight.svg';
|
import LogoHighlightSVG from '../../../../public/res/svg/cinny-highlight.svg';
|
||||||
|
import NotificationSound from '../../../../public/sound/notification.ogg';
|
||||||
|
import InviteSound from '../../../../public/sound/invite.ogg';
|
||||||
import { setFavicon } from '../../utils/dom';
|
import { setFavicon } from '../../utils/dom';
|
||||||
import { useSetting } from '../../state/hooks/settings';
|
import { useSetting } from '../../state/hooks/settings';
|
||||||
import { settingsAtom } from '../../state/settings';
|
import { settingsAtom } from '../../state/settings';
|
||||||
|
@ -28,14 +30,21 @@ function FaviconUpdater() {
|
||||||
const roomToUnread = useAtomValue(roomToUnreadAtom);
|
const roomToUnread = useAtomValue(roomToUnreadAtom);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (roomToUnread.size === 0) {
|
let notification = false;
|
||||||
setFavicon(LogoSVG);
|
let highlight = false;
|
||||||
} else {
|
roomToUnread.forEach((unread) => {
|
||||||
const highlight = Array.from(roomToUnread.entries()).find(
|
if (unread.total > 0) {
|
||||||
([, unread]) => unread.highlight > 0
|
notification = true;
|
||||||
);
|
}
|
||||||
|
if (unread.highlight > 0) {
|
||||||
|
highlight = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (notification) {
|
||||||
setFavicon(highlight ? LogoHighlightSVG : LogoUnreadSVG);
|
setFavicon(highlight ? LogoHighlightSVG : LogoUnreadSVG);
|
||||||
|
} else {
|
||||||
|
setFavicon(LogoSVG);
|
||||||
}
|
}
|
||||||
}, [roomToUnread]);
|
}, [roomToUnread]);
|
||||||
|
|
||||||
|
@ -88,7 +97,7 @@ function InviteNotifications() {
|
||||||
return (
|
return (
|
||||||
// eslint-disable-next-line jsx-a11y/media-has-caption
|
// eslint-disable-next-line jsx-a11y/media-has-caption
|
||||||
<audio ref={audioRef} style={{ display: 'none' }}>
|
<audio ref={audioRef} style={{ display: 'none' }}>
|
||||||
<source src="../../../../public/sound/invite.ogg" type="audio/ogg" />
|
<source src={InviteSound} type="audio/ogg" />
|
||||||
</audio>
|
</audio>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -168,6 +177,7 @@ function MessageNotifications() {
|
||||||
const cachedUnreadInfo = unreadCacheRef.current.get(room.roomId);
|
const cachedUnreadInfo = unreadCacheRef.current.get(room.roomId);
|
||||||
unreadCacheRef.current.set(room.roomId, unreadInfo);
|
unreadCacheRef.current.set(room.roomId, unreadInfo);
|
||||||
|
|
||||||
|
if (unreadInfo.total === 0) return;
|
||||||
if (
|
if (
|
||||||
cachedUnreadInfo &&
|
cachedUnreadInfo &&
|
||||||
unreadEqual(unreadInfoToUnread(cachedUnreadInfo), unreadInfoToUnread(unreadInfo))
|
unreadEqual(unreadInfoToUnread(cachedUnreadInfo), unreadInfoToUnread(unreadInfo))
|
||||||
|
@ -210,7 +220,7 @@ function MessageNotifications() {
|
||||||
return (
|
return (
|
||||||
// eslint-disable-next-line jsx-a11y/media-has-caption
|
// eslint-disable-next-line jsx-a11y/media-has-caption
|
||||||
<audio ref={audioRef} style={{ display: 'none' }}>
|
<audio ref={audioRef} style={{ display: 'none' }}>
|
||||||
<source src="../../../../public/sound/notification.ogg" type="audio/ogg" />
|
<source src={NotificationSound} type="audio/ogg" />
|
||||||
</audio>
|
</audio>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue