From 8bffe1f28c79cde91855f6c702f159022e823961 Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Mon, 28 Oct 2019 10:37:13 -0300 Subject: [PATCH] [FIX] Invalid server version (#1319) --- app/lib/methods/getSettings.js | 15 +++++++++++++++ app/lib/rocketchat.js | 3 ++- app/sagas/selectServer.js | 17 ++++------------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/app/lib/methods/getSettings.js b/app/lib/methods/getSettings.js index 1dd8b7909..997e3c533 100644 --- a/app/lib/methods/getSettings.js +++ b/app/lib/methods/getSettings.js @@ -2,6 +2,7 @@ import { InteractionManager } from 'react-native'; import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord'; import { Q } from '@nozbe/watermelondb'; +import RocketChat from '../rocketchat'; import reduxStore from '../createStore'; import * as actions from '../../actions'; import settings from '../../constants/settings'; @@ -51,6 +52,20 @@ const serverInfoUpdate = async(serverInfo, iconSetting) => { }); }; +export async function setSettings() { + const db = database.active; + const settingsCollection = db.collections.get('settings'); + const settingsRecords = await settingsCollection.query().fetch(); + const parsed = Object.values(settingsRecords).map(item => ({ + _id: item.id, + valueAsString: item.valueAsString, + valueAsBoolean: item.valueAsBoolean, + valueAsNumber: item.valueAsNumber, + _updatedAt: item._updatedAt + })); + reduxStore.dispatch(actions.setAllSettings(RocketChat.parseSettings(parsed.slice(0, parsed.length)))); +} + export default async function() { try { const db = database.active; diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index 1040410c3..af1a4c146 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -27,7 +27,7 @@ import subscribeRoom from './methods/subscriptions/room'; import protectedFunction from './methods/helpers/protectedFunction'; import readMessages from './methods/readMessages'; -import getSettings from './methods/getSettings'; +import getSettings, { setSettings } from './methods/getSettings'; import getRooms from './methods/getRooms'; import getPermissions from './methods/getPermissions'; @@ -532,6 +532,7 @@ const RocketChat = { cancelUpload, isUploadActive, getSettings, + setSettings, getPermissions, getCustomEmojis, setCustomEmojis, diff --git a/app/sagas/selectServer.js b/app/sagas/selectServer.js index 83fdc2976..b997845e7 100644 --- a/app/sagas/selectServer.js +++ b/app/sagas/selectServer.js @@ -90,19 +90,10 @@ const handleSelectServer = function* handleSelectServer({ server, version, fetch yield put(actions.appStart('outside')); } - const db = database.active; - const serversCollection = db.collections.get('settings'); - const settingsRecords = yield serversCollection.query().fetch(); - const settings = Object.values(settingsRecords).map(item => ({ - _id: item.id, - valueAsString: item.valueAsString, - valueAsBoolean: item.valueAsBoolean, - valueAsNumber: item.valueAsNumber, - _updatedAt: item._updatedAt - })); - yield put(actions.setAllSettings(RocketChat.parseSettings(settings.slice(0, settings.length)))); - - yield RocketChat.setCustomEmojis(); + // We can't use yield here because fetch of Settings & Custom Emojis is slower + // and block the selectServerSuccess raising multiples errors + RocketChat.setSettings(); + RocketChat.setCustomEmojis(); let serverInfo; if (fetchVersion) {