forked from Ivasoft/mattermost-mobile
* Only call app entry on websocket reconnect * Handle notification on its own entry and run app entry on websocket initialization * Fix notification entry issues * Fix login entry and add retry on entry failure * feedback review * Put back handleEntryAfterLoadNavigation before the batching --------- Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
57 lines
1.9 KiB
TypeScript
57 lines
1.9 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {setLastServerVersionCheck} from '@actions/local/systems';
|
|
import {fetchConfigAndLicense} from '@actions/remote/systems';
|
|
import DatabaseManager from '@database/manager';
|
|
import WebsocketManager from '@managers/websocket_manager';
|
|
import {prepareCommonSystemValues} from '@queries/servers/system';
|
|
import {deleteV1Data} from '@utils/file';
|
|
|
|
import {verifyPushProxy} from './common';
|
|
|
|
export async function appEntry(serverUrl: string, since = 0) {
|
|
const operator = DatabaseManager.serverDatabases[serverUrl]?.operator;
|
|
if (!operator) {
|
|
return {error: `${serverUrl} database not found`};
|
|
}
|
|
|
|
if (!since) {
|
|
if (Object.keys(DatabaseManager.serverDatabases).length === 1) {
|
|
await setLastServerVersionCheck(serverUrl, true);
|
|
}
|
|
}
|
|
|
|
// clear lastUnreadChannelId
|
|
const removeLastUnreadChannelId = await prepareCommonSystemValues(operator, {lastUnreadChannelId: ''});
|
|
if (removeLastUnreadChannelId) {
|
|
await operator.batchRecords(removeLastUnreadChannelId, 'appEntry - removeLastUnreadChannelId');
|
|
}
|
|
|
|
WebsocketManager.openAll();
|
|
|
|
verifyPushProxy(serverUrl);
|
|
|
|
return {};
|
|
}
|
|
|
|
export async function upgradeEntry(serverUrl: string) {
|
|
const dt = Date.now();
|
|
|
|
try {
|
|
const configAndLicense = await fetchConfigAndLicense(serverUrl, false);
|
|
const entryData = await appEntry(serverUrl, 0);
|
|
const error = configAndLicense.error || entryData.error;
|
|
|
|
if (!error) {
|
|
await DatabaseManager.updateServerIdentifier(serverUrl, configAndLicense.config!.DiagnosticId);
|
|
await DatabaseManager.setActiveServerDatabase(serverUrl);
|
|
deleteV1Data();
|
|
}
|
|
|
|
return {error, time: Date.now() - dt};
|
|
} catch (e) {
|
|
return {error: e, time: Date.now() - dt};
|
|
}
|
|
}
|