Skip to content

Commit 8a5cf2d

Browse files
authored
Merge pull request #4773 from parasharrajat/markercount
Fix MarkerBadge Count
2 parents 95bf36d + 968fcff commit 8a5cf2d

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

src/pages/home/report/ReportActionsView.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class ReportActionsView extends React.Component {
100100
this.state = {
101101
isLoadingMoreChats: false,
102102
isMarkerActive: false,
103+
localUnreadActionCount: this.props.report.unreadActionCount,
103104
};
104105

105106
this.currentScrollOffset = 0;
@@ -110,6 +111,7 @@ class ReportActionsView extends React.Component {
110111
this.showMarker = this.showMarker.bind(this);
111112
this.hideMarker = this.hideMarker.bind(this);
112113
this.toggleMarker = this.toggleMarker.bind(this);
114+
this.updateLocalUnreadActionCount = this.updateLocalUnreadActionCount.bind(this);
113115
}
114116

115117
componentDidMount() {
@@ -162,6 +164,10 @@ class ReportActionsView extends React.Component {
162164
return true;
163165
}
164166

167+
if (nextState.localUnreadActionCount !== this.state.localUnreadActionCount) {
168+
return true;
169+
}
170+
165171
if (this.props.isSmallScreenWidth !== nextProps.isSmallScreenWidth) {
166172
return true;
167173
}
@@ -200,8 +206,16 @@ class ReportActionsView extends React.Component {
200206
updateLastReadActionID(this.props.reportID);
201207
}
202208

203-
// show new MarkerBadge when there is a new Message
204-
this.toggleMarker();
209+
if (lodashGet(lastAction, 'actorEmail', '') !== lodashGet(this.props.session, 'email', '')) {
210+
// Only update the unread count when MarkerBadge is visible
211+
// Otherwise marker will be shown on scrolling up from the bottom even if user have read those messages
212+
if (this.state.isMarkerActive) {
213+
this.updateLocalUnreadActionCount();
214+
}
215+
216+
// show new MarkerBadge when there is a new message
217+
this.toggleMarker();
218+
}
205219
}
206220

207221
// We want to mark the unread comments when user resize the screen to desktop
@@ -363,7 +377,9 @@ class ReportActionsView extends React.Component {
363377
* Show/hide the new MarkerBadge when user is scrolling back/forth in the history of messages.
364378
*/
365379
toggleMarker() {
380+
// Update the unread message count before MarkerBadge is about to show
366381
if (this.currentScrollOffset < -200 && !this.state.isMarkerActive) {
382+
this.updateLocalUnreadActionCount();
367383
this.showMarker();
368384
}
369385

@@ -372,6 +388,13 @@ class ReportActionsView extends React.Component {
372388
}
373389
}
374390

391+
/**
392+
* Update the unread messages count to show in the MarkerBadge
393+
*/
394+
updateLocalUnreadActionCount() {
395+
this.setState(prevState => ({localUnreadActionCount: prevState.localUnreadActionCount + this.props.report.unreadActionCount}));
396+
}
397+
375398
/**
376399
* Show the new MarkerBadge
377400
*/
@@ -383,7 +406,9 @@ class ReportActionsView extends React.Component {
383406
* Hide the new MarkerBadge
384407
*/
385408
hideMarker() {
386-
this.setState({isMarkerActive: false});
409+
this.setState({isMarkerActive: false}, () => {
410+
this.setState({localUnreadActionCount: 0});
411+
});
387412
}
388413

389414
/**
@@ -487,7 +512,7 @@ class ReportActionsView extends React.Component {
487512
<>
488513
<MarkerBadge
489514
active={this.state.isMarkerActive}
490-
count={this.props.report.unreadActionCount}
515+
count={this.state.localUnreadActionCount}
491516
onClick={scrollToBottom}
492517
onClose={this.hideMarker}
493518
/>

0 commit comments

Comments
 (0)