diff --git a/js/views/inbox_view.js b/js/views/inbox_view.js index 6e926b62d..bb0c7adb5 100644 --- a/js/views/inbox_view.js +++ b/js/views/inbox_view.js @@ -92,13 +92,6 @@ const inboxCollection = getInboxCollection(); // ConversationCollection - const conversations = getConversations(); - this.listenTo(conversations, 'remove', conversation => { - if (this.conversation_stack) { - this.conversation_stack.close(conversation); - } - }); - this.listenTo(inboxCollection, 'messageError', () => { if (this.networkStatusView) { this.networkStatusView.render(); @@ -318,12 +311,6 @@ this.conversation_stack.open(conversation); }, - closeConversation(conversation) { - if (conversation) { - this.inboxListView.removeItem(conversation); - this.conversation_stack.close(conversation); - } - }, }); Whisper.ExpiredAlertBanner = Whisper.View.extend({ diff --git a/ts/components/MainViewController.tsx b/ts/components/MainViewController.tsx index 6b07835c6..f65ce58f3 100644 --- a/ts/components/MainViewController.tsx +++ b/ts/components/MainViewController.tsx @@ -16,8 +16,6 @@ export const MainViewController = { import { ContactType } from './session/SessionMemberListItem'; import { ToastUtils } from '../session/utils'; -import { toast } from 'react-toastify'; -import { SessionToast, SessionToastType } from './session/SessionToast'; export class MessageView extends React.Component { public render() { diff --git a/ts/components/session/conversation/SessionConversation.tsx b/ts/components/session/conversation/SessionConversation.tsx index 0d3c163ee..a0ff376aa 100644 --- a/ts/components/session/conversation/SessionConversation.tsx +++ b/ts/components/session/conversation/SessionConversation.tsx @@ -27,6 +27,7 @@ import { ToastUtils } from '../../../session/utils'; import * as MIME from '../../../types/MIME'; import { SessionFileDropzone } from './SessionFileDropzone'; import { ConversationType } from '../../../state/ducks/conversations'; +import { MessageView } from '../../MainViewController'; interface State { // Message sending progress @@ -175,15 +176,23 @@ export class SessionConversation extends React.Component { public componentDidUpdate(prevProps: Props, prevState: State) { const { conversationKey: oldKey } = prevProps; + try { const oldConversationModel = window.ConversationController.getOrThrow( oldKey ); - oldConversationModel.off('change', this.refreshMessages); - const { conversationKey: newKey } = this.props; - const newCconversationModel = window.ConversationController.getOrThrow( - newKey - ); - newCconversationModel.on('change', this.refreshMessages); + oldConversationModel.off('change', this.refreshMessages); + } catch (e) { + window.log.warn(e); + } + try { + const { conversationKey: newKey } = this.props; + const newConversationModel = window.ConversationController.getOrThrow( + newKey + ); + newConversationModel.on('change', this.refreshMessages); + } catch (e) { + window.log.warn(e); + } } public componentDidMount() { @@ -220,10 +229,15 @@ export class SessionConversation extends React.Component { const selectionMode = !!selectedMessages.length; const { conversation, conversationKey } = this.props; - const conversationModel = window.ConversationController.getOrThrow( + const conversationModel = window.ConversationController.get( conversationKey ); + if (!conversationModel) { + // return an empty message view + return ; + } + const { isRss } = conversation; // TODO VINCE: OPTIMISE FOR NEW SENDING??? @@ -334,7 +348,7 @@ export class SessionConversation extends React.Component { if (this.state.initialFetchComplete) { return; } - const { conversationKey } = this.props; + const { conversationKey, conversation } = this.props; const conversationModel = window.ConversationController.getOrThrow( conversationKey ); @@ -343,15 +357,17 @@ export class SessionConversation extends React.Component { Constants.CONVERSATION.DEFAULT_MESSAGE_FETCH_COUNT, unreadCount ); - return this.getMessages(messagesToFetch, () => { - this.setState({ initialFetchComplete: true }); - }); + if (conversation) { + return this.getMessages(messagesToFetch, () => { + this.setState({ initialFetchComplete: true }); + }); + } } // tslint:disable-next-line: no-empty public async getMessages(numMessages?: number, callback: any = () => {}) { const { unreadCount } = this.state; - const { conversationKey } = this.props; + const { conversationKey, conversation } = this.props; let msgCount = numMessages || Number(Constants.CONVERSATION.DEFAULT_MESSAGE_FETCH_COUNT) + unreadCount; @@ -364,6 +380,11 @@ export class SessionConversation extends React.Component { msgCount = Constants.CONVERSATION.DEFAULT_MESSAGE_FETCH_COUNT; } + if (!conversation) { + // no valid conversation, early return + return; + } + const messageSet = await window.Signal.Data.getMessagesByConversation( conversationKey, { limit: msgCount, MessageCollection: window.Whisper.MessageCollection } @@ -374,7 +395,7 @@ export class SessionConversation extends React.Component { const messages = []; // no need to do that `firstMessageOfSeries` on a private chat - if (this.props.conversation.type === 'direct') { + if (conversation.type === 'direct') { this.setState({ messages: messageSet.models }, callback); return; }