@@ -100,6 +100,7 @@ class ReportActionsView extends React.Component {
100
100
this . state = {
101
101
isLoadingMoreChats : false ,
102
102
isMarkerActive : false ,
103
+ localUnreadActionCount : this . props . report . unreadActionCount ,
103
104
} ;
104
105
105
106
this . currentScrollOffset = 0 ;
@@ -110,6 +111,7 @@ class ReportActionsView extends React.Component {
110
111
this . showMarker = this . showMarker . bind ( this ) ;
111
112
this . hideMarker = this . hideMarker . bind ( this ) ;
112
113
this . toggleMarker = this . toggleMarker . bind ( this ) ;
114
+ this . updateLocalUnreadActionCount = this . updateLocalUnreadActionCount . bind ( this ) ;
113
115
}
114
116
115
117
componentDidMount ( ) {
@@ -162,6 +164,10 @@ class ReportActionsView extends React.Component {
162
164
return true ;
163
165
}
164
166
167
+ if ( nextState . localUnreadActionCount !== this . state . localUnreadActionCount ) {
168
+ return true ;
169
+ }
170
+
165
171
if ( this . props . isSmallScreenWidth !== nextProps . isSmallScreenWidth ) {
166
172
return true ;
167
173
}
@@ -200,8 +206,16 @@ class ReportActionsView extends React.Component {
200
206
updateLastReadActionID ( this . props . reportID ) ;
201
207
}
202
208
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
+ }
205
219
}
206
220
207
221
// We want to mark the unread comments when user resize the screen to desktop
@@ -363,7 +377,9 @@ class ReportActionsView extends React.Component {
363
377
* Show/hide the new MarkerBadge when user is scrolling back/forth in the history of messages.
364
378
*/
365
379
toggleMarker ( ) {
380
+ // Update the unread message count before MarkerBadge is about to show
366
381
if ( this . currentScrollOffset < - 200 && ! this . state . isMarkerActive ) {
382
+ this . updateLocalUnreadActionCount ( ) ;
367
383
this . showMarker ( ) ;
368
384
}
369
385
@@ -372,6 +388,13 @@ class ReportActionsView extends React.Component {
372
388
}
373
389
}
374
390
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
+
375
398
/**
376
399
* Show the new MarkerBadge
377
400
*/
@@ -383,7 +406,9 @@ class ReportActionsView extends React.Component {
383
406
* Hide the new MarkerBadge
384
407
*/
385
408
hideMarker ( ) {
386
- this . setState ( { isMarkerActive : false } ) ;
409
+ this . setState ( { isMarkerActive : false } , ( ) => {
410
+ this . setState ( { localUnreadActionCount : 0 } ) ;
411
+ } ) ;
387
412
}
388
413
389
414
/**
@@ -487,7 +512,7 @@ class ReportActionsView extends React.Component {
487
512
< >
488
513
< MarkerBadge
489
514
active = { this . state . isMarkerActive }
490
- count = { this . props . report . unreadActionCount }
515
+ count = { this . state . localUnreadActionCount }
491
516
onClick = { scrollToBottom }
492
517
onClose = { this . hideMarker }
493
518
/>
0 commit comments