@@ -177,8 +177,7 @@ function ReportActionsList({
177
177
const userActiveSince = useRef < string | null > ( null ) ;
178
178
const lastMessageTime = useRef < string | null > ( null ) ;
179
179
180
- const [ isVisible , setIsVisible ] = useState ( Visibility . isVisible ( ) ) ;
181
- const hasCalledReadNewestAction = useRef ( false ) ;
180
+ const [ isVisible , setIsVisible ] = useState ( false ) ;
182
181
const isFocused = useIsFocused ( ) ;
183
182
184
183
useEffect ( ( ) => {
@@ -268,17 +267,13 @@ function ReportActionsList({
268
267
if ( ! userActiveSince . current || report . reportID !== prevReportID ) {
269
268
return ;
270
269
}
271
- if ( hasCalledReadNewestAction . current ) {
272
- return ;
273
- }
274
270
if ( ReportUtils . isUnread ( report ) ) {
275
271
// On desktop, when the notification center is displayed, Visibility.isVisible() will return false.
276
272
// Currently, there's no programmatic way to dismiss the notification center panel.
277
273
// To handle this, we use the 'referrer' parameter to check if the current navigation is triggered from a notification.
278
274
const isFromNotification = route ?. params ?. referrer === CONST . REFERRER . NOTIFICATION ;
279
275
if ( ( Visibility . isVisible ( ) || isFromNotification ) && scrollingVerticalOffset . current < MSG_VISIBLE_THRESHOLD ) {
280
276
Report . readNewestAction ( report . reportID ) ;
281
- hasCalledReadNewestAction . current = true ;
282
277
if ( isFromNotification ) {
283
278
Navigation . setParams ( { referrer : undefined } ) ;
284
279
}
@@ -529,10 +524,6 @@ function ReportActionsList({
529
524
return ;
530
525
}
531
526
532
- if ( hasCalledReadNewestAction . current ) {
533
- return ;
534
- }
535
-
536
527
if ( ! isVisible || ! isFocused ) {
537
528
if ( ! lastMessageTime . current ) {
538
529
lastMessageTime . current = sortedVisibleReportActions [ 0 ] ?. created ?? '' ;
@@ -544,27 +535,24 @@ function ReportActionsList({
544
535
// show marker based on report.lastReadTime
545
536
const newMessageTimeReference = lastMessageTime . current && report . lastReadTime && lastMessageTime . current > report . lastReadTime ? userActiveSince . current : report . lastReadTime ;
546
537
lastMessageTime . current = null ;
547
- const areSomeReportActionsUnread = sortedVisibleReportActions . some ( ( reportAction ) => {
548
- /**
549
- * The archived reports should not be marked as unread. So we are checking if the report is archived or not.
550
- * If the report is archived, we will mark the report as read.
551
- */
552
- const isArchivedReport = ReportUtils . isArchivedRoom ( report ) ;
553
- const isUnread = isArchivedReport || ( newMessageTimeReference && newMessageTimeReference < reportAction . created ) ;
554
- return (
555
- isUnread && ( ReportActionsUtils . isReportPreviewAction ( reportAction ) ? reportAction . childLastActorAccountID : reportAction . actorAccountID ) !== Report . getCurrentUserAccountID ( )
556
- ) ;
557
- } ) ;
558
- if ( scrollingVerticalOffset . current >= MSG_VISIBLE_THRESHOLD || ! areSomeReportActionsUnread ) {
538
+ if (
539
+ scrollingVerticalOffset . current >= MSG_VISIBLE_THRESHOLD ||
540
+ ! sortedVisibleReportActions . some (
541
+ ( reportAction ) =>
542
+ newMessageTimeReference &&
543
+ newMessageTimeReference < reportAction . created &&
544
+ ( ReportActionsUtils . isReportPreviewAction ( reportAction ) ? reportAction . childLastActorAccountID : reportAction . actorAccountID ) !== Report . getCurrentUserAccountID ( ) ,
545
+ )
546
+ ) {
559
547
return ;
560
548
}
549
+
561
550
Report . readNewestAction ( report . reportID ) ;
562
551
userActiveSince . current = DateUtils . getDBTime ( ) ;
563
552
lastReadTimeRef . current = newMessageTimeReference ;
564
553
setCurrentUnreadMarker ( null ) ;
565
554
cacheUnreadMarkers . delete ( report . reportID ) ;
566
555
calculateUnreadMarker ( ) ;
567
- hasCalledReadNewestAction . current = true ;
568
556
569
557
// This effect logic to `mark as read` will only run when the report focused has new messages and the App visibility
570
558
// is changed to visible(meaning user switched to app/web, while user was previously using different tab or application).
0 commit comments