Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Components/ColumnMiddle/MessagesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -1731,7 +1731,7 @@ class MessagesList extends React.Component {
<ActionBar chatId={chatId} />
<Placeholder />
{scrollDownVisible && (
<ScrollDownButton ref={this.scrollDownButtonRef} onClick={this.handleScrollDownClick} />
<ScrollDownButton ref={this.scrollDownButtonRef} onClick={this.handleScrollDownClick} chatId={chatId}/>
)}
<FilesDropTarget />
<StickersHint />
Expand Down
65 changes: 62 additions & 3 deletions src/Components/ColumnMiddle/ScrollDownButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,80 @@
import React from 'react';
import PropTypes from 'prop-types';
import ArrowDownwardIcon from '@material-ui/icons/ArrowDownward';
import Badge from '@material-ui/core/Badge';
import IconButton from '@material-ui/core/IconButton';
import ChatStore from '../../Stores/ChatStore';
import './ScrollDownButton.css';
import { getChatUnreadCount } from '../../Utils/Chat';

class ScrollDownButton extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
const {
chatId,
chatList
} = this.props;

if (nextProps.chatId !== chatId) {
return true;
}

if (nextProps.chatList !== chatList) {
return true;
}

return false;
}

componentDidMount() {
ChatStore.on('clientUpdateFastUpdatingComplete', this.onFastUpdatingComplete);
ChatStore.on('updateChatIsMarkedAsUnread', this.onUpdate);
ChatStore.on('updateChatReadInbox', this.onUpdate);
ChatStore.on('updateChatLastMessage', this.onUpdate);
ChatStore.on('updateChatReadOutbox', this.onUpdate);
ChatStore.on('updateChatUnreadMentionCount', this.onUpdate);
ChatStore.on('updateMessageMentionRead', this.onUpdate);
}

componentWillUnmount() {
ChatStore.on('clientUpdateFastUpdatingComplete', this.onFastUpdatingComplete);
ChatStore.on('updateChatIsMarkedAsUnread', this.onUpdate);
ChatStore.on('updateChatReadInbox', this.onUpdate);
ChatStore.on('updateChatLastMessage', this.onUpdate);
ChatStore.on('updateChatReadOutbox', this.onUpdate);
ChatStore.on('updateChatUnreadMentionCount', this.onUpdate);
ChatStore.on('updateMessageMentionRead', this.onUpdate);
}


render() {
const { onClick } = this.props;
const { chatId } = this.props;

const unreadCount = getChatUnreadCount(chatId);

return (
<div className='scroll-down-button'>
<IconButton disableRipple={true} onMouseDown={onClick}>
<ArrowDownwardIcon />
</IconButton>
<Badge badgeContent={unreadCount || 0} color="primary" overlap="circle">
<IconButton disableRipple={true} onMouseDown={onClick}>
<ArrowDownwardIcon />
</IconButton>
</Badge>
</div>
);
}

onFastUpdatingComplete = update => {
this.forceUpdate();
};

onUpdate = update => {
const { chatId } = this.props;

if (update.chat_id !== chatId) return;

this.forceUpdate();
};

}

ScrollDownButton.propTypes = {
Expand Down
18 changes: 18 additions & 0 deletions src/Utils/Chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,15 @@ function showChatUnreadMentionCount(chatId) {
return unread_mention_count > 0;
}

export function getChatUnreadMentionCount(chatId) {
const chat = ChatStore.get(chatId);
if (!chat) return false;

const { unread_mention_count } = chat;

return unread_mention_count;
}

function showChatUnreadCount(chatId) {
const chat = ChatStore.get(chatId);
if (!chat) return false;
Expand All @@ -542,6 +551,15 @@ function showChatUnreadCount(chatId) {
);
}

export function getChatUnreadCount(chatId) {
const chat = ChatStore.get(chatId);
if (!chat) return false;

const { unread_count } = chat;

return unread_count;
}

function isChatUnread(chatId) {
const chat = ChatStore.get(chatId);
if (!chat) return false;
Expand Down