signal-desktop/ts/state/getInitialState.ts

150 lines
5.3 KiB
TypeScript
Raw Normal View History

// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { getEmptyState as accounts } from './ducks/accounts';
import { getEmptyState as app } from './ducks/app';
import { getEmptyState as audioPlayer } from './ducks/audioPlayer';
import { getEmptyState as audioRecorder } from './ducks/audioRecorder';
import { getEmptyState as calling } from './ducks/calling';
import { getEmptyState as composer } from './ducks/composer';
import { getEmptyState as conversations } from './ducks/conversations';
import { getEmptyState as crashReports } from './ducks/crashReports';
import { getEmptyState as expiration } from './ducks/expiration';
import { getEmptyState as globalModals } from './ducks/globalModals';
2022-12-10 02:02:22 +00:00
import { getEmptyState as lightbox } from './ducks/lightbox';
import { getEmptyState as linkPreviews } from './ducks/linkPreviews';
2022-12-20 17:50:23 +00:00
import { getEmptyState as mediaGallery } from './ducks/mediaGallery';
import { getEmptyState as network } from './ducks/network';
import { getEmptyState as preferredReactions } from './ducks/preferredReactions';
import { getEmptyState as safetyNumber } from './ducks/safetyNumber';
import { getEmptyState as search } from './ducks/search';
2022-03-04 21:14:52 +00:00
import { getEmptyState as getStoriesEmptyState } from './ducks/stories';
2022-07-01 00:52:03 +00:00
import { getEmptyState as getStoryDistributionListsEmptyState } from './ducks/storyDistributionLists';
import { getEmptyState as getToastEmptyState } from './ducks/toast';
import { getEmptyState as updates } from './ducks/updates';
import { getEmptyState as user } from './ducks/user';
2022-10-18 17:12:02 +00:00
import { getEmptyState as username } from './ducks/username';
import type { StateType } from './reducer';
import type { BadgesStateType } from './ducks/badges';
2022-03-04 21:14:52 +00:00
import type { StoryDataType } from './ducks/stories';
2022-07-01 00:52:03 +00:00
import type { StoryDistributionListDataType } from './ducks/storyDistributionLists';
import { getInitialState as stickers } from '../types/Stickers';
import type { MenuOptionsType } from '../types/menu';
2022-07-08 20:46:25 +00:00
import { UUIDKind } from '../types/UUID';
import { getEmojiReducerState as emojis } from '../util/loadRecentEmojis';
import type { MainWindowStatsType } from '../windows/context';
2022-07-13 00:37:21 +00:00
import { getThemeType } from '../util/getThemeType';
export function getInitialState({
badges,
2022-03-04 21:14:52 +00:00
stories,
2022-07-01 00:52:03 +00:00
storyDistributionLists,
mainWindowStats,
menuOptions,
}: {
badges: BadgesStateType;
2022-03-04 21:14:52 +00:00
stories: Array<StoryDataType>;
2022-07-01 00:52:03 +00:00
storyDistributionLists: Array<StoryDistributionListDataType>;
mainWindowStats: MainWindowStatsType;
menuOptions: MenuOptionsType;
}): StateType {
const items = window.storage.getItemsState();
const convoCollection = window.getConversations();
const formattedConversations = convoCollection.map(conversation =>
conversation.format()
);
const ourNumber = window.textsecure.storage.user.getNumber();
2022-07-08 20:46:25 +00:00
const ourACI = window.textsecure.storage.user
.getUuid(UUIDKind.ACI)
?.toString();
const ourPNI = window.textsecure.storage.user
.getUuid(UUIDKind.PNI)
?.toString();
const ourConversationId =
window.ConversationController.getOurConversationId();
const ourDeviceId = window.textsecure.storage.user.getDeviceId();
2022-07-13 00:37:21 +00:00
const theme = getThemeType();
return {
accounts: accounts(),
app: app(),
audioPlayer: audioPlayer(),
audioRecorder: audioRecorder(),
badges,
calling: calling(),
composer: composer(),
conversations: {
...conversations(),
conversationLookup: window.Signal.Util.makeLookup(
formattedConversations,
'id'
),
conversationsByE164: window.Signal.Util.makeLookup(
formattedConversations,
'e164'
),
2022-09-27 20:31:55 +00:00
conversationsByUuid: {
...window.Signal.Util.makeLookup(formattedConversations, 'uuid'),
...window.Signal.Util.makeLookup(formattedConversations, 'pni'),
},
conversationsByGroupId: window.Signal.Util.makeLookup(
formattedConversations,
'groupId'
),
conversationsByUsername: window.Signal.Util.makeLookup(
formattedConversations,
'username'
),
},
crashReports: crashReports(),
emojis: emojis(),
expiration: expiration(),
globalModals: globalModals(),
items,
2022-12-10 02:02:22 +00:00
lightbox: lightbox(),
linkPreviews: linkPreviews(),
2022-12-20 17:50:23 +00:00
mediaGallery: mediaGallery(),
network: network(),
preferredReactions: preferredReactions(),
safetyNumber: safetyNumber(),
search: search(),
stickers: stickers(),
2022-03-04 21:14:52 +00:00
stories: {
...getStoriesEmptyState(),
stories,
},
2022-07-01 00:52:03 +00:00
storyDistributionLists: {
...getStoryDistributionListsEmptyState(),
distributionLists: storyDistributionLists || [],
},
toast: getToastEmptyState(),
updates: updates(),
user: {
...user(),
attachmentsPath: window.baseAttachmentsPath,
stickersPath: window.baseStickersPath,
tempPath: window.baseTempPath,
regionCode: window.storage.get('regionCode'),
ourConversationId,
ourDeviceId,
ourNumber,
2022-07-08 20:46:25 +00:00
ourACI,
ourPNI,
platform: window.platform,
i18n: window.i18n,
localeMessages: window.SignalContext.localeMessages,
interactionMode: window.getInteractionMode(),
theme,
version: window.getVersion(),
isMainWindowMaximized: mainWindowStats.isMaximized,
isMainWindowFullScreen: mainWindowStats.isFullScreen,
menuOptions,
},
2022-10-18 17:12:02 +00:00
username: username(),
};
}