2017-12-21 18:32:51 +01:00
|
|
|
import * as ACTIONS from 'constants/action_types';
|
2021-10-17 10:36:14 +02:00
|
|
|
import * as SETTINGS from 'constants/settings';
|
|
|
|
import * as SHARED_PREFERENCES from 'constants/shared_preferences';
|
2019-08-16 16:57:15 +02:00
|
|
|
import moment from 'moment';
|
2020-07-10 23:04:36 +02:00
|
|
|
import { getSubsetFromKeysArray } from 'util/sync-settings';
|
2021-01-06 19:13:56 +01:00
|
|
|
import { getDefaultLanguage } from 'util/default-languages';
|
2021-11-24 17:11:25 +01:00
|
|
|
import { UNSYNCED_SETTINGS } from 'config';
|
2020-11-10 17:07:00 +01:00
|
|
|
|
2020-07-10 23:04:36 +02:00
|
|
|
const { CLIENT_SYNC_KEYS } = SHARED_PREFERENCES;
|
2020-07-31 20:24:01 +02:00
|
|
|
const settingsToIgnore = (UNSYNCED_SETTINGS && UNSYNCED_SETTINGS.trim().split(' ')) || [];
|
|
|
|
const clientSyncKeys = settingsToIgnore.length
|
2021-07-19 18:52:29 +02:00
|
|
|
? CLIENT_SYNC_KEYS.filter((k) => !settingsToIgnore.includes(k))
|
2020-07-31 20:24:01 +02:00
|
|
|
: CLIENT_SYNC_KEYS;
|
2020-07-10 23:04:36 +02:00
|
|
|
|
2017-06-06 06:21:55 +02:00
|
|
|
const reducers = {};
|
2019-12-30 20:54:53 +01:00
|
|
|
let settingLanguage = [];
|
|
|
|
try {
|
|
|
|
let appLanguage = window.localStorage.getItem(SETTINGS.LANGUAGE);
|
|
|
|
settingLanguage.push(appLanguage);
|
|
|
|
} catch (e) {}
|
2021-01-06 19:13:56 +01:00
|
|
|
settingLanguage.push(getDefaultLanguage());
|
2019-12-30 20:54:53 +01:00
|
|
|
settingLanguage.push('en');
|
|
|
|
|
2017-06-28 09:12:01 +02:00
|
|
|
const defaultState = {
|
2019-09-17 20:49:03 +02:00
|
|
|
isNight: false,
|
2020-03-24 18:57:17 +01:00
|
|
|
findingFFmpeg: false,
|
2019-11-14 00:51:23 +01:00
|
|
|
loadedLanguages: [...Object.keys(window.i18n_messages), 'en'] || ['en'],
|
2019-12-11 21:09:27 +01:00
|
|
|
customWalletServers: [],
|
2020-02-25 02:04:37 +01:00
|
|
|
sharedPreferences: {},
|
2019-09-17 20:49:03 +02:00
|
|
|
daemonSettings: {},
|
2020-03-24 18:57:17 +01:00
|
|
|
daemonStatus: { ffmpeg_status: {} },
|
2017-06-28 09:12:01 +02:00
|
|
|
clientSettings: {
|
2019-09-17 20:49:03 +02:00
|
|
|
// UX
|
|
|
|
[SETTINGS.EMAIL_COLLECTION_ACKNOWLEDGED]: false,
|
2020-08-24 06:00:10 +02:00
|
|
|
[SETTINGS.FOLLOWING_ACKNOWLEDGED]: false,
|
|
|
|
[SETTINGS.TAGS_ACKNOWLEDGED]: false,
|
2020-08-20 07:37:55 +02:00
|
|
|
[SETTINGS.ENABLE_SYNC]: IS_WEB,
|
2020-08-11 11:54:09 +02:00
|
|
|
[SETTINGS.ENABLE_PUBLISH_PREVIEW]: true,
|
2019-09-17 20:49:03 +02:00
|
|
|
|
|
|
|
// UI
|
2020-11-20 14:21:31 +01:00
|
|
|
[SETTINGS.LANGUAGE]: null,
|
2020-10-15 19:56:55 +02:00
|
|
|
[SETTINGS.SEARCH_IN_LANGUAGE]: false,
|
2022-02-11 19:50:55 +01:00
|
|
|
[SETTINGS.THEME]: __('dark'),
|
|
|
|
[SETTINGS.THEMES]: [__('dark'), __('light')],
|
2020-11-20 14:21:31 +01:00
|
|
|
[SETTINGS.HOMEPAGE]: null,
|
2019-09-17 20:49:03 +02:00
|
|
|
[SETTINGS.HIDE_SPLASH_ANIMATION]: false,
|
|
|
|
[SETTINGS.HIDE_BALANCE]: false,
|
|
|
|
[SETTINGS.OS_NOTIFICATIONS_ENABLED]: true,
|
|
|
|
[SETTINGS.AUTOMATIC_DARK_MODE_ENABLED]: false,
|
2021-04-03 07:26:05 +02:00
|
|
|
[SETTINGS.CLOCK_24H]: false,
|
2020-08-21 17:49:13 +02:00
|
|
|
[SETTINGS.TILE_LAYOUT]: true,
|
2021-01-08 16:21:27 +01:00
|
|
|
[SETTINGS.VIDEO_THEATER_MODE]: false,
|
2021-01-14 14:16:04 +01:00
|
|
|
[SETTINGS.VIDEO_PLAYBACK_RATE]: 1,
|
2021-01-26 06:17:42 +01:00
|
|
|
[SETTINGS.DESKTOP_WINDOW_ZOOM]: 1,
|
2019-11-18 19:30:15 +01:00
|
|
|
|
2020-07-10 23:04:36 +02:00
|
|
|
[SETTINGS.DARK_MODE_TIMES]: {
|
2019-08-18 18:54:55 +02:00
|
|
|
from: { hour: '21', min: '00', formattedTime: '21:00' },
|
|
|
|
to: { hour: '8', min: '00', formattedTime: '8:00' },
|
2019-09-17 20:49:03 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// Purchasing
|
|
|
|
[SETTINGS.INSTANT_PURCHASE_ENABLED]: false,
|
|
|
|
[SETTINGS.INSTANT_PURCHASE_MAX]: {
|
|
|
|
currency: 'LBC',
|
|
|
|
amount: 0.1,
|
|
|
|
},
|
|
|
|
|
|
|
|
// Content
|
|
|
|
[SETTINGS.SHOW_MATURE]: false,
|
2021-09-02 22:05:32 +02:00
|
|
|
[SETTINGS.AUTOPLAY_MEDIA]: true,
|
2019-09-17 20:49:03 +02:00
|
|
|
[SETTINGS.FLOATING_PLAYER]: true,
|
|
|
|
[SETTINGS.AUTO_DOWNLOAD]: true,
|
2021-11-24 17:11:25 +01:00
|
|
|
[SETTINGS.HIDE_REPOSTS]: false,
|
2022-01-05 22:20:43 +01:00
|
|
|
[SETTINGS.HIDE_SCHEDULED_LIVESTREAMS]: false,
|
2022-03-17 01:23:16 +01:00
|
|
|
[SETTINGS.HIDE_REPOSTS]: false,
|
2019-11-18 19:30:15 +01:00
|
|
|
|
|
|
|
// OS
|
|
|
|
[SETTINGS.AUTO_LAUNCH]: true,
|
2020-08-13 18:57:00 +02:00
|
|
|
[SETTINGS.TO_TRAY_WHEN_CLOSED]: true,
|
2017-06-28 09:12:01 +02:00
|
|
|
},
|
|
|
|
};
|
2021-09-27 21:10:41 +02:00
|
|
|
defaultState.clientSettings[SETTINGS.AUTOPLAY_NEXT] = defaultState.clientSettings[SETTINGS.AUTOPLAY_MEDIA];
|
2017-05-17 23:52:45 +02:00
|
|
|
|
2020-07-10 23:04:36 +02:00
|
|
|
reducers[ACTIONS.REHYDRATE] = (state, action) => {
|
|
|
|
const { clientSettings } = state;
|
|
|
|
if (action && action.payload && action.payload.settings) {
|
|
|
|
const persistedSettings = action.payload && action.payload.settings;
|
|
|
|
const persistedClientSettings = persistedSettings.clientSettings;
|
|
|
|
const newClientSettings = { ...clientSettings, ...persistedClientSettings };
|
|
|
|
return Object.assign({}, state, { ...persistedSettings, clientSettings: newClientSettings });
|
|
|
|
}
|
|
|
|
return Object.assign({}, state, { clientSettings });
|
|
|
|
};
|
|
|
|
|
2021-07-19 18:52:29 +02:00
|
|
|
reducers[ACTIONS.FINDING_FFMPEG_STARTED] = (state) =>
|
2020-03-24 18:57:17 +01:00
|
|
|
Object.assign({}, state, {
|
|
|
|
findingFFmpeg: true,
|
|
|
|
});
|
|
|
|
|
2021-07-19 18:52:29 +02:00
|
|
|
reducers[ACTIONS.FINDING_FFMPEG_COMPLETED] = (state) =>
|
2020-03-24 18:57:17 +01:00
|
|
|
Object.assign({}, state, {
|
|
|
|
findingFFmpeg: false,
|
|
|
|
});
|
|
|
|
|
2021-10-17 10:36:14 +02:00
|
|
|
reducers[ACTIONS.DAEMON_SETTINGS_RECEIVED] = (state, action) =>
|
2017-12-28 00:48:11 +01:00
|
|
|
Object.assign({}, state, {
|
2017-06-06 23:19:12 +02:00
|
|
|
daemonSettings: action.data.settings,
|
|
|
|
});
|
2017-05-17 23:52:45 +02:00
|
|
|
|
2021-10-17 10:36:14 +02:00
|
|
|
reducers[ACTIONS.DAEMON_STATUS_RECEIVED] = (state, action) =>
|
2019-12-12 21:18:13 +01:00
|
|
|
Object.assign({}, state, {
|
|
|
|
daemonStatus: action.data.status,
|
|
|
|
});
|
|
|
|
|
2017-12-28 00:48:11 +01:00
|
|
|
reducers[ACTIONS.CLIENT_SETTING_CHANGED] = (state, action) => {
|
2017-06-28 09:12:01 +02:00
|
|
|
const { key, value } = action.data;
|
|
|
|
const clientSettings = Object.assign({}, state.clientSettings);
|
|
|
|
|
|
|
|
clientSettings[key] = value;
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
clientSettings,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-07-19 18:52:29 +02:00
|
|
|
reducers[ACTIONS.UPDATE_IS_NIGHT] = (state) => {
|
2020-07-10 23:04:36 +02:00
|
|
|
const { from, to } = state.clientSettings[SETTINGS.DARK_MODE_TIMES];
|
2019-08-16 16:57:15 +02:00
|
|
|
const momentNow = moment();
|
2019-08-18 18:54:55 +02:00
|
|
|
const startNightMoment = moment(from.formattedTime, 'HH:mm');
|
|
|
|
const endNightMoment = moment(to.formattedTime, 'HH:mm');
|
2019-08-16 16:57:15 +02:00
|
|
|
const isNight = !(momentNow.isAfter(endNightMoment) && momentNow.isBefore(startNightMoment));
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
isNight,
|
2018-01-14 10:14:15 +01:00
|
|
|
});
|
2019-08-16 16:57:15 +02:00
|
|
|
};
|
2018-01-14 10:14:15 +01:00
|
|
|
|
2019-11-08 21:51:42 +01:00
|
|
|
reducers[ACTIONS.DOWNLOAD_LANGUAGE_SUCCESS] = (state, action) => {
|
|
|
|
const { loadedLanguages } = state;
|
|
|
|
const { language } = action.data;
|
|
|
|
|
2019-12-06 14:58:17 +01:00
|
|
|
if (language && loadedLanguages && !loadedLanguages.includes(language)) {
|
2019-11-08 21:51:42 +01:00
|
|
|
return Object.assign({}, state, {
|
|
|
|
loadedLanguages: [...loadedLanguages, language],
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-10-17 10:36:14 +02:00
|
|
|
reducers[ACTIONS.SHARED_PREFERENCE_SET] = (state, action) => {
|
2019-12-11 21:09:27 +01:00
|
|
|
const { key, value } = action.data;
|
2019-12-12 21:18:13 +01:00
|
|
|
const sharedPreferences = Object.assign({}, state.sharedPreferences);
|
|
|
|
sharedPreferences[key] = value;
|
2019-12-11 21:09:27 +01:00
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
2019-12-12 21:18:13 +01:00
|
|
|
sharedPreferences,
|
2019-12-11 21:09:27 +01:00
|
|
|
});
|
2019-12-30 20:54:53 +01:00
|
|
|
};
|
2019-12-11 21:09:27 +01:00
|
|
|
|
2021-07-19 18:52:29 +02:00
|
|
|
reducers[ACTIONS.SYNC_CLIENT_SETTINGS] = (state) => {
|
2020-07-31 20:24:01 +02:00
|
|
|
const { clientSettings } = state;
|
|
|
|
const sharedPreferences = Object.assign({}, state.sharedPreferences);
|
|
|
|
const selectedClientSettings = getSubsetFromKeysArray(clientSettings, clientSyncKeys);
|
|
|
|
const newSharedPreferences = { ...sharedPreferences, ...selectedClientSettings };
|
|
|
|
return Object.assign({}, state, { sharedPreferences: newSharedPreferences });
|
|
|
|
};
|
|
|
|
|
2021-10-17 10:36:14 +02:00
|
|
|
reducers[ACTIONS.USER_STATE_POPULATE] = (state, action) => {
|
2020-09-11 20:35:50 +02:00
|
|
|
const { clientSettings: currentClientSettings } = state;
|
2019-12-12 21:18:13 +01:00
|
|
|
const { settings: sharedPreferences } = action.data;
|
2020-08-28 17:25:47 +02:00
|
|
|
const selectedSettings = sharedPreferences ? getSubsetFromKeysArray(sharedPreferences, clientSyncKeys) : {};
|
2020-09-11 20:35:50 +02:00
|
|
|
const mergedClientSettings = { ...currentClientSettings, ...selectedSettings };
|
2020-08-28 17:25:47 +02:00
|
|
|
const newSharedPreferences = sharedPreferences || {};
|
2021-07-25 14:52:45 +02:00
|
|
|
|
2020-09-09 19:37:55 +02:00
|
|
|
return Object.assign({}, state, {
|
|
|
|
sharedPreferences: newSharedPreferences,
|
|
|
|
clientSettings: mergedClientSettings,
|
|
|
|
});
|
2019-12-11 21:09:27 +01:00
|
|
|
};
|
|
|
|
|
2021-10-17 10:36:14 +02:00
|
|
|
reducers[ACTIONS.SAVE_CUSTOM_WALLET_SERVERS] = (state, action) => {
|
2019-12-30 20:54:53 +01:00
|
|
|
return Object.assign({}, state, { customWalletServers: action.data });
|
|
|
|
};
|
2019-12-11 21:09:27 +01:00
|
|
|
|
2017-05-17 23:52:45 +02:00
|
|
|
export default function reducer(state = defaultState, action) {
|
|
|
|
const handler = reducers[action.type];
|
|
|
|
if (handler) return handler(state, action);
|
|
|
|
return state;
|
|
|
|
}
|