SessionConversation, render MessageView if no conversationModel found

pull/1381/head
Audric Ackermann 5 years ago
parent 190d597814
commit b9c4394b27
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -92,13 +92,6 @@
const inboxCollection = getInboxCollection(); const inboxCollection = getInboxCollection();
// ConversationCollection // ConversationCollection
const conversations = getConversations();
this.listenTo(conversations, 'remove', conversation => {
if (this.conversation_stack) {
this.conversation_stack.close(conversation);
}
});
this.listenTo(inboxCollection, 'messageError', () => { this.listenTo(inboxCollection, 'messageError', () => {
if (this.networkStatusView) { if (this.networkStatusView) {
this.networkStatusView.render(); this.networkStatusView.render();
@ -318,12 +311,6 @@
this.conversation_stack.open(conversation); this.conversation_stack.open(conversation);
}, },
closeConversation(conversation) {
if (conversation) {
this.inboxListView.removeItem(conversation);
this.conversation_stack.close(conversation);
}
},
}); });
Whisper.ExpiredAlertBanner = Whisper.View.extend({ Whisper.ExpiredAlertBanner = Whisper.View.extend({

@ -16,8 +16,6 @@ export const MainViewController = {
import { ContactType } from './session/SessionMemberListItem'; import { ContactType } from './session/SessionMemberListItem';
import { ToastUtils } from '../session/utils'; import { ToastUtils } from '../session/utils';
import { toast } from 'react-toastify';
import { SessionToast, SessionToastType } from './session/SessionToast';
export class MessageView extends React.Component { export class MessageView extends React.Component {
public render() { public render() {

@ -27,6 +27,7 @@ import { ToastUtils } from '../../../session/utils';
import * as MIME from '../../../types/MIME'; import * as MIME from '../../../types/MIME';
import { SessionFileDropzone } from './SessionFileDropzone'; import { SessionFileDropzone } from './SessionFileDropzone';
import { ConversationType } from '../../../state/ducks/conversations'; import { ConversationType } from '../../../state/ducks/conversations';
import { MessageView } from '../../MainViewController';
interface State { interface State {
// Message sending progress // Message sending progress
@ -175,15 +176,23 @@ export class SessionConversation extends React.Component<Props, State> {
public componentDidUpdate(prevProps: Props, prevState: State) { public componentDidUpdate(prevProps: Props, prevState: State) {
const { conversationKey: oldKey } = prevProps; const { conversationKey: oldKey } = prevProps;
try {
const oldConversationModel = window.ConversationController.getOrThrow( const oldConversationModel = window.ConversationController.getOrThrow(
oldKey oldKey
); );
oldConversationModel.off('change', this.refreshMessages); oldConversationModel.off('change', this.refreshMessages);
const { conversationKey: newKey } = this.props; } catch (e) {
const newCconversationModel = window.ConversationController.getOrThrow( window.log.warn(e);
newKey }
); try {
newCconversationModel.on('change', this.refreshMessages); const { conversationKey: newKey } = this.props;
const newConversationModel = window.ConversationController.getOrThrow(
newKey
);
newConversationModel.on('change', this.refreshMessages);
} catch (e) {
window.log.warn(e);
}
} }
public componentDidMount() { public componentDidMount() {
@ -220,10 +229,15 @@ export class SessionConversation extends React.Component<Props, State> {
const selectionMode = !!selectedMessages.length; const selectionMode = !!selectedMessages.length;
const { conversation, conversationKey } = this.props; const { conversation, conversationKey } = this.props;
const conversationModel = window.ConversationController.getOrThrow( const conversationModel = window.ConversationController.get(
conversationKey conversationKey
); );
if (!conversationModel) {
// return an empty message view
return <MessageView />;
}
const { isRss } = conversation; const { isRss } = conversation;
// TODO VINCE: OPTIMISE FOR NEW SENDING??? // TODO VINCE: OPTIMISE FOR NEW SENDING???
@ -334,7 +348,7 @@ export class SessionConversation extends React.Component<Props, State> {
if (this.state.initialFetchComplete) { if (this.state.initialFetchComplete) {
return; return;
} }
const { conversationKey } = this.props; const { conversationKey, conversation } = this.props;
const conversationModel = window.ConversationController.getOrThrow( const conversationModel = window.ConversationController.getOrThrow(
conversationKey conversationKey
); );
@ -343,15 +357,17 @@ export class SessionConversation extends React.Component<Props, State> {
Constants.CONVERSATION.DEFAULT_MESSAGE_FETCH_COUNT, Constants.CONVERSATION.DEFAULT_MESSAGE_FETCH_COUNT,
unreadCount unreadCount
); );
return this.getMessages(messagesToFetch, () => { if (conversation) {
this.setState({ initialFetchComplete: true }); return this.getMessages(messagesToFetch, () => {
}); this.setState({ initialFetchComplete: true });
});
}
} }
// tslint:disable-next-line: no-empty // tslint:disable-next-line: no-empty
public async getMessages(numMessages?: number, callback: any = () => {}) { public async getMessages(numMessages?: number, callback: any = () => {}) {
const { unreadCount } = this.state; const { unreadCount } = this.state;
const { conversationKey } = this.props; const { conversationKey, conversation } = this.props;
let msgCount = let msgCount =
numMessages || numMessages ||
Number(Constants.CONVERSATION.DEFAULT_MESSAGE_FETCH_COUNT) + unreadCount; Number(Constants.CONVERSATION.DEFAULT_MESSAGE_FETCH_COUNT) + unreadCount;
@ -364,6 +380,11 @@ export class SessionConversation extends React.Component<Props, State> {
msgCount = Constants.CONVERSATION.DEFAULT_MESSAGE_FETCH_COUNT; msgCount = Constants.CONVERSATION.DEFAULT_MESSAGE_FETCH_COUNT;
} }
if (!conversation) {
// no valid conversation, early return
return;
}
const messageSet = await window.Signal.Data.getMessagesByConversation( const messageSet = await window.Signal.Data.getMessagesByConversation(
conversationKey, conversationKey,
{ limit: msgCount, MessageCollection: window.Whisper.MessageCollection } { limit: msgCount, MessageCollection: window.Whisper.MessageCollection }
@ -374,7 +395,7 @@ export class SessionConversation extends React.Component<Props, State> {
const messages = []; const messages = [];
// no need to do that `firstMessageOfSeries` on a private chat // 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); this.setState({ messages: messageSet.models }, callback);
return; return;
} }

Loading…
Cancel
Save