Rough in support for chat sound and flash notification
This commit is contained in:
parent
34a575482c
commit
cf93733076
7 changed files with 64 additions and 6 deletions
|
@ -23,6 +23,8 @@ export const CHAT_READ_REQUEST = 'CHAT_READ_REQUEST';
|
||||||
export const CHAT_READ_SUCCESS = 'CHAT_READ_SUCCESS';
|
export const CHAT_READ_SUCCESS = 'CHAT_READ_SUCCESS';
|
||||||
export const CHAT_READ_FAIL = 'CHAT_READ_FAIL';
|
export const CHAT_READ_FAIL = 'CHAT_READ_FAIL';
|
||||||
|
|
||||||
|
export const STREAMING_CHAT_UPDATE = 'STREAMING_CHAT_UPDATE';
|
||||||
|
|
||||||
export function fetchChats() {
|
export function fetchChats() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
dispatch({ type: CHATS_FETCH_REQUEST });
|
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));
|
||||||
|
// }
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
|
@ -32,6 +32,8 @@ const defaultSettings = ImmutableMap({
|
||||||
chats: ImmutableMap({
|
chats: ImmutableMap({
|
||||||
panes: ImmutableList(),
|
panes: ImmutableList(),
|
||||||
mainWindow: 'minimized',
|
mainWindow: 'minimized',
|
||||||
|
sound: true,
|
||||||
|
flash: true,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
home: ImmutableMap({
|
home: ImmutableMap({
|
||||||
|
|
|
@ -7,12 +7,13 @@ import {
|
||||||
processTimelineUpdate,
|
processTimelineUpdate,
|
||||||
} from './timelines';
|
} from './timelines';
|
||||||
import { updateNotificationsQueue, expandNotifications } from './notifications';
|
import { updateNotificationsQueue, expandNotifications } from './notifications';
|
||||||
|
import { updateChatsQueue } from './chats';
|
||||||
import { updateConversations } from './conversations';
|
import { updateConversations } from './conversations';
|
||||||
import { fetchFilters } from './filters';
|
import { fetchFilters } from './filters';
|
||||||
import { getSettings } from 'soapbox/actions/settings';
|
import { getSettings } from 'soapbox/actions/settings';
|
||||||
import messages from 'soapbox/locales/messages';
|
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);
|
const validLocale = locale => Object.keys(messages).includes(locale);
|
||||||
|
|
||||||
|
@ -55,7 +56,8 @@ export function connectTimelineStream(timelineId, path, pollingRefresh = null, a
|
||||||
dispatch(fetchFilters());
|
dispatch(fetchFilters());
|
||||||
break;
|
break;
|
||||||
case 'pleroma:chat_update':
|
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;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,7 +4,7 @@ import {
|
||||||
ACCOUNT_FETCH_FAIL_FOR_USERNAME_LOOKUP,
|
ACCOUNT_FETCH_FAIL_FOR_USERNAME_LOOKUP,
|
||||||
} from '../actions/importer';
|
} from '../actions/importer';
|
||||||
import { CHATS_FETCH_SUCCESS, CHAT_FETCH_SUCCESS } from 'soapbox/actions/chats';
|
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 { normalizeAccount as normalizeAccount2 } from 'soapbox/actions/importer/normalizer';
|
||||||
import { Map as ImmutableMap, fromJS } from 'immutable';
|
import { Map as ImmutableMap, fromJS } from 'immutable';
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import {
|
||||||
CHAT_MESSAGE_SEND_REQUEST,
|
CHAT_MESSAGE_SEND_REQUEST,
|
||||||
CHAT_MESSAGE_SEND_SUCCESS,
|
CHAT_MESSAGE_SEND_SUCCESS,
|
||||||
} from 'soapbox/actions/chats';
|
} 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';
|
import { Map as ImmutableMap, OrderedSet as ImmutableOrderedSet } from 'immutable';
|
||||||
|
|
||||||
const initialState = ImmutableMap();
|
const initialState = ImmutableMap();
|
||||||
|
|
|
@ -4,7 +4,7 @@ import {
|
||||||
CHAT_MESSAGE_SEND_REQUEST,
|
CHAT_MESSAGE_SEND_REQUEST,
|
||||||
CHAT_MESSAGE_SEND_SUCCESS,
|
CHAT_MESSAGE_SEND_SUCCESS,
|
||||||
} from 'soapbox/actions/chats';
|
} 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';
|
import { Map as ImmutableMap, fromJS } from 'immutable';
|
||||||
|
|
||||||
const initialState = ImmutableMap();
|
const initialState = ImmutableMap();
|
||||||
|
|
|
@ -4,7 +4,7 @@ import {
|
||||||
CHAT_READ_SUCCESS,
|
CHAT_READ_SUCCESS,
|
||||||
CHAT_READ_REQUEST,
|
CHAT_READ_REQUEST,
|
||||||
} from 'soapbox/actions/chats';
|
} 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 { normalizeChat } from 'soapbox/actions/importer/normalizer';
|
||||||
import { Map as ImmutableMap, fromJS } from 'immutable';
|
import { Map as ImmutableMap, fromJS } from 'immutable';
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue