Unverified Commit cfab6428 authored by Djorkaeff Alexandre's avatar Djorkaeff Alexandre Committed by GitHub
Browse files

[FIX] LoginSignup blink services (#1809)


Co-authored-by: default avatarDiego Mello <diegolmello@gmail.com>
parent d1844ba1
......@@ -40,12 +40,6 @@ export function addSettings(settings) {
payload: settings
};
}
export function setAllSettings(settings) {
return {
type: types.SET_ALL_SETTINGS,
payload: settings
};
}
export function login() {
return {
......
export const SET_CURRENT_SERVER = 'SET_CURRENT_SERVER';
export const SET_ALL_SETTINGS = 'SET_ALL_SETTINGS';
export const SET_CUSTOM_EMOJIS = 'SET_CUSTOM_EMOJIS';
export const ADD_SETTINGS = 'ADD_SETTINGS';
......@@ -52,21 +52,17 @@ const serverInfoUpdate = async(serverInfo, iconSetting) => {
});
};
export function getSetting({ server, setting }) {
return new Promise(async(resolve, reject) => {
try {
const result = await fetch(`${ server }/api/v1/settings.public?query={"_id":{"$in":["${ setting }"]}}`).then(response => response.json());
export async function getLoginSettings({ server }) {
try {
const settingsParams = JSON.stringify(['Accounts_ShowFormLogin', 'Accounts_RegistrationForm']);
const result = await fetch(`${ server }/api/v1/settings.public?query={"_id":{"$in":${ settingsParams }}}`).then(response => response.json());
if (result.success && result.settings.length) {
const [{ value }] = result.settings;
return resolve(value);
}
} catch (e) {
log(e);
if (result.success && result.settings.length) {
reduxStore.dispatch(actions.addSettings(this.parseSettings(this._prepareSettings(result.settings))));
}
return reject();
});
} catch (e) {
log(e);
}
}
export async function setSettings() {
......@@ -81,7 +77,7 @@ export async function setSettings() {
valueAsArray: item.valueAsArray,
_updatedAt: item._updatedAt
}));
reduxStore.dispatch(actions.setAllSettings(RocketChat.parseSettings(parsed.slice(0, parsed.length))));
reduxStore.dispatch(actions.addSettings(RocketChat.parseSettings(parsed.slice(0, parsed.length))));
}
export default async function() {
......
......@@ -24,7 +24,7 @@ import subscribeRooms from './methods/subscriptions/rooms';
import protectedFunction from './methods/helpers/protectedFunction';
import readMessages from './methods/readMessages';
import getSettings, { getSetting, setSettings } from './methods/getSettings';
import getSettings, { getLoginSettings, setSettings } from './methods/getSettings';
import getRooms from './methods/getRooms';
import getPermissions from './methods/getPermissions';
......@@ -619,7 +619,7 @@ const RocketChat = {
cancelUpload,
isUploadActive,
getSettings,
getSetting,
getLoginSettings,
setSettings,
getPermissions,
getCustomEmojis,
......
......@@ -2,11 +2,6 @@ import * as types from '../constants/types';
import initialState from './initialState';
export default function settings(state = initialState.settings, action) {
if (action.type === types.SET_ALL_SETTINGS) {
return {
...action.payload
};
}
if (action.type === types.ADD_SETTINGS) {
return {
...state,
......
import {
put, take, takeLatest, fork, cancel, race
put, take, takeLatest, fork, cancel, race, select
} from 'redux-saga/effects';
import { Alert } from 'react-native';
import RNUserDefaults from 'rn-user-defaults';
......@@ -133,9 +133,12 @@ const handleServerRequest = function* handleServerRequest({ server, certificate
const serverInfo = yield getServerInfo({ server });
if (serverInfo) {
const showFormLogin = yield RocketChat.getSetting({ server, setting: 'Accounts_ShowFormLogin' });
const loginServicesLength = yield RocketChat.getLoginServices(server);
if (loginServicesLength === 0 && showFormLogin) {
yield RocketChat.getLoginSettings({ server });
const showFormLogin = yield select(state => state.settings.Accounts_ShowFormLogin);
if (!loginServicesLength && showFormLogin) {
Navigation.navigate('LoginView');
} else {
Navigation.navigate('LoginSignupView');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment