Skip to content
Snippets Groups Projects
Commit e3f66da4 authored by Anton Georgiev's avatar Anton Georgiev
Browse files

update chat unless user just left

parent fe998aac
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,7 @@ class Chat extends Component {
scrollPosition,
hasUnreadMessages,
lastReadMessageTime,
partnerIsLoggedOut,
isChatLocked,
actions,
intl,
......@@ -65,6 +66,7 @@ class Chat extends Component {
handleScrollUpdate={actions.handleScrollUpdate}
handleReadMessage={actions.handleReadMessage}
lastReadMessageTime={lastReadMessageTime}
partnerIsLoggedOut={partnerIsLoggedOut}
/>
<MessageForm
disabled={isChatLocked}
......
......@@ -54,6 +54,9 @@ export default injectIntl(createContainer(({ params, intl }) => {
messages = ChatService.getPrivateMessages(chatID);
}
let user = ChatService.getUser(chatID, '{{NAME}}');
const partnerIsLoggedOut = user.isLoggedOut;
if (messages && chatID !== PUBLIC_CHAT_KEY) {
let userMessage = messages.find(m => m.sender !== null);
let user = ChatService.getUser(chatID, '{{NAME}}');
......@@ -62,7 +65,7 @@ export default injectIntl(createContainer(({ params, intl }) => {
title = intl.formatMessage(intlMessages.titlePrivate, { name: user.name });
chatName = user.name;
if (user.isLoggedOut) {
if (partnerIsLoggedOut) {
let time = Date.now();
let id = `partner-disconnected-${time}`;
let messagePartnerLoggedOut = {
......@@ -92,6 +95,7 @@ export default injectIntl(createContainer(({ params, intl }) => {
messages,
lastReadMessageTime,
hasUnreadMessages,
partnerIsLoggedOut,
isChatLocked,
scrollPosition,
actions: {
......
import React, { Component, PropTypes } from 'react';
import { defineMessages, injectIntl } from 'react-intl';
import _ from 'lodash';
......@@ -112,14 +111,27 @@ class MessageList extends Component {
}
shouldComponentUpdate(nextProps) {
if (this.props.chatId !== nextProps.chatId
|| this.props.hasUnreadMessages !== nextProps.hasUnreadMessages
|| this.props.messages.length !== nextProps.messages.length
|| !_.isEqual(this.props.messages, nextProps.messages)) {
return true;
}
const {
chatId,
hasUnreadMessages,
partnerIsLoggedOut,
} = this.props;
const switchingCorrespondent = chatId !== nextProps.chatId;
const hasNewUnreadMessages = hasUnreadMessages !== nextProps.hasUnreadMessages;
// console.log('switchingCorrespondent=' + switchingCorrespondent);
// console.log('hasNewUnreadMessages=' + hasNewUnreadMessages);
// check if the messages include <user has left the meeting>
const lastMessageId = nextProps.messages[nextProps.messages.length - 1].id;
const userLeftIsDisplayed = lastMessageId.includes('partner-disconnected');
if (switchingCorrespondent || hasNewUnreadMessages) return true;
if (partnerIsLoggedOut && userLeftIsDisplayed) return false; // update leads to endless loop
return false;
return true;
}
render() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment