[CHORE] Change database location to Experimental Apps (#2483)

* change database location of experimental apps

* fix migration from older versions
This commit is contained in:
Djorkaeff Alexandre 2020-09-23 14:16:04 -03:00 committed by GitHub
parent e1c8b10765
commit 8ae489074e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 53 additions and 19 deletions

View File

@ -36,7 +36,7 @@ if (__DEV__ && isIOS) {
export const getDatabase = (database = '') => {
const path = database.replace(/(^\w+:|^)\/\//, '').replace(/\//g, '.');
const dbName = `${ appGroupPath }${ path }.db`;
const dbName = `${ appGroupPath }${ path }-experimental.db`;
const adapter = new SQLiteAdapter({
dbName,
@ -68,7 +68,7 @@ class DB {
databases = {
serversDB: new Database({
adapter: new SQLiteAdapter({
dbName: `${ appGroupPath }default.db`,
dbName: `${ appGroupPath }default-experimental.db`,
schema: serversSchema,
migrations: serversMigrations
}),
@ -95,7 +95,7 @@ class DB {
setShareDB(database = '') {
const path = database.replace(/(^\w+:|^)\/\//, '').replace(/\//g, '.');
const dbName = `${ appGroupPath }${ path }.db`;
const dbName = `${ appGroupPath }${ path }-experimental.db`;
const adapter = new SQLiteAdapter({
dbName,

View File

@ -58,7 +58,7 @@ class Encryption {
get establishing() {
const { banner } = store.getState().encryption;
// If the password was not inserted yet
if (banner === E2E_BANNER_TYPE.REQUEST_PASSWORD) {
if (!banner || banner === E2E_BANNER_TYPE.REQUEST_PASSWORD) {
// We can't decrypt/encrypt, so, reject this try
return Promise.reject();
}

View File

@ -13,8 +13,13 @@ export async function setEnterpriseModules() {
const { server: serverId } = reduxStore.getState().server;
const serversDB = database.servers;
const serversCollection = serversDB.collections.get('servers');
const server = await serversCollection.find(serverId);
if (server.enterpriseModules) {
let server;
try {
server = await serversCollection.find(serverId);
} catch {
// Server not found
}
if (server?.enterpriseModules) {
reduxStore.dispatch(setEnterpriseModulesAction(server.enterpriseModules.split(',')));
return;
}

View File

@ -150,7 +150,11 @@ export default async function() {
// filter server info
const serverInfo = filteredSettings.filter(i1 => serverInfoKeys.includes(i1._id));
const iconSetting = data.find(item => item._id === 'Assets_favicon_512');
await serverInfoUpdate(serverInfo, iconSetting);
try {
await serverInfoUpdate(serverInfo, iconSetting);
} catch {
// Server not found
}
await db.action(async() => {
const settingsCollection = db.collections.get('settings');

View File

@ -20,19 +20,26 @@ import I18n from '../i18n';
import log from '../utils/log';
const getServer = state => state.share.server || state.server.server;
const getE2eEnable = state => state.settings.E2E_Enable;
const handleEncryptionInit = function* handleEncryptionInit() {
try {
const server = yield select(getServer);
const user = yield select(getUserSelector);
const E2E_Enable = yield select(getE2eEnable);
// Fetch server info to check E2E enable
const serversDB = database.servers;
const serversCollection = serversDB.collections.get('servers');
const serverInfo = yield serversCollection.find(server);
let serverInfo;
try {
serverInfo = yield serversCollection.find(server);
} catch {
// Server not found
}
// If E2E is disabled on server, skip
if (!serverInfo?.E2E_Enable) {
if (!serverInfo?.E2E_Enable && !E2E_Enable) {
return;
}

View File

@ -40,8 +40,13 @@ const restore = function* restore() {
const serversDB = database.servers;
const serverCollections = serversDB.collections.get('servers');
yield localAuthenticate(server);
const serverObj = yield serverCollections.find(server);
let serverObj;
try {
yield localAuthenticate(server);
serverObj = yield serverCollections.find(server);
} catch {
// Server not found
}
yield put(selectServerRequest(server, serverObj && serverObj.version));
}

View File

@ -16,13 +16,17 @@ import protectedFunction from '../lib/methods/helpers/protectedFunction';
const updateRooms = function* updateRooms({ server, newRoomsUpdatedAt }) {
const serversDB = database.servers;
const serversCollection = serversDB.collections.get('servers');
const serverRecord = yield serversCollection.find(server);
try {
const serverRecord = yield serversCollection.find(server);
return serversDB.action(async() => {
await serverRecord.update((record) => {
record.roomsUpdatedAt = newRoomsUpdatedAt;
return serversDB.action(async() => {
await serverRecord.update((record) => {
record.roomsUpdatedAt = newRoomsUpdatedAt;
});
});
});
} catch {
// Server not found
}
};
const handleRoomsRequest = function* handleRoomsRequest({ params }) {
@ -36,8 +40,12 @@ const handleRoomsRequest = function* handleRoomsRequest({ params }) {
yield put(roomsRefresh());
} else {
const serversCollection = serversDB.collections.get('servers');
const serverRecord = yield serversCollection.find(server);
({ roomsUpdatedAt } = serverRecord);
try {
const serverRecord = yield serversCollection.find(server);
({ roomsUpdatedAt } = serverRecord);
} catch {
// Server not found
}
}
const [subscriptionsResult, roomsResult] = yield RocketChat.getRooms(roomsUpdatedAt);
const { subscriptions } = yield mergeSubscriptionsRooms(subscriptionsResult, roomsResult);

View File

@ -77,6 +77,7 @@ const handleSelectServer = function* handleSelectServer({ server, version, fetch
let user = null;
if (userId) {
try {
// search credentials on database
const userRecord = yield userCollections.find(userId);
user = {
id: userRecord.id,
@ -89,7 +90,11 @@ const handleSelectServer = function* handleSelectServer({ server, version, fetch
roles: userRecord.roles
};
} catch {
// Do nothing
// search credentials on shared credentials (Experimental/Official)
const token = yield UserPreferences.getStringAsync(`${ RocketChat.TOKEN_KEY }-${ userId }`);
if (token) {
user = { token };
}
}
}