Skip to content

Commit

Permalink
Hot fix the unread count bug on selected conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
rickmak committed Apr 24, 2017
1 parent 39d711a commit 5631d40
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
17 changes: 13 additions & 4 deletions src/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,27 @@ export default class App extends React.Component {
}

updateUnreadCount() {
const {
activeID
} = this.state;
const activeUC = this.userConversationList.get(activeID);
skygearChat.getUnreadCount().then(result => {
// FIXME: activeUC count is always reset to zero for async.
if (activeUC) {
result.message = result.message - activeUC.unread_count;
activeUC.unread_count = 0;
}
this.setState({unreadCount: result.message});
});
}

selectConversation(userConversation) {
const unread_count = userConversation.unread_count;
userConversation.unread_count = 0;
this.setState({
activeID: userConversation._id,
unreadCount: this.state.unreadCount - userConversation.unread_count
unreadCount: this.state.unreadCount - unread_count
});
userConversation.unread_count = 0;
this.updateUnreadCount();
}

render() {
Expand Down Expand Up @@ -100,7 +109,7 @@ export default class App extends React.Component {
return <ConversationPreview
key={'ConversationPreview-' + uc.id + uc.updatedAt}
selected={
uc.id === activeID}
uc._id === activeID}
userConversation={uc}
conversation={uc.$transient.conversation}
onClick={() => this.selectConversation(uc)}/>
Expand Down
5 changes: 4 additions & 1 deletion src/components/ConversationPreview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,17 @@ export default class ConversationPreview extends React.Component {
selected,
onClick,
} = this.props;
const {
let {
unread_count
} = this.props.userConversation;
const {
title,
imageURL
} = this.state;
const lastMessage = this.props.conversation.$transient.last_message;
if (selected) {
unread_count = 0;
}

return (
<div
Expand Down
4 changes: 2 additions & 2 deletions src/utils/ManagedMessageList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ export default class ManagedMessageList {
const {_messages} = this;
if (!_messages.hasOwnProperty(message._id)) {
_messages[message._id] = message;
this._messagesUpdated();
if (this._autoRead) {
this._messagesUpdated();
if (this._autoRead) {
skygearChat.markAsLastMessageRead(this._conversation, message);
}
}
Expand Down

0 comments on commit 5631d40

Please sign in to comment.