mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-06 23:30:28 +03:00
Notification sounds (#367)
* Basic notification sound support * Add settings option for notification sounds * Allow sound without desktop notifications
This commit is contained in:
parent
a2655ee6a5
commit
dc6e153b92
7 changed files with 78 additions and 24 deletions
|
|
@ -6,6 +6,8 @@ import cons from './cons';
|
|||
import navigation from './navigation';
|
||||
import settings from './settings';
|
||||
|
||||
import NotificationSound from '../../../public/sound/notification.ogg';
|
||||
|
||||
function isNotifEvent(mEvent) {
|
||||
const eType = mEvent.getType();
|
||||
if (!cons.supportEventTypes.includes(eType)) return false;
|
||||
|
|
@ -185,7 +187,7 @@ class Notifications extends EventEmitter {
|
|||
}
|
||||
|
||||
async _displayPopupNoti(mEvent, room) {
|
||||
if (!settings.showNotifications) return;
|
||||
if (!settings.showNotifications && !settings.isNotificationSounds) return;
|
||||
|
||||
const actions = this.matrixClient.getPushActionsForEvent(mEvent);
|
||||
if (!actions?.notify) return;
|
||||
|
|
@ -196,28 +198,43 @@ class Notifications extends EventEmitter {
|
|||
await mEvent.attemptDecryption(this.matrixClient.crypto);
|
||||
}
|
||||
|
||||
let title;
|
||||
if (!mEvent.sender || room.name === mEvent.sender.name) {
|
||||
title = room.name;
|
||||
} else if (mEvent.sender) {
|
||||
title = `${mEvent.sender.name} (${room.name})`;
|
||||
if (settings.showNotifications) {
|
||||
let title;
|
||||
if (!mEvent.sender || room.name === mEvent.sender.name) {
|
||||
title = room.name;
|
||||
} else if (mEvent.sender) {
|
||||
title = `${mEvent.sender.name} (${room.name})`;
|
||||
}
|
||||
|
||||
const iconSize = 36;
|
||||
const icon = await renderAvatar({
|
||||
text: mEvent.sender.name,
|
||||
bgColor: cssColorMXID(mEvent.getSender()),
|
||||
imageSrc: mEvent.sender?.getAvatarUrl(this.matrixClient.baseUrl, iconSize, iconSize, 'crop'),
|
||||
size: iconSize,
|
||||
borderRadius: 8,
|
||||
scale: 8,
|
||||
});
|
||||
|
||||
const noti = new window.Notification(title, {
|
||||
body: mEvent.getContent().body,
|
||||
icon,
|
||||
silent: settings.isNotificationSounds,
|
||||
});
|
||||
if (settings.isNotificationSounds) {
|
||||
noti.onshow = () => this._playNotiSounds();
|
||||
}
|
||||
noti.onclick = () => selectRoom(room.roomId, mEvent.getId());
|
||||
} else {
|
||||
this._playNotiSounds();
|
||||
}
|
||||
}
|
||||
|
||||
const iconSize = 36;
|
||||
const icon = await renderAvatar({
|
||||
text: mEvent.sender.name,
|
||||
bgColor: cssColorMXID(mEvent.getSender()),
|
||||
imageSrc: mEvent.sender?.getAvatarUrl(this.matrixClient.baseUrl, iconSize, iconSize, 'crop'),
|
||||
size: iconSize,
|
||||
borderRadius: 8,
|
||||
scale: 8,
|
||||
});
|
||||
|
||||
const noti = new window.Notification(title, {
|
||||
body: mEvent.getContent().body,
|
||||
icon,
|
||||
});
|
||||
noti.onclick = () => selectRoom(room.roomId, mEvent.getId());
|
||||
_playNotiSounds() {
|
||||
if (!this._notiAudio) {
|
||||
this._notiAudio = new Audio(NotificationSound);
|
||||
}
|
||||
this._notiAudio.play();
|
||||
}
|
||||
|
||||
_listenEvents() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue