SessionConversation, render MessageView if no conversationModel found

pull/1381/head
Audric Ackermann 4 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();
// 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({

@ -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() {

@ -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<Props, State> {
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<Props, State> {
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 <MessageView />;
}
const { isRss } = conversation;
// TODO VINCE: OPTIMISE FOR NEW SENDING???
@ -334,7 +348,7 @@ export class SessionConversation extends React.Component<Props, State> {
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<Props, State> {
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<Props, State> {
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<Props, State> {
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;
}

Loading…
Cancel
Save