From cf93733076a6ffad7af127afcebe76fd17d68195 Mon Sep 17 00:00:00 2001 From: Curtis ROck Date: Fri, 4 Sep 2020 21:43:14 -0500 Subject: [PATCH] Rough in support for chat sound and flash notification --- app/soapbox/actions/chats.js | 54 ++++++++++++++++++++++ app/soapbox/actions/settings.js | 2 + app/soapbox/actions/streaming.js | 6 ++- app/soapbox/reducers/accounts.js | 2 +- app/soapbox/reducers/chat_message_lists.js | 2 +- app/soapbox/reducers/chat_messages.js | 2 +- app/soapbox/reducers/chats.js | 2 +- 7 files changed, 64 insertions(+), 6 deletions(-) diff --git a/app/soapbox/actions/chats.js b/app/soapbox/actions/chats.js index 729dc128e..79d7e25ea 100644 --- a/app/soapbox/actions/chats.js +++ b/app/soapbox/actions/chats.js @@ -23,6 +23,8 @@ export const CHAT_READ_REQUEST = 'CHAT_READ_REQUEST'; 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 function fetchChats() { return (dispatch, getState) => { dispatch({ type: CHATS_FETCH_REQUEST }); @@ -150,3 +152,55 @@ 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 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' }, + // }); + // } + + 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)); + // } + }; +}; diff --git a/app/soapbox/actions/settings.js b/app/soapbox/actions/settings.js index 4432fa6e0..7d330219f 100644 --- a/app/soapbox/actions/settings.js +++ b/app/soapbox/actions/settings.js @@ -32,6 +32,8 @@ const defaultSettings = ImmutableMap({ chats: ImmutableMap({ panes: ImmutableList(), mainWindow: 'minimized', + sound: true, + flash: true, }), home: ImmutableMap({ diff --git a/app/soapbox/actions/streaming.js b/app/soapbox/actions/streaming.js index a581ae0fe..c3e4363da 100644 --- a/app/soapbox/actions/streaming.js +++ b/app/soapbox/actions/streaming.js @@ -7,12 +7,13 @@ import { processTimelineUpdate, } from './timelines'; import { updateNotificationsQueue, expandNotifications } from './notifications'; +import { updateChatsQueue } from './chats'; import { updateConversations } from './conversations'; import { fetchFilters } from './filters'; import { getSettings } from 'soapbox/actions/settings'; import messages from 'soapbox/locales/messages'; -export const STREAMING_CHAT_UPDATE = 'STREAMING_CHAT_UPDATE'; +// export const STREAMING_CHAT_UPDATE = 'STREAMING_CHAT_UPDATE'; const validLocale = locale => Object.keys(messages).includes(locale); @@ -55,7 +56,8 @@ export function connectTimelineStream(timelineId, path, pollingRefresh = null, a dispatch(fetchFilters()); break; case 'pleroma:chat_update': - dispatch({ type: STREAMING_CHAT_UPDATE, chat: JSON.parse(data.payload), me: getState().get('me') }); + dispatch(updateChatsQueue(JSON.parse(data.payload))); + // dispatch({ type: STREAMING_CHAT_UPDATE, chat: JSON.parse(data.payload), me: getState().get('me') }); break; } }, diff --git a/app/soapbox/reducers/accounts.js b/app/soapbox/reducers/accounts.js index b02ef763f..ae565d782 100644 --- a/app/soapbox/reducers/accounts.js +++ b/app/soapbox/reducers/accounts.js @@ -4,7 +4,7 @@ import { ACCOUNT_FETCH_FAIL_FOR_USERNAME_LOOKUP, } from '../actions/importer'; import { CHATS_FETCH_SUCCESS, CHAT_FETCH_SUCCESS } from 'soapbox/actions/chats'; -import { STREAMING_CHAT_UPDATE } from 'soapbox/actions/streaming'; +import { STREAMING_CHAT_UPDATE } from 'soapbox/actions/chats'; import { normalizeAccount as normalizeAccount2 } from 'soapbox/actions/importer/normalizer'; import { Map as ImmutableMap, fromJS } from 'immutable'; diff --git a/app/soapbox/reducers/chat_message_lists.js b/app/soapbox/reducers/chat_message_lists.js index b584dca72..b1cfcd0a4 100644 --- a/app/soapbox/reducers/chat_message_lists.js +++ b/app/soapbox/reducers/chat_message_lists.js @@ -4,7 +4,7 @@ import { CHAT_MESSAGE_SEND_REQUEST, CHAT_MESSAGE_SEND_SUCCESS, } from 'soapbox/actions/chats'; -import { STREAMING_CHAT_UPDATE } from 'soapbox/actions/streaming'; +import { STREAMING_CHAT_UPDATE } from 'soapbox/actions/chats'; import { Map as ImmutableMap, OrderedSet as ImmutableOrderedSet } from 'immutable'; const initialState = ImmutableMap(); diff --git a/app/soapbox/reducers/chat_messages.js b/app/soapbox/reducers/chat_messages.js index 74d83ef79..b44a1e6e5 100644 --- a/app/soapbox/reducers/chat_messages.js +++ b/app/soapbox/reducers/chat_messages.js @@ -4,7 +4,7 @@ import { CHAT_MESSAGE_SEND_REQUEST, CHAT_MESSAGE_SEND_SUCCESS, } from 'soapbox/actions/chats'; -import { STREAMING_CHAT_UPDATE } from 'soapbox/actions/streaming'; +import { STREAMING_CHAT_UPDATE } from 'soapbox/actions/chats'; import { Map as ImmutableMap, fromJS } from 'immutable'; const initialState = ImmutableMap(); diff --git a/app/soapbox/reducers/chats.js b/app/soapbox/reducers/chats.js index 0efb5361f..745a7acf7 100644 --- a/app/soapbox/reducers/chats.js +++ b/app/soapbox/reducers/chats.js @@ -4,7 +4,7 @@ import { CHAT_READ_SUCCESS, CHAT_READ_REQUEST, } from 'soapbox/actions/chats'; -import { STREAMING_CHAT_UPDATE } from 'soapbox/actions/streaming'; +import { STREAMING_CHAT_UPDATE } from 'soapbox/actions/chats'; import { normalizeChat } from 'soapbox/actions/importer/normalizer'; import { Map as ImmutableMap, fromJS } from 'immutable';