[CHORE] Change database location to Experimental Apps (#2483)
* change database location of experimental apps * fix migration from older versions
This commit is contained in:
parent
e1c8b10765
commit
8ae489074e
|
@ -36,7 +36,7 @@ if (__DEV__ && isIOS) {
|
||||||
|
|
||||||
export const getDatabase = (database = '') => {
|
export const getDatabase = (database = '') => {
|
||||||
const path = database.replace(/(^\w+:|^)\/\//, '').replace(/\//g, '.');
|
const path = database.replace(/(^\w+:|^)\/\//, '').replace(/\//g, '.');
|
||||||
const dbName = `${ appGroupPath }${ path }.db`;
|
const dbName = `${ appGroupPath }${ path }-experimental.db`;
|
||||||
|
|
||||||
const adapter = new SQLiteAdapter({
|
const adapter = new SQLiteAdapter({
|
||||||
dbName,
|
dbName,
|
||||||
|
@ -68,7 +68,7 @@ class DB {
|
||||||
databases = {
|
databases = {
|
||||||
serversDB: new Database({
|
serversDB: new Database({
|
||||||
adapter: new SQLiteAdapter({
|
adapter: new SQLiteAdapter({
|
||||||
dbName: `${ appGroupPath }default.db`,
|
dbName: `${ appGroupPath }default-experimental.db`,
|
||||||
schema: serversSchema,
|
schema: serversSchema,
|
||||||
migrations: serversMigrations
|
migrations: serversMigrations
|
||||||
}),
|
}),
|
||||||
|
@ -95,7 +95,7 @@ class DB {
|
||||||
|
|
||||||
setShareDB(database = '') {
|
setShareDB(database = '') {
|
||||||
const path = database.replace(/(^\w+:|^)\/\//, '').replace(/\//g, '.');
|
const path = database.replace(/(^\w+:|^)\/\//, '').replace(/\//g, '.');
|
||||||
const dbName = `${ appGroupPath }${ path }.db`;
|
const dbName = `${ appGroupPath }${ path }-experimental.db`;
|
||||||
|
|
||||||
const adapter = new SQLiteAdapter({
|
const adapter = new SQLiteAdapter({
|
||||||
dbName,
|
dbName,
|
||||||
|
|
|
@ -58,7 +58,7 @@ class Encryption {
|
||||||
get establishing() {
|
get establishing() {
|
||||||
const { banner } = store.getState().encryption;
|
const { banner } = store.getState().encryption;
|
||||||
// If the password was not inserted yet
|
// 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
|
// We can't decrypt/encrypt, so, reject this try
|
||||||
return Promise.reject();
|
return Promise.reject();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,13 @@ export async function setEnterpriseModules() {
|
||||||
const { server: serverId } = reduxStore.getState().server;
|
const { server: serverId } = reduxStore.getState().server;
|
||||||
const serversDB = database.servers;
|
const serversDB = database.servers;
|
||||||
const serversCollection = serversDB.collections.get('servers');
|
const serversCollection = serversDB.collections.get('servers');
|
||||||
const server = await serversCollection.find(serverId);
|
let server;
|
||||||
if (server.enterpriseModules) {
|
try {
|
||||||
|
server = await serversCollection.find(serverId);
|
||||||
|
} catch {
|
||||||
|
// Server not found
|
||||||
|
}
|
||||||
|
if (server?.enterpriseModules) {
|
||||||
reduxStore.dispatch(setEnterpriseModulesAction(server.enterpriseModules.split(',')));
|
reduxStore.dispatch(setEnterpriseModulesAction(server.enterpriseModules.split(',')));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,7 +150,11 @@ export default async function() {
|
||||||
// filter server info
|
// filter server info
|
||||||
const serverInfo = filteredSettings.filter(i1 => serverInfoKeys.includes(i1._id));
|
const serverInfo = filteredSettings.filter(i1 => serverInfoKeys.includes(i1._id));
|
||||||
const iconSetting = data.find(item => item._id === 'Assets_favicon_512');
|
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() => {
|
await db.action(async() => {
|
||||||
const settingsCollection = db.collections.get('settings');
|
const settingsCollection = db.collections.get('settings');
|
||||||
|
|
|
@ -20,19 +20,26 @@ import I18n from '../i18n';
|
||||||
import log from '../utils/log';
|
import log from '../utils/log';
|
||||||
|
|
||||||
const getServer = state => state.share.server || state.server.server;
|
const getServer = state => state.share.server || state.server.server;
|
||||||
|
const getE2eEnable = state => state.settings.E2E_Enable;
|
||||||
|
|
||||||
const handleEncryptionInit = function* handleEncryptionInit() {
|
const handleEncryptionInit = function* handleEncryptionInit() {
|
||||||
try {
|
try {
|
||||||
const server = yield select(getServer);
|
const server = yield select(getServer);
|
||||||
const user = yield select(getUserSelector);
|
const user = yield select(getUserSelector);
|
||||||
|
const E2E_Enable = yield select(getE2eEnable);
|
||||||
|
|
||||||
// Fetch server info to check E2E enable
|
// Fetch server info to check E2E enable
|
||||||
const serversDB = database.servers;
|
const serversDB = database.servers;
|
||||||
const serversCollection = serversDB.collections.get('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 E2E is disabled on server, skip
|
||||||
if (!serverInfo?.E2E_Enable) {
|
if (!serverInfo?.E2E_Enable && !E2E_Enable) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,13 @@ const restore = function* restore() {
|
||||||
const serversDB = database.servers;
|
const serversDB = database.servers;
|
||||||
const serverCollections = serversDB.collections.get('servers');
|
const serverCollections = serversDB.collections.get('servers');
|
||||||
|
|
||||||
yield localAuthenticate(server);
|
let serverObj;
|
||||||
const serverObj = yield serverCollections.find(server);
|
try {
|
||||||
|
yield localAuthenticate(server);
|
||||||
|
serverObj = yield serverCollections.find(server);
|
||||||
|
} catch {
|
||||||
|
// Server not found
|
||||||
|
}
|
||||||
yield put(selectServerRequest(server, serverObj && serverObj.version));
|
yield put(selectServerRequest(server, serverObj && serverObj.version));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,13 +16,17 @@ import protectedFunction from '../lib/methods/helpers/protectedFunction';
|
||||||
const updateRooms = function* updateRooms({ server, newRoomsUpdatedAt }) {
|
const updateRooms = function* updateRooms({ server, newRoomsUpdatedAt }) {
|
||||||
const serversDB = database.servers;
|
const serversDB = database.servers;
|
||||||
const serversCollection = serversDB.collections.get('servers');
|
const serversCollection = serversDB.collections.get('servers');
|
||||||
const serverRecord = yield serversCollection.find(server);
|
try {
|
||||||
|
const serverRecord = yield serversCollection.find(server);
|
||||||
|
|
||||||
return serversDB.action(async() => {
|
return serversDB.action(async() => {
|
||||||
await serverRecord.update((record) => {
|
await serverRecord.update((record) => {
|
||||||
record.roomsUpdatedAt = newRoomsUpdatedAt;
|
record.roomsUpdatedAt = newRoomsUpdatedAt;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
} catch {
|
||||||
|
// Server not found
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRoomsRequest = function* handleRoomsRequest({ params }) {
|
const handleRoomsRequest = function* handleRoomsRequest({ params }) {
|
||||||
|
@ -36,8 +40,12 @@ const handleRoomsRequest = function* handleRoomsRequest({ params }) {
|
||||||
yield put(roomsRefresh());
|
yield put(roomsRefresh());
|
||||||
} else {
|
} else {
|
||||||
const serversCollection = serversDB.collections.get('servers');
|
const serversCollection = serversDB.collections.get('servers');
|
||||||
const serverRecord = yield serversCollection.find(server);
|
try {
|
||||||
({ roomsUpdatedAt } = serverRecord);
|
const serverRecord = yield serversCollection.find(server);
|
||||||
|
({ roomsUpdatedAt } = serverRecord);
|
||||||
|
} catch {
|
||||||
|
// Server not found
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const [subscriptionsResult, roomsResult] = yield RocketChat.getRooms(roomsUpdatedAt);
|
const [subscriptionsResult, roomsResult] = yield RocketChat.getRooms(roomsUpdatedAt);
|
||||||
const { subscriptions } = yield mergeSubscriptionsRooms(subscriptionsResult, roomsResult);
|
const { subscriptions } = yield mergeSubscriptionsRooms(subscriptionsResult, roomsResult);
|
||||||
|
|
|
@ -77,6 +77,7 @@ const handleSelectServer = function* handleSelectServer({ server, version, fetch
|
||||||
let user = null;
|
let user = null;
|
||||||
if (userId) {
|
if (userId) {
|
||||||
try {
|
try {
|
||||||
|
// search credentials on database
|
||||||
const userRecord = yield userCollections.find(userId);
|
const userRecord = yield userCollections.find(userId);
|
||||||
user = {
|
user = {
|
||||||
id: userRecord.id,
|
id: userRecord.id,
|
||||||
|
@ -89,7 +90,11 @@ const handleSelectServer = function* handleSelectServer({ server, version, fetch
|
||||||
roles: userRecord.roles
|
roles: userRecord.roles
|
||||||
};
|
};
|
||||||
} catch {
|
} catch {
|
||||||
// Do nothing
|
// search credentials on shared credentials (Experimental/Official)
|
||||||
|
const token = yield UserPreferences.getStringAsync(`${ RocketChat.TOKEN_KEY }-${ userId }`);
|
||||||
|
if (token) {
|
||||||
|
user = { token };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue