import React from 'react'; import { Provider } from 'react-redux'; import { bindActionCreators } from 'redux'; import { getMessageById } from '../../data/data'; import { ConversationModel } from '../../models/conversation'; import { MessageModel } from '../../models/message'; import { getMessageQueue } from '../../session'; import { ConversationController } from '../../session/conversations'; import { MessageController } from '../../session/messages'; import { OpenGroupMessage } from '../../session/messages/outgoing'; import { RawMessage } from '../../session/types'; import { UserUtils } from '../../session/utils'; import { createStore } from '../../state/createStore'; import { actions as conversationActions } from '../../state/ducks/conversations'; import { actions as userActions } from '../../state/ducks/user'; import { SmartLeftPane } from '../../state/smart/LeftPane'; import { SmartSessionConversation } from '../../state/smart/SessionConversation'; import { makeLookup } from '../../util'; import { SessionSettingCategory, SmartSettingsView, } from './settings/SessionSettings'; // Workaround: A react component's required properties are filtering up through connect() // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/31363 const FilteredLeftPane = SmartLeftPane as any; const FilteredSettingsView = SmartSettingsView as any; type Props = { focusedSection: number; }; type State = { isInitialLoadComplete: boolean; settingsCategory?: SessionSettingCategory; isExpired: boolean; }; export class SessionInboxView extends React.Component { private store: any; constructor(props: any) { super(props); this.state = { isInitialLoadComplete: false, settingsCategory: undefined, isExpired: false, }; this.showSessionSettingsCategory = this.showSessionSettingsCategory.bind( this ); this.showSessionViewConversation = this.showSessionViewConversation.bind( this ); void this.setupLeftPane(); // not reactified yet. this is a callback called once we were able to check for expiration of this Session version window.extension.expired((expired: boolean) => { if (expired) { this.setState({ isExpired: true, }); } }); } public render() { if (!this.state.isInitialLoadComplete) { return <>; } const { settingsCategory } = this.state; const isSettingsView = settingsCategory !== undefined; return (
{this.renderLeftPane()}
{isSettingsView ? this.renderSettings() : this.renderSessionConversation()} ); } private renderLeftPane() { return ( ); } private renderSettings() { const category = this.state.settingsCategory || SessionSettingCategory.Appearance; return ; } private renderSessionConversation() { return (
); } private async setupLeftPane() { // Here we set up a full redux store with initial state for our LeftPane Root const convoCollection = ConversationController.getInstance().getConversations(); const conversations = convoCollection.map( (conversation: ConversationModel) => conversation.getProps() ); const filledConversations = conversations.map((conv: any) => { return { ...conv, messages: [] }; }); const fullFilledConversations = await Promise.all(filledConversations); const initialState = { conversations: { conversationLookup: makeLookup(fullFilledConversations, 'id'), }, user: { ourPrimary: window.storage.get('primaryDevicePubKey'), ourNumber: UserUtils.getOurPubKeyStrFromCache(), i18n: window.i18n, }, section: { focusedSection: 1, }, }; this.store = createStore(initialState); window.inboxStore = this.store; // Enables our redux store to be updated by backbone events in the outside world const { messageExpired } = bindActionCreators( conversationActions, this.store.dispatch ); window.actionsCreators = conversationActions; // messageExpired is currently inboked fropm js. So we link it to Redux that way window.Whisper.events.on('messageExpired', messageExpired); this.setState({ isInitialLoadComplete: true }); } private showSessionSettingsCategory(category: SessionSettingCategory) { this.setState({ settingsCategory: category }); } private showSessionViewConversation() { this.setState({ settingsCategory: undefined }); } }