-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix: notification count for empty reports #30133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b0c9b95
90c915b
15294be
7fba759
208d572
d5391d9
04119fd
b5987fe
1cdb174
50580cb
5bff1bd
59cfe6f
bbe1a98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,38 +1,29 @@ | ||
| import {InteractionManager} from 'react-native'; | ||
| import Onyx from 'react-native-onyx'; | ||
| import _ from 'underscore'; | ||
| import * as ReportUtils from '@libs/ReportUtils'; | ||
| import CONST from '@src/CONST'; | ||
| import Navigation, {navigationRef} from '@navigation/Navigation'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import updateUnread from './updateUnread/index'; | ||
|
|
||
| let previousUnreadCount = 0; | ||
| let allReports = []; | ||
|
|
||
| const triggerUnreadUpdate = () => { | ||
| const currentReportID = navigationRef.isReady() ? Navigation.getTopmostReportId() : ''; | ||
|
|
||
| // We want to keep notification count consistent with what can be accessed from the LHN list | ||
| const unreadReports = _.filter(allReports, (report) => ReportUtils.isUnread(report) && ReportUtils.shouldReportBeInOptionList(report, currentReportID)); | ||
| updateUnread(_.size(unreadReports)); | ||
| }; | ||
|
|
||
| Onyx.connect({ | ||
| key: ONYXKEYS.COLLECTION.REPORT, | ||
| waitForCollectionCallback: true, | ||
| callback: (reportsFromOnyx) => { | ||
| if (!reportsFromOnyx) { | ||
| return; | ||
| } | ||
|
|
||
| /** | ||
| * We need to wait until after interactions have finished to update the unread count because otherwise | ||
| * the unread count will be updated while the interactions/animations are in progress and we don't want | ||
| * to put more work on the main thread. | ||
| * | ||
| * For eg. On web we are manipulating DOM and it makes it a better candidate to wait until after interactions | ||
| * have finished. | ||
| * | ||
| * More info: https://reactnative.dev/docs/interactionmanager | ||
| */ | ||
| InteractionManager.runAfterInteractions(() => { | ||
| const unreadReports = _.filter(reportsFromOnyx, (report) => ReportUtils.isUnread(report) && report.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because we wanted to sync this exactly with the LHN.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know, did we? I summed it up before as... "A notification count should only include threads that are accessible, i.e. can be navigated to". ...in other words... "A notification count should not include threads that are inaccessible, i.e. cannot be navigated to". ...and I stand with this. It's my personal summary based on my understanding of the issue. Notification preferences are a user-accessible feature: We don't want to break this, right? It sounds like a different topic.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is something different. By setting this preference, you're setting if you want to receive a notification for a new message. Changing this won't really effect the count.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In other words, do you suggest that the old code checking for Or maybe that the user setting I added a screenshot of is not actually related to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @marcaaron Im OoO for two more days. I'll raise a PR for this after then if that's fine.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have a GH issue for this mentioned regression?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think #33506 could be regression from this PR.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Would you provide an update? We can move the further discussion to #33506
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PR created already! |
||
| const unreadReportsCount = _.size(unreadReports); | ||
| if (previousUnreadCount !== unreadReportsCount) { | ||
| previousUnreadCount = unreadReportsCount; | ||
| updateUnread(unreadReportsCount); | ||
| } | ||
| }); | ||
| allReports = reportsFromOnyx; | ||
| triggerUnreadUpdate(); | ||
| }, | ||
| }); | ||
|
|
||
| navigationRef.addListener('state', () => { | ||
| triggerUnreadUpdate(); | ||
| }); | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tested this
''case? I understand the defence-in-depth strategy, but I'm not convinced by this specific implementation of it.Maybe...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or
: false, depending on what we want to do in the corner caseThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is in accordance with how we're saving
currentReportIDinCurrentReportIdContextThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok