Streaming: Add locale fallback for invalid locale

This commit is contained in:
Alex Gleason 2020-08-13 04:20:35 -05:00
parent 6652df35b3
commit e7bd011495
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -12,10 +12,17 @@ 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';
const validLocale = locale => Object.keys(messages).includes(locale);
const getLocale = state => {
const locale = getSettings(state).get('locale');
return validLocale(locale) ? locale : 'en';
};
export function connectTimelineStream(timelineId, path, pollingRefresh = null, accept = null) { export function connectTimelineStream(timelineId, path, pollingRefresh = null, accept = null) {
return connectStream (path, pollingRefresh, (dispatch, getState) => { return connectStream (path, pollingRefresh, (dispatch, getState) => {
const locale = getSettings(getState()).get('locale'); const locale = getLocale(getState());
return { return {
onConnect() { onConnect() {