Notifications: Fix unneeded sound from reactions (#1756)

This commit is contained in:
Alexander Zinchuk 2022-03-13 14:52:53 +01:00
parent 0b1fc0904e
commit 6d0d8a3419
2 changed files with 8 additions and 4 deletions

View File

@ -485,7 +485,7 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
const chat = selectChat(global, update.chatId); const chat = selectChat(global, update.chatId);
const currentReactions = message?.reactions; const currentReactions = message?.reactions;
// `updateMessageReactions` happens with an interval so we try to avoid redundant global state updates // `updateMessageReactions` happens with an interval, so we try to avoid redundant global state updates
if (currentReactions && areDeepEqual(reactions, currentReactions)) { if (currentReactions && areDeepEqual(reactions, currentReactions)) {
return; return;
} }
@ -501,6 +501,7 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
notifyAboutMessage({ notifyAboutMessage({
chat, chat,
message: newMessage, message: newMessage,
isReaction: true,
}); });
} }

View File

@ -332,12 +332,15 @@ async function getAvatar(chat: ApiChat) {
export async function notifyAboutMessage({ export async function notifyAboutMessage({
chat, chat,
message, message,
}: { chat: ApiChat; message: Partial<ApiMessage> }) { isReaction = false,
}: { chat: ApiChat; message: Partial<ApiMessage>; isReaction?: boolean }) {
const { hasWebNotifications } = await loadNotificationSettings(); const { hasWebNotifications } = await loadNotificationSettings();
if (!checkIfShouldNotify(chat)) return; if (!checkIfShouldNotify(chat)) return;
const areNotificationsSupported = checkIfNotificationsSupported(); const areNotificationsSupported = checkIfNotificationsSupported();
if (!hasWebNotifications || !areNotificationsSupported) { if (!hasWebNotifications || !areNotificationsSupported) {
// only play sound if web notifications are disabled // Do not play notification sound for reactions if web notifications are disabled
if (isReaction) return;
// Only play sound if web notifications are disabled
playNotifySoundDebounced(String(message.id) || chat.id); playNotifySoundDebounced(String(message.id) || chat.id);
return; return;
} }
@ -364,7 +367,7 @@ export async function notifyAboutMessage({
icon, icon,
chatId: chat.id, chatId: chat.id,
messageId: message.id, messageId: message.id,
reaction: activeReaction ? activeReaction.reaction : undefined, reaction: activeReaction?.reaction,
}, },
}); });
} }