mirror of
https://github.com/mattermost/mattermost-mobile.git
synced 2026-11-05 18:38:54 +00:00
* consider all error paths when wiping server artifacts * log events related to ephemeral mode to keep an audit log server side * adds playbook run delete count to cleanup audit events * sends signature as proof for auditing wipe events * fixes some missed data in audit events * throw and log errors while enqueuing audit events * report exact deleted count on audit event * test terminate session prunes audit event queue in all cases * assert on queue lenght in tests * fetch count inside write transaction to return accurate value * remove delete count expectations from tests since unsafe where clauses are not supported by loki
93 lines
3.4 KiB
TypeScript
93 lines
3.4 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {flushOrphanedAuditQueues} from '@actions/remote/ephemeral_mode';
|
|
import {CallsManager} from '@calls/calls_manager';
|
|
import DatabaseManager from '@database/manager';
|
|
import CallsNative from '@init/calls_native';
|
|
import {getAllServerCredentials} from '@init/credentials';
|
|
import ManagedApp from '@init/managed_app';
|
|
import PushNotifications from '@init/push_notifications';
|
|
import EphemeralModeManager from '@managers/ephemeral_mode_manager';
|
|
import GlobalEventHandler from '@managers/global_event_handler';
|
|
import NetworkManager from '@managers/network_manager';
|
|
import SecurityManager from '@managers/security_manager';
|
|
import SessionAttributesManager from '@managers/session_attributes_manager';
|
|
import SessionManager from '@managers/session_manager';
|
|
import WebsocketManager from '@managers/websocket_manager';
|
|
import {queryAllActiveServers} from '@queries/app/servers';
|
|
import EphemeralStore from '@store/ephemeral_store';
|
|
import {NavigationStore} from '@store/navigation_store';
|
|
|
|
// Controls whether the main initialization (database, etc...) is done, either on app launch
|
|
// or on the Share Extension, for example.
|
|
let baseAppInitialized = false;
|
|
let serverCredentials: ServerCredential[] = [];
|
|
|
|
// Fallback Polyfill for Promise.allSettle
|
|
Promise.allSettled = Promise.allSettled || (<T>(promises: Array<Promise<T>>) => Promise.all(
|
|
promises.map((p) => p.
|
|
then((value) => ({
|
|
status: 'fulfilled',
|
|
value,
|
|
})).
|
|
catch((reason) => ({
|
|
status: 'rejected',
|
|
reason,
|
|
})),
|
|
),
|
|
));
|
|
|
|
export async function initialize() {
|
|
if (!baseAppInitialized) {
|
|
baseAppInitialized = true;
|
|
try {
|
|
await DatabaseManager.initAppDatabase();
|
|
|
|
// Keystore entries with no matching active DB row are skipped (accepted vs listing every service).
|
|
const activeUrls = (await queryAllActiveServers()?.fetch() ?? []).map((s) => s.url);
|
|
serverCredentials = await getAllServerCredentials(activeUrls);
|
|
|
|
await DatabaseManager.initServerDatabases(serverCredentials.map((c) => c.serverUrl));
|
|
await NetworkManager.init(serverCredentials);
|
|
|
|
flushOrphanedAuditQueues(serverCredentials);
|
|
|
|
// EphemeralModeManager init runs before WS init so any pending wipes
|
|
// complete before WebSocket clients start populating server databases.
|
|
await EphemeralModeManager.init(serverCredentials);
|
|
await WebsocketManager.init(serverCredentials);
|
|
} catch (error) {
|
|
baseAppInitialized = false;
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
NavigationStore.reset();
|
|
EphemeralStore.setCurrentThreadId('');
|
|
EphemeralStore.setProcessingNotification('');
|
|
|
|
await SecurityManager.init();
|
|
|
|
await SessionAttributesManager.syncStaticValues();
|
|
|
|
GlobalEventHandler.init();
|
|
ManagedApp.init();
|
|
SessionManager.init();
|
|
CallsManager.initialize();
|
|
CallsNative.init();
|
|
|
|
PushNotifications.init(serverCredentials.length > 0);
|
|
}
|
|
|
|
export function cleanup() {
|
|
ManagedApp.cleanup();
|
|
GlobalEventHandler.cleanup();
|
|
SecurityManager.cleanup();
|
|
SessionManager.cleanup();
|
|
CallsManager.cleanup();
|
|
CallsNative.cleanup();
|
|
PushNotifications.cleanup();
|
|
EphemeralModeManager.cleanup();
|
|
}
|