[FIX] Invalid server version (#1319)

This commit is contained in:
Djorkaeff Alexandre 2019-10-28 10:37:13 -03:00 committed by Diego Mello
parent d52a7e00cc
commit 8bffe1f28c
3 changed files with 21 additions and 14 deletions

View File

@ -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;

View File

@ -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,

View File

@ -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) {