2022-02-23 18:48:40 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2024-08-26 14:26:21 +00:00
|
|
|
import { getEmptyState as accountsEmptyState } from './ducks/accounts';
|
|
|
|
import { getEmptyState as appEmptyState } from './ducks/app';
|
|
|
|
import { getEmptyState as audioPlayerEmptyState } from './ducks/audioPlayer';
|
|
|
|
import { getEmptyState as audioRecorderEmptyState } from './ducks/audioRecorder';
|
|
|
|
import { getEmptyState as badgesEmptyState } from './ducks/badges';
|
|
|
|
import { getEmptyState as callHistoryEmptyState } from './ducks/callHistory';
|
|
|
|
import { getEmptyState as callingEmptyState } from './ducks/calling';
|
|
|
|
import { getEmptyState as composerEmptyState } from './ducks/composer';
|
|
|
|
import { getEmptyState as conversationsEmptyState } from './ducks/conversations';
|
|
|
|
import { getEmptyState as crashReportsEmptyState } from './ducks/crashReports';
|
|
|
|
import { getEmptyState as emojiEmptyState } from './ducks/emojis';
|
|
|
|
import { getEmptyState as expirationEmptyState } from './ducks/expiration';
|
|
|
|
import { getEmptyState as globalModalsEmptyState } from './ducks/globalModals';
|
|
|
|
import { getEmptyState as inboxEmptyState } from './ducks/inbox';
|
2024-09-04 02:56:13 +00:00
|
|
|
import { getEmptyState as installerEmptyState } from './ducks/installer';
|
2024-08-29 13:30:27 +00:00
|
|
|
import { getEmptyState as itemsEmptyState } from './ducks/items';
|
2024-08-26 14:26:21 +00:00
|
|
|
import { getEmptyState as lightboxEmptyState } from './ducks/lightbox';
|
|
|
|
import { getEmptyState as linkPreviewsEmptyState } from './ducks/linkPreviews';
|
|
|
|
import { getEmptyState as mediaGalleryEmptyState } from './ducks/mediaGallery';
|
|
|
|
import { getEmptyState as navEmptyState } from './ducks/nav';
|
|
|
|
import { getEmptyState as networkEmptyState } from './ducks/network';
|
|
|
|
import { getEmptyState as preferredReactionsEmptyState } from './ducks/preferredReactions';
|
|
|
|
import { getEmptyState as safetyNumberEmptyState } from './ducks/safetyNumber';
|
|
|
|
import { getEmptyState as searchEmptyState } from './ducks/search';
|
2024-08-29 13:30:27 +00:00
|
|
|
import { getEmptyState as stickersEmptyState } from './ducks/stickers';
|
2024-08-26 14:26:21 +00:00
|
|
|
import { getEmptyState as storiesEmptyState } from './ducks/stories';
|
|
|
|
import { getEmptyState as storyDistributionListsEmptyState } from './ducks/storyDistributionLists';
|
|
|
|
import { getEmptyState as toastEmptyState } from './ducks/toast';
|
|
|
|
import { getEmptyState as updatesEmptyState } from './ducks/updates';
|
|
|
|
import { getEmptyState as userEmptyState } from './ducks/user';
|
|
|
|
import { getEmptyState as usernameEmptyState } from './ducks/username';
|
2022-02-23 18:48:40 +00:00
|
|
|
|
2023-04-20 21:23:19 +00:00
|
|
|
import OS from '../util/os/osMain';
|
2023-03-14 15:55:31 +00:00
|
|
|
import { getInteractionMode } from '../services/InteractionMode';
|
2023-04-11 03:54:43 +00:00
|
|
|
import { makeLookup } from '../util/makeLookup';
|
2024-08-26 14:26:21 +00:00
|
|
|
|
|
|
|
import type { StateType } from './reducer';
|
|
|
|
import type { MainWindowStatsType } from '../windows/context';
|
|
|
|
import type { ConversationsStateType } from './ducks/conversations';
|
|
|
|
import type { MenuOptionsType } from '../types/menu';
|
|
|
|
import type {
|
|
|
|
StoryDistributionListDataType,
|
|
|
|
StoryDistributionListStateType,
|
|
|
|
} from './ducks/storyDistributionLists';
|
2024-03-07 17:36:08 +00:00
|
|
|
import type { ThemeType } from '../types/Util';
|
2024-08-26 14:26:21 +00:00
|
|
|
import type { UserStateType } from './ducks/user';
|
|
|
|
import type { ReduxInitData } from './initializeRedux';
|
|
|
|
|
|
|
|
export function getInitialState(
|
|
|
|
{
|
|
|
|
badgesState,
|
|
|
|
callLinks,
|
|
|
|
callHistory: calls,
|
|
|
|
callHistoryUnreadCount,
|
|
|
|
mainWindowStats,
|
|
|
|
menuOptions,
|
|
|
|
recentEmoji,
|
|
|
|
stickers,
|
|
|
|
stories,
|
|
|
|
storyDistributionLists,
|
|
|
|
theme,
|
|
|
|
}: ReduxInitData,
|
|
|
|
existingState?: StateType
|
|
|
|
): StateType {
|
|
|
|
const items = window.storage.getItemsState();
|
|
|
|
|
|
|
|
const baseState: StateType = existingState ?? getEmptyState();
|
|
|
|
|
|
|
|
return {
|
|
|
|
...baseState,
|
|
|
|
badges: badgesState,
|
|
|
|
callHistory: {
|
|
|
|
...callHistoryEmptyState(),
|
|
|
|
callHistoryByCallId: makeLookup(calls, 'callId'),
|
|
|
|
unreadCount: callHistoryUnreadCount,
|
|
|
|
},
|
|
|
|
calling: {
|
|
|
|
...callingEmptyState(),
|
|
|
|
callLinks: makeLookup(callLinks, 'roomId'),
|
|
|
|
},
|
|
|
|
emojis: recentEmoji,
|
|
|
|
items,
|
|
|
|
stickers,
|
|
|
|
stories: {
|
|
|
|
...storiesEmptyState(),
|
|
|
|
stories,
|
|
|
|
},
|
|
|
|
storyDistributionLists: generateStoryDistributionListState(
|
|
|
|
storyDistributionLists
|
|
|
|
),
|
|
|
|
user: generateUserState({
|
|
|
|
mainWindowStats,
|
|
|
|
menuOptions,
|
|
|
|
theme,
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function generateConversationsState(): ConversationsStateType {
|
|
|
|
const convoCollection = window.getConversations();
|
|
|
|
const formattedConversations = convoCollection.map(conversation =>
|
|
|
|
conversation.format()
|
|
|
|
);
|
2022-02-23 18:48:40 +00:00
|
|
|
|
2024-08-26 14:26:21 +00:00
|
|
|
return {
|
|
|
|
...conversationsEmptyState(),
|
|
|
|
conversationLookup: makeLookup(formattedConversations, 'id'),
|
|
|
|
conversationsByE164: makeLookup(formattedConversations, 'e164'),
|
|
|
|
conversationsByServiceId: {
|
|
|
|
...makeLookup(formattedConversations, 'serviceId'),
|
|
|
|
...makeLookup(formattedConversations, 'pni'),
|
|
|
|
},
|
|
|
|
conversationsByGroupId: makeLookup(formattedConversations, 'groupId'),
|
|
|
|
conversationsByUsername: makeLookup(formattedConversations, 'username'),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function getEmptyState(): StateType {
|
|
|
|
return {
|
|
|
|
accounts: accountsEmptyState(),
|
|
|
|
app: appEmptyState(),
|
|
|
|
audioPlayer: audioPlayerEmptyState(),
|
|
|
|
audioRecorder: audioRecorderEmptyState(),
|
|
|
|
badges: badgesEmptyState(),
|
|
|
|
callHistory: callHistoryEmptyState(),
|
|
|
|
calling: callingEmptyState(),
|
|
|
|
composer: composerEmptyState(),
|
|
|
|
conversations: generateConversationsState(),
|
|
|
|
crashReports: crashReportsEmptyState(),
|
|
|
|
emojis: emojiEmptyState(),
|
|
|
|
expiration: expirationEmptyState(),
|
|
|
|
globalModals: globalModalsEmptyState(),
|
|
|
|
inbox: inboxEmptyState(),
|
2024-09-04 02:56:13 +00:00
|
|
|
installer: installerEmptyState(),
|
2024-08-26 14:26:21 +00:00
|
|
|
items: itemsEmptyState(),
|
|
|
|
lightbox: lightboxEmptyState(),
|
|
|
|
linkPreviews: linkPreviewsEmptyState(),
|
|
|
|
mediaGallery: mediaGalleryEmptyState(),
|
|
|
|
nav: navEmptyState(),
|
|
|
|
network: networkEmptyState(),
|
|
|
|
preferredReactions: preferredReactionsEmptyState(),
|
|
|
|
safetyNumber: safetyNumberEmptyState(),
|
|
|
|
search: searchEmptyState(),
|
|
|
|
stickers: stickersEmptyState(),
|
|
|
|
stories: storiesEmptyState(),
|
|
|
|
storyDistributionLists: storyDistributionListsEmptyState(),
|
|
|
|
toast: toastEmptyState(),
|
|
|
|
updates: updatesEmptyState(),
|
|
|
|
user: userEmptyState(),
|
|
|
|
username: usernameEmptyState(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function generateStoryDistributionListState(
|
|
|
|
storyDistributionLists: ReadonlyArray<StoryDistributionListDataType>
|
|
|
|
): StoryDistributionListStateType {
|
|
|
|
return {
|
|
|
|
...storyDistributionListsEmptyState(),
|
|
|
|
distributionLists: storyDistributionLists || [],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function generateUserState({
|
2022-06-08 22:00:32 +00:00
|
|
|
mainWindowStats,
|
|
|
|
menuOptions,
|
2024-03-07 17:36:08 +00:00
|
|
|
theme,
|
2022-02-23 18:48:40 +00:00
|
|
|
}: {
|
2022-06-08 22:00:32 +00:00
|
|
|
mainWindowStats: MainWindowStatsType;
|
|
|
|
menuOptions: MenuOptionsType;
|
2024-03-07 17:36:08 +00:00
|
|
|
theme: ThemeType;
|
2024-08-26 14:26:21 +00:00
|
|
|
}): UserStateType {
|
2022-02-23 18:48:40 +00:00
|
|
|
const ourNumber = window.textsecure.storage.user.getNumber();
|
2023-08-10 16:43:33 +00:00
|
|
|
const ourAci = window.textsecure.storage.user.getAci();
|
|
|
|
const ourPni = window.textsecure.storage.user.getPni();
|
2022-02-23 18:48:40 +00:00
|
|
|
const ourConversationId =
|
|
|
|
window.ConversationController.getOurConversationId();
|
|
|
|
const ourDeviceId = window.textsecure.storage.user.getDeviceId();
|
|
|
|
|
2023-01-13 00:24:59 +00:00
|
|
|
let osName: 'windows' | 'macos' | 'linux' | undefined;
|
|
|
|
|
|
|
|
if (OS.isWindows()) {
|
|
|
|
osName = 'windows';
|
|
|
|
} else if (OS.isMacOS()) {
|
|
|
|
osName = 'macos';
|
|
|
|
} else if (OS.isLinux()) {
|
|
|
|
osName = 'linux';
|
|
|
|
}
|
|
|
|
|
2022-02-23 18:48:40 +00:00
|
|
|
return {
|
2024-08-26 14:26:21 +00:00
|
|
|
...userEmptyState(),
|
|
|
|
attachmentsPath: window.BasePaths.attachments,
|
|
|
|
i18n: window.i18n,
|
|
|
|
interactionMode: getInteractionMode(),
|
|
|
|
isMainWindowFullScreen: mainWindowStats.isFullScreen,
|
|
|
|
isMainWindowMaximized: mainWindowStats.isMaximized,
|
|
|
|
localeMessages: window.i18n.getLocaleMessages(),
|
|
|
|
menuOptions,
|
|
|
|
osName,
|
|
|
|
ourAci,
|
|
|
|
ourConversationId,
|
|
|
|
ourDeviceId,
|
|
|
|
ourNumber,
|
|
|
|
ourPni,
|
|
|
|
platform: window.platform,
|
|
|
|
regionCode: window.storage.get('regionCode'),
|
|
|
|
stickersPath: window.BasePaths.stickers,
|
|
|
|
tempPath: window.BasePaths.temp,
|
|
|
|
theme,
|
|
|
|
version: window.getVersion(),
|
2022-02-23 18:48:40 +00:00
|
|
|
};
|
|
|
|
}
|