2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
2021-06-17 21:15:09 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
2024-03-13 20:44:13 +00:00
|
|
|
import React, { memo } from 'react';
|
2024-01-29 20:09:54 +00:00
|
|
|
import { useSelector } from 'react-redux';
|
2023-08-29 00:41:32 +00:00
|
|
|
import type { VerificationTransport } from '../../types/VerificationTransport';
|
2024-07-22 18:16:33 +00:00
|
|
|
import { DataWriter } from '../../sql/Client';
|
2021-08-31 20:58:39 +00:00
|
|
|
import { App } from '../../components/App';
|
2023-04-20 21:23:19 +00:00
|
|
|
import OS from '../../util/os/osMain';
|
2024-07-15 21:05:09 +00:00
|
|
|
import { getConversation } from '../../util/getConversation';
|
|
|
|
import { getChallengeURL } from '../../challenge';
|
|
|
|
import { writeProfile } from '../../services/writeProfile';
|
2023-08-29 00:41:32 +00:00
|
|
|
import { strictAssert } from '../../util/assert';
|
2021-06-17 21:15:09 +00:00
|
|
|
import { SmartCallManager } from './CallManager';
|
|
|
|
import { SmartGlobalModalContainer } from './GlobalModalContainer';
|
2022-12-10 02:02:22 +00:00
|
|
|
import { SmartLightbox } from './Lightbox';
|
2022-07-06 19:06:20 +00:00
|
|
|
import { SmartStoryViewer } from './StoryViewer';
|
2022-06-08 22:00:32 +00:00
|
|
|
import {
|
|
|
|
getIsMainWindowMaximized,
|
|
|
|
getIsMainWindowFullScreen,
|
2024-03-19 17:12:32 +00:00
|
|
|
getTheme,
|
2022-06-08 22:00:32 +00:00
|
|
|
} from '../selectors/user';
|
2024-03-19 17:12:32 +00:00
|
|
|
import { hasSelectedStoryData as getHasSelectedStoryData } from '../selectors/stories';
|
2024-01-29 20:09:54 +00:00
|
|
|
import { useAppActions } from '../ducks/app';
|
|
|
|
import { useConversationsActions } from '../ducks/conversations';
|
|
|
|
import { useStoriesActions } from '../ducks/stories';
|
2022-07-29 00:10:07 +00:00
|
|
|
import { ErrorBoundary } from '../../components/ErrorBoundary';
|
2022-10-17 16:58:49 +00:00
|
|
|
import { ModalContainer } from '../../components/ModalContainer';
|
2023-01-02 21:34:41 +00:00
|
|
|
import { SmartInbox } from './Inbox';
|
2024-08-27 21:00:41 +00:00
|
|
|
import { getApp } from '../selectors/app';
|
2023-01-02 21:34:41 +00:00
|
|
|
|
|
|
|
function renderInbox(): JSX.Element {
|
|
|
|
return <SmartInbox />;
|
|
|
|
}
|
2021-06-17 21:15:09 +00:00
|
|
|
|
2024-03-19 17:12:32 +00:00
|
|
|
function renderCallManager(): JSX.Element {
|
|
|
|
return (
|
|
|
|
<ModalContainer className="module-calling__modal-container">
|
|
|
|
<SmartCallManager />
|
|
|
|
</ModalContainer>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderGlobalModalContainer(): JSX.Element {
|
|
|
|
return <SmartGlobalModalContainer />;
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderLightbox(): JSX.Element {
|
|
|
|
return <SmartLightbox />;
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderStoryViewer(closeView: () => unknown): JSX.Element {
|
|
|
|
return (
|
|
|
|
<ErrorBoundary name="App/renderStoryViewer" closeView={closeView}>
|
|
|
|
<SmartStoryViewer />
|
|
|
|
</ErrorBoundary>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-07-15 21:05:09 +00:00
|
|
|
async function getCaptchaToken(): Promise<string> {
|
|
|
|
const url = getChallengeURL('registration');
|
|
|
|
document.location.href = url;
|
|
|
|
if (!window.Signal.challengeHandler) {
|
|
|
|
throw new Error('Captcha handler is not ready!');
|
|
|
|
}
|
|
|
|
return window.Signal.challengeHandler.requestCaptcha({
|
|
|
|
reason: 'standalone registration',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-03-19 17:12:32 +00:00
|
|
|
function requestVerification(
|
|
|
|
number: string,
|
|
|
|
captcha: string,
|
|
|
|
transport: VerificationTransport
|
|
|
|
): Promise<{ sessionId: string }> {
|
|
|
|
const { server } = window.textsecure;
|
|
|
|
strictAssert(server !== undefined, 'WebAPI not available');
|
|
|
|
return server.requestVerification(number, captcha, transport);
|
|
|
|
}
|
|
|
|
|
|
|
|
function registerSingleDevice(
|
|
|
|
number: string,
|
|
|
|
code: string,
|
|
|
|
sessionId: string
|
|
|
|
): Promise<void> {
|
|
|
|
return window
|
|
|
|
.getAccountManager()
|
|
|
|
.registerSingleDevice(number, code, sessionId);
|
|
|
|
}
|
|
|
|
|
2024-07-15 21:05:09 +00:00
|
|
|
function readyForUpdates(): void {
|
|
|
|
window.IPC.readyForUpdates();
|
|
|
|
}
|
|
|
|
|
|
|
|
async function uploadProfile({
|
|
|
|
firstName,
|
|
|
|
lastName,
|
|
|
|
}: {
|
|
|
|
firstName: string;
|
|
|
|
lastName: string;
|
|
|
|
}): Promise<void> {
|
|
|
|
const us = window.ConversationController.getOurConversationOrThrow();
|
|
|
|
us.set('profileName', firstName);
|
|
|
|
us.set('profileFamilyName', lastName);
|
|
|
|
us.captureChange('standaloneProfile');
|
2024-07-22 18:16:33 +00:00
|
|
|
await DataWriter.updateConversation(us.attributes);
|
2024-07-15 21:05:09 +00:00
|
|
|
|
|
|
|
await writeProfile(getConversation(us), {
|
|
|
|
keepAvatar: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
export const SmartApp = memo(function SmartApp() {
|
2024-08-27 21:00:41 +00:00
|
|
|
const state = useSelector(getApp);
|
2024-03-19 17:12:32 +00:00
|
|
|
const isMaximized = useSelector(getIsMainWindowMaximized);
|
|
|
|
const isFullScreen = useSelector(getIsMainWindowFullScreen);
|
|
|
|
const hasSelectedStoryData = useSelector(getHasSelectedStoryData);
|
|
|
|
const theme = useSelector(getTheme);
|
2022-07-29 00:10:07 +00:00
|
|
|
|
2024-01-29 20:09:54 +00:00
|
|
|
const { openInbox } = useAppActions();
|
|
|
|
const { scrollToMessage } = useConversationsActions();
|
|
|
|
const { viewStory } = useStoriesActions();
|
2021-06-17 21:15:09 +00:00
|
|
|
|
2024-03-19 17:12:32 +00:00
|
|
|
const osClassName = OS.getClassName();
|
|
|
|
|
2024-01-29 20:09:54 +00:00
|
|
|
return (
|
|
|
|
<App
|
2024-08-27 21:00:41 +00:00
|
|
|
state={state}
|
2024-03-19 17:12:32 +00:00
|
|
|
isMaximized={isMaximized}
|
|
|
|
isFullScreen={isFullScreen}
|
2024-07-15 21:05:09 +00:00
|
|
|
getCaptchaToken={getCaptchaToken}
|
2024-03-19 17:12:32 +00:00
|
|
|
osClassName={osClassName}
|
|
|
|
renderCallManager={renderCallManager}
|
|
|
|
renderGlobalModalContainer={renderGlobalModalContainer}
|
|
|
|
renderLightbox={renderLightbox}
|
|
|
|
hasSelectedStoryData={hasSelectedStoryData}
|
2024-07-15 21:05:09 +00:00
|
|
|
readyForUpdates={readyForUpdates}
|
2024-03-19 17:12:32 +00:00
|
|
|
renderStoryViewer={renderStoryViewer}
|
2024-01-29 20:09:54 +00:00
|
|
|
renderInbox={renderInbox}
|
2024-03-19 17:12:32 +00:00
|
|
|
requestVerification={requestVerification}
|
|
|
|
registerSingleDevice={registerSingleDevice}
|
2024-07-15 21:05:09 +00:00
|
|
|
uploadProfile={uploadProfile}
|
2024-03-19 17:12:32 +00:00
|
|
|
theme={theme}
|
2024-01-29 20:09:54 +00:00
|
|
|
openInbox={openInbox}
|
|
|
|
scrollToMessage={scrollToMessage}
|
|
|
|
viewStory={viewStory}
|
|
|
|
/>
|
|
|
|
);
|
2024-03-13 20:44:13 +00:00
|
|
|
});
|