move appStartup stuff todo on start

pull/1576/head
Audric Ackermann 4 years ago
parent 1720b6b627
commit 75cc39e9e7
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { Dispatch, useEffect, useState } from 'react';
import { SessionIconButton, SessionIconSize, SessionIconType } from './icon';
import { Avatar, AvatarSize } from '../Avatar';
import { darkTheme, lightTheme } from '../../state/ducks/SessionTheme';
@ -31,7 +31,7 @@ import { showLeftPaneSection } from '../../state/ducks/section';
import { cleanUpOldDecryptedMedias } from '../../session/crypto/DecryptedAttachmentsManager';
import { OpenGroupManagerV2 } from '../../opengroup/opengroupV2/OpenGroupManagerV2';
import { loadDefaultRoomsIfNeeded } from '../../opengroup/opengroupV2/ApiUtil';
import { loadDefaultRooms } from '../../opengroup/opengroupV2/ApiUtil';
// tslint:disable-next-line: no-import-side-effect no-submodule-imports
export enum SectionType {
@ -130,6 +130,49 @@ const showResetSessionIDDialogIfNeeded = async () => {
const cleanUpMediasInterval = MINUTES * 30;
/**
* This function is called only once: on app startup with a logged in user
*/
const doAppStartUp = (dispatch: Dispatch<any>) => {
if (window.lokiFeatureFlags.useOnionRequests || window.lokiFeatureFlags.useFileOnionRequests) {
// Initialize paths for onion requests
void OnionPaths.getInstance().buildNewOnionPaths();
}
// init the messageQueue. In the constructor, we had all not send messages
// this call does nothing except calling the constructor, which will continue sending message in the pipeline
void getMessageQueue().processAllPending();
const theme = window.Events.getThemeSetting();
window.setTheme(theme);
const newThemeObject = theme === 'dark' ? darkTheme : lightTheme;
dispatch(applyTheme(newThemeObject));
void showResetSessionIDDialogIfNeeded();
// remove existing prekeys, sign prekeys and sessions
void clearSessionsAndPreKeys();
// we consider people had the time to upgrade, so remove this id from the db
// it was used to display a dialog when we added the light mode auto-enabled
void removeItemById('hasSeenLightModeDialog');
// Do this only if we created a new Session ID, or if we already received the initial configuration message
const syncConfiguration = async () => {
const didWeHandleAConfigurationMessageAlready =
(await getItemById(hasSyncedInitialConfigurationItem))?.value || false;
if (didWeHandleAConfigurationMessageAlready) {
await syncConfigurationIfNeeded();
}
};
void generateAttachmentKeyIfEmpty();
// trigger a sync message if needed for our other devices
void OpenGroupManagerV2.getInstance().startPolling();
void syncConfiguration();
void loadDefaultRooms();
};
/**
* ActionsPanel is the far left banner (not the left pane).
* The panel with buttons to switch between the message/contact/settings/theme views
@ -143,43 +186,7 @@ export const ActionsPanel = () => {
// this maxi useEffect is called only once: when the component is mounted.
// For the action panel, it means this is called only one per app start/with a user loggedin
useEffect(() => {
if (window.lokiFeatureFlags.useOnionRequests || window.lokiFeatureFlags.useFileOnionRequests) {
// Initialize paths for onion requests
void OnionPaths.getInstance().buildNewOnionPaths();
}
// init the messageQueue. In the constructor, we had all not send messages
// this call does nothing except calling the constructor, which will continue sending message in the pipeline
void getMessageQueue().processAllPending();
const theme = window.Events.getThemeSetting();
window.setTheme(theme);
const newThemeObject = theme === 'dark' ? darkTheme : lightTheme;
dispatch(applyTheme(newThemeObject));
void showResetSessionIDDialogIfNeeded();
// remove existing prekeys, sign prekeys and sessions
void clearSessionsAndPreKeys();
// we consider people had the time to upgrade, so remove this id from the db
// it was used to display a dialog when we added the light mode auto-enabled
void removeItemById('hasSeenLightModeDialog');
// Do this only if we created a new Session ID, or if we already received the initial configuration message
const syncConfiguration = async () => {
const didWeHandleAConfigurationMessageAlready =
(await getItemById(hasSyncedInitialConfigurationItem))?.value || false;
if (didWeHandleAConfigurationMessageAlready) {
await syncConfigurationIfNeeded();
}
};
void generateAttachmentKeyIfEmpty();
// trigger a sync message if needed for our other devices
void OpenGroupManagerV2.getInstance().startPolling();
void syncConfiguration();
void loadDefaultRoomsIfNeeded();
void doAppStartUp(dispatch);
}, []);
// wait for cleanUpMediasInterval and then start cleaning up medias

@ -133,7 +133,7 @@ const loadDefaultRoomsSingle = () =>
};
});
} catch (e) {
window.log.warn('loadDefaultRoomsIfNeeded failed', e);
window.log.warn('loadDefaultRoomloadDefaultRoomssIfNeeded failed', e);
}
return [];
}
@ -145,7 +145,7 @@ const loadDefaultRoomsSingle = () =>
* Load to the cache all the details of the room of the default opengroupv2 server
* This call will only run once at a time.
*/
export const loadDefaultRoomsIfNeeded = async () => {
export const loadDefaultRooms = async () => {
// FIXME audric do the UI and refresh this list from time to time
const allRooms: Array<OpenGroupV2InfoJoinable> = await loadDefaultRoomsSingle();
if (allRooms !== undefined) {

Loading…
Cancel
Save