Reinitialize redux after importing a backup
This commit is contained in:
parent
19e0eb4444
commit
abdef4847a
21 changed files with 437 additions and 264 deletions
|
@ -1,75 +1,175 @@
|
|||
// 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 callHistory } from './ducks/callHistory';
|
||||
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';
|
||||
import { getEmptyState as inbox } from './ducks/inbox';
|
||||
import { getEmptyState as lightbox } from './ducks/lightbox';
|
||||
import { getEmptyState as linkPreviews } from './ducks/linkPreviews';
|
||||
import { getEmptyState as mediaGallery } from './ducks/mediaGallery';
|
||||
import { getEmptyState as nav } from './ducks/nav';
|
||||
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';
|
||||
import { getEmptyState as getStoriesEmptyState } from './ducks/stories';
|
||||
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';
|
||||
import { getEmptyState as username } from './ducks/username';
|
||||
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 itemsEmptyState } from './ducks/items';
|
||||
import { getEmptyState as stickersEmptyState } from './ducks/stickers';
|
||||
import { getEmptyState as expirationEmptyState } from './ducks/expiration';
|
||||
import { getEmptyState as globalModalsEmptyState } from './ducks/globalModals';
|
||||
import { getEmptyState as inboxEmptyState } from './ducks/inbox';
|
||||
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';
|
||||
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';
|
||||
|
||||
import type { StateType } from './reducer';
|
||||
import type { BadgesStateType } from './ducks/badges';
|
||||
import type { MainWindowStatsType } from '../windows/context';
|
||||
import type { MenuOptionsType } from '../types/menu';
|
||||
import type { StoryDataType } from './ducks/stories';
|
||||
import type { StoryDistributionListDataType } from './ducks/storyDistributionLists';
|
||||
import OS from '../util/os/osMain';
|
||||
import { getEmojiReducerState as emojis } from '../util/loadRecentEmojis';
|
||||
import { getInitialState as stickers } from '../types/Stickers';
|
||||
import { getInteractionMode } from '../services/InteractionMode';
|
||||
import { makeLookup } from '../util/makeLookup';
|
||||
import type { CallHistoryDetails } from '../types/CallDisposition';
|
||||
import type { ThemeType } from '../types/Util';
|
||||
import type { CallLinkType } from '../types/CallLink';
|
||||
|
||||
export function getInitialState({
|
||||
badges,
|
||||
callLinks,
|
||||
callsHistory,
|
||||
callsHistoryUnreadCount,
|
||||
stories,
|
||||
storyDistributionLists,
|
||||
mainWindowStats,
|
||||
menuOptions,
|
||||
theme,
|
||||
}: {
|
||||
badges: BadgesStateType;
|
||||
callLinks: ReadonlyArray<CallLinkType>;
|
||||
callsHistory: ReadonlyArray<CallHistoryDetails>;
|
||||
callsHistoryUnreadCount: number;
|
||||
stories: Array<StoryDataType>;
|
||||
storyDistributionLists: Array<StoryDistributionListDataType>;
|
||||
mainWindowStats: MainWindowStatsType;
|
||||
menuOptions: MenuOptionsType;
|
||||
theme: ThemeType;
|
||||
}): StateType {
|
||||
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';
|
||||
import type { ThemeType } from '../types/Util';
|
||||
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()
|
||||
);
|
||||
|
||||
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(),
|
||||
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({
|
||||
mainWindowStats,
|
||||
menuOptions,
|
||||
theme,
|
||||
}: {
|
||||
mainWindowStats: MainWindowStatsType;
|
||||
menuOptions: MenuOptionsType;
|
||||
theme: ThemeType;
|
||||
}): UserStateType {
|
||||
const ourNumber = window.textsecure.storage.user.getNumber();
|
||||
const ourAci = window.textsecure.storage.user.getAci();
|
||||
const ourPni = window.textsecure.storage.user.getPni();
|
||||
|
@ -88,79 +188,25 @@ export function getInitialState({
|
|||
}
|
||||
|
||||
return {
|
||||
accounts: accounts(),
|
||||
app: app(),
|
||||
audioPlayer: audioPlayer(),
|
||||
audioRecorder: audioRecorder(),
|
||||
badges,
|
||||
callHistory: {
|
||||
...callHistory(),
|
||||
callHistoryByCallId: makeLookup(callsHistory, 'callId'),
|
||||
unreadCount: callsHistoryUnreadCount,
|
||||
},
|
||||
calling: {
|
||||
...calling(),
|
||||
callLinks: makeLookup(callLinks, 'roomId'),
|
||||
},
|
||||
composer: composer(),
|
||||
conversations: {
|
||||
...conversations(),
|
||||
conversationLookup: makeLookup(formattedConversations, 'id'),
|
||||
conversationsByE164: makeLookup(formattedConversations, 'e164'),
|
||||
conversationsByServiceId: {
|
||||
...makeLookup(formattedConversations, 'serviceId'),
|
||||
...makeLookup(formattedConversations, 'pni'),
|
||||
},
|
||||
conversationsByGroupId: makeLookup(formattedConversations, 'groupId'),
|
||||
conversationsByUsername: makeLookup(formattedConversations, 'username'),
|
||||
},
|
||||
crashReports: crashReports(),
|
||||
emojis: emojis(),
|
||||
expiration: expiration(),
|
||||
globalModals: globalModals(),
|
||||
inbox: inbox(),
|
||||
items,
|
||||
lightbox: lightbox(),
|
||||
linkPreviews: linkPreviews(),
|
||||
mediaGallery: mediaGallery(),
|
||||
nav: nav(),
|
||||
network: network(),
|
||||
preferredReactions: preferredReactions(),
|
||||
safetyNumber: safetyNumber(),
|
||||
search: search(),
|
||||
stickers: stickers(),
|
||||
stories: {
|
||||
...getStoriesEmptyState(),
|
||||
stories,
|
||||
},
|
||||
storyDistributionLists: {
|
||||
...getStoryDistributionListsEmptyState(),
|
||||
distributionLists: storyDistributionLists || [],
|
||||
},
|
||||
toast: getToastEmptyState(),
|
||||
updates: updates(),
|
||||
user: {
|
||||
...user(),
|
||||
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(),
|
||||
},
|
||||
username: username(),
|
||||
...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(),
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue