Commit 62db1ec9 authored by Djorkaeff Alexandre's avatar Djorkaeff Alexandre Committed by Diego Mello
Browse files

[CHORE] Update to new server response (#1509)

parent 1aadb883
......@@ -4,6 +4,7 @@ import {
import { Alert } from 'react-native';
import RNUserDefaults from 'rn-user-defaults';
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
import semver from 'semver';
import Navigation from '../lib/Navigation';
import { SERVER } from '../actions/actionsTypes';
......@@ -35,18 +36,20 @@ const getServerInfo = function* getServerInfo({ server, raiseError = true }) {
return;
}
const validVersion = semver.coerce(serverInfo.version);
const serversDB = database.servers;
const serversCollection = serversDB.collections.get('servers');
yield serversDB.action(async() => {
try {
const serverRecord = await serversCollection.find(server);
await serverRecord.update((record) => {
record.version = serverInfo.version;
record.version = validVersion;
});
} catch (e) {
await serversCollection.create((record) => {
record._raw = sanitizedRaw({ id: server }, serversCollection.schema);
record.version = serverInfo.version;
record.version = validVersion;
});
}
});
......
Supports Markdown
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