[FIX] Clear settings on server change (#1967)
This commit is contained in:
parent
3d80f95923
commit
9f830c7f0a
|
@ -63,3 +63,4 @@ export const INVITE_LINKS = createRequestTypes('INVITE_LINKS', [
|
||||||
'CLEAR',
|
'CLEAR',
|
||||||
...defaultTypes
|
...defaultTypes
|
||||||
]);
|
]);
|
||||||
|
export const SETTINGS = createRequestTypes('SETTINGS', ['CLEAR', 'ADD']);
|
||||||
|
|
|
@ -34,13 +34,6 @@ export function setCurrentServer(server) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addSettings(settings) {
|
|
||||||
return {
|
|
||||||
type: types.ADD_SETTINGS,
|
|
||||||
payload: settings
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function login() {
|
export function login() {
|
||||||
return {
|
return {
|
||||||
type: 'LOGIN'
|
type: 'LOGIN'
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
import { SETTINGS } from './actionsTypes';
|
||||||
|
|
||||||
|
export function addSettings(settings) {
|
||||||
|
return {
|
||||||
|
type: SETTINGS.ADD,
|
||||||
|
payload: settings
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clearSettings() {
|
||||||
|
return {
|
||||||
|
type: SETTINGS.CLEAR
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
export const SET_CURRENT_SERVER = 'SET_CURRENT_SERVER';
|
export const SET_CURRENT_SERVER = 'SET_CURRENT_SERVER';
|
||||||
export const SET_CUSTOM_EMOJIS = 'SET_CUSTOM_EMOJIS';
|
export const SET_CUSTOM_EMOJIS = 'SET_CUSTOM_EMOJIS';
|
||||||
export const ADD_SETTINGS = 'ADD_SETTINGS';
|
export const ADD_SETTINGS = 'ADD_SETTINGS';
|
||||||
|
export const CLEAR_SETTINGS = 'CLEAR_SETTINGS';
|
||||||
|
|
|
@ -2,9 +2,9 @@ import { InteractionManager } from 'react-native';
|
||||||
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
|
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
|
||||||
import { Q } from '@nozbe/watermelondb';
|
import { Q } from '@nozbe/watermelondb';
|
||||||
|
|
||||||
|
import { addSettings, clearSettings } from '../../actions/settings';
|
||||||
import RocketChat from '../rocketchat';
|
import RocketChat from '../rocketchat';
|
||||||
import reduxStore from '../createStore';
|
import reduxStore from '../createStore';
|
||||||
import * as actions from '../../actions';
|
|
||||||
import settings from '../../constants/settings';
|
import settings from '../../constants/settings';
|
||||||
import log from '../../utils/log';
|
import log from '../../utils/log';
|
||||||
import database from '../database';
|
import database from '../database';
|
||||||
|
@ -58,7 +58,8 @@ export async function getLoginSettings({ server }) {
|
||||||
const result = await fetch(`${ server }/api/v1/settings.public?query={"_id":{"$in":${ settingsParams }}}`).then(response => response.json());
|
const result = await fetch(`${ server }/api/v1/settings.public?query={"_id":{"$in":${ settingsParams }}}`).then(response => response.json());
|
||||||
|
|
||||||
if (result.success && result.settings.length) {
|
if (result.success && result.settings.length) {
|
||||||
reduxStore.dispatch(actions.addSettings(this.parseSettings(this._prepareSettings(result.settings))));
|
reduxStore.dispatch(clearSettings());
|
||||||
|
reduxStore.dispatch(addSettings(this.parseSettings(this._prepareSettings(result.settings))));
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log(e);
|
log(e);
|
||||||
|
@ -77,7 +78,7 @@ export async function setSettings() {
|
||||||
valueAsArray: item.valueAsArray,
|
valueAsArray: item.valueAsArray,
|
||||||
_updatedAt: item._updatedAt
|
_updatedAt: item._updatedAt
|
||||||
}));
|
}));
|
||||||
reduxStore.dispatch(actions.addSettings(RocketChat.parseSettings(parsed.slice(0, parsed.length))));
|
reduxStore.dispatch(addSettings(RocketChat.parseSettings(parsed.slice(0, parsed.length))));
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function() {
|
export default async function() {
|
||||||
|
@ -94,7 +95,7 @@ export default async function() {
|
||||||
const filteredSettings = this._prepareSettings(data);
|
const filteredSettings = this._prepareSettings(data);
|
||||||
const filteredSettingsIds = filteredSettings.map(s => s._id);
|
const filteredSettingsIds = filteredSettings.map(s => s._id);
|
||||||
|
|
||||||
reduxStore.dispatch(actions.addSettings(this.parseSettings(filteredSettings)));
|
reduxStore.dispatch(addSettings(this.parseSettings(filteredSettings)));
|
||||||
InteractionManager.runAfterInteractions(async() => {
|
InteractionManager.runAfterInteractions(async() => {
|
||||||
// filter server info
|
// filter server info
|
||||||
const serverInfo = filteredSettings.filter(i1 => serverInfoKeys.includes(i1._id));
|
const serverInfo = filteredSettings.filter(i1 => serverInfoKeys.includes(i1._id));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { combineReducers } from 'redux';
|
import { combineReducers } from 'redux';
|
||||||
import settings from './reducers';
|
import settings from './settings';
|
||||||
import login from './login';
|
import login from './login';
|
||||||
import meteor from './connect';
|
import meteor from './connect';
|
||||||
import room from './room';
|
import room from './room';
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
export default {
|
|
||||||
server: null,
|
|
||||||
login: {},
|
|
||||||
settings: {}
|
|
||||||
};
|
|
|
@ -1,12 +0,0 @@
|
||||||
import * as types from '../constants/types';
|
|
||||||
import initialState from './initialState';
|
|
||||||
|
|
||||||
export default function settings(state = initialState.settings, action) {
|
|
||||||
if (action.type === types.ADD_SETTINGS) {
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
...action.payload
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return state;
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
import { combineReducers } from 'redux';
|
|
||||||
import * as reducers from './reducers';
|
|
||||||
import * as login from './login';
|
|
||||||
import * as connect from './connect';
|
|
||||||
|
|
||||||
const rootReducer = combineReducers({
|
|
||||||
...reducers, ...login, ...connect
|
|
||||||
});
|
|
||||||
|
|
||||||
export default rootReducer;
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
import { SETTINGS } from '../actions/actionsTypes';
|
||||||
|
|
||||||
|
const initialState = {};
|
||||||
|
|
||||||
|
export default (state = initialState, action) => {
|
||||||
|
switch (action.type) {
|
||||||
|
case SETTINGS.ADD:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
...action.payload
|
||||||
|
};
|
||||||
|
case SETTINGS.CLEAR:
|
||||||
|
return initialState;
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
};
|
|
@ -13,6 +13,7 @@ import {
|
||||||
serverFailure, selectServerRequest, selectServerSuccess, selectServerFailure
|
serverFailure, selectServerRequest, selectServerSuccess, selectServerFailure
|
||||||
} from '../actions/server';
|
} from '../actions/server';
|
||||||
import { setUser } from '../actions/login';
|
import { setUser } from '../actions/login';
|
||||||
|
import { clearSettings } from '../actions/settings';
|
||||||
import RocketChat from '../lib/rocketchat';
|
import RocketChat from '../lib/rocketchat';
|
||||||
import database from '../lib/database';
|
import database from '../lib/database';
|
||||||
import log, { logServerVersion } from '../utils/log';
|
import log, { logServerVersion } from '../utils/log';
|
||||||
|
@ -94,6 +95,8 @@ const handleSelectServer = function* handleSelectServer({ server, version, fetch
|
||||||
const basicAuth = yield RNUserDefaults.get(`${ BASIC_AUTH_KEY }-${ server }`);
|
const basicAuth = yield RNUserDefaults.get(`${ BASIC_AUTH_KEY }-${ server }`);
|
||||||
setBasicAuth(basicAuth);
|
setBasicAuth(basicAuth);
|
||||||
|
|
||||||
|
yield put(clearSettings());
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
yield RocketChat.connect({ server, user, logoutOnError: true });
|
yield RocketChat.connect({ server, user, logoutOnError: true });
|
||||||
yield put(setUser(user));
|
yield put(setUser(user));
|
||||||
|
|
Loading…
Reference in New Issue