From ca9be1ed05fcc166009a933eec383d99797fdc2b Mon Sep 17 00:00:00 2001 From: Curtis ROck Date: Sat, 5 Sep 2020 16:50:33 -0500 Subject: [PATCH] Audio notification on chat. Currently hardcoded on in store/settings --- app/soapbox/actions/chats.js | 53 ++++++------------------------------ 1 file changed, 9 insertions(+), 44 deletions(-) diff --git a/app/soapbox/actions/chats.js b/app/soapbox/actions/chats.js index 79d7e25ea..4e89d4ad6 100644 --- a/app/soapbox/actions/chats.js +++ b/app/soapbox/actions/chats.js @@ -24,6 +24,7 @@ export const CHAT_READ_SUCCESS = 'CHAT_READ_SUCCESS'; export const CHAT_READ_FAIL = 'CHAT_READ_FAIL'; export const STREAMING_CHAT_UPDATE = 'STREAMING_CHAT_UPDATE'; +export const CHATS_UPDATE_NOOP = 'CHATS_UPDATE_NOOP'; export function fetchChats() { return (dispatch, getState) => { @@ -155,52 +156,16 @@ export function markChatRead(chatId, lastReadId) { export function updateChatsQueue(chat) { return (dispatch, getState) => { - if (chat.type === 'pleroma:chat_mention') return; // Drop chat notifications, handle them per-chat + const playSound = getSettings(getState()).getIn(['chats', 'sound']); + // const flashWindow = getSettings(getState()).getIn(['chats', 'flash']); - // const showAlert = getSettings(getState()).getIn(['notifications', 'alerts', chat.type]); - // const filters = getFilters(getState(), { contextType: 'notifications' }); - // const playSound = getSettings(getState()).getIn(['notifications', 'sounds', chat.type]); - // - // let filtered = false; - // - // const isOnNotificationsPage = curPath === '/notifications'; - // - // if (chat.type === 'mention') { - // const regex = regexFromFilters(filters); - // const searchIndex = chat.status.spoiler_text + '\n' + unescapeHTML(chat.status.content); - // filtered = regex && regex.test(searchIndex); - // } - // - // // Desktop notifications - // if (typeof window.Notification !== 'undefined' && showAlert && !filtered) { - // const title = new IntlMessageFormat(intlMessages[`notification.${chat.type}`], intlLocale).format({ name: chat.account.display_name.length > 0 ? chat.account.display_name : notification.account.username }); - // const body = (chat.status && chat.status.spoiler_text.length > 0) ? chat.status.spoiler_text : unescapeHTML(chat.status ? chat.status.content : ''); - // - // const notify = new Notification(title, { body, icon: chat.account.avatar, tag: chat.id }); - // - // notify.addEventListener('click', () => { - // window.focus(); - // notify.close(); - // }); - // } - - // if (playSound && !filtered) { - // dispatch({ - // type: CHATS_UPDATE_NOOP, - // meta: { sound: 'boop' }, - // }); - // } + if (playSound) { + dispatch({ + type: CHATS_UPDATE_NOOP, + meta: { sound: 'chat' }, + }); + } dispatch({ type: STREAMING_CHAT_UPDATE, chat: chat, me: getState().get('me') }); - // if (isOnNotificationsPage) { - // dispatch({ - // type: CHATS_UPDATE_QUEUE, - // chat, - // intlMessages, - // intlLocale, - // }); - // } else { - // dispatch(updateChats(chat, intlMessages, intlLocale)); - // } }; };