-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13600 from Expensify/tgolen-fix-unread-count-on-s…
…ignout Fix the unread count not going away when you've signed out
- Loading branch information
Showing
8 changed files
with
26 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,14 @@ | ||
import _ from 'underscore'; | ||
import Onyx from 'react-native-onyx'; | ||
import ONYXKEYS from '../../ONYXKEYS'; | ||
import updateUnread from './updateUnread'; | ||
import updateUnread from './updateUnread/index'; | ||
import * as ReportUtils from '../ReportUtils'; | ||
|
||
const reports = {}; | ||
|
||
/** | ||
* Updates the title and favicon of the current browser tab and Mac OS or iOS dock icon with an unread indicator. | ||
* Note: We are throttling this since listening for report changes can trigger many updates depending on how many reports | ||
* a user has and how often they are updated. | ||
*/ | ||
const throttledUpdatePageTitleAndUnreadCount = _.throttle(() => { | ||
const totalCount = _.filter(reports, ReportUtils.isUnread).length; | ||
updateUnread(totalCount); | ||
}, 100, {leading: false}); | ||
|
||
let connectionID; | ||
|
||
/** | ||
* Bind to the report collection key and update | ||
* the title and unread count indicators | ||
*/ | ||
function listenForReportChanges() { | ||
connectionID = Onyx.connect({ | ||
key: ONYXKEYS.COLLECTION.REPORT, | ||
callback: (report) => { | ||
if (!report || !report.reportID) { | ||
return; | ||
} | ||
|
||
reports[report.reportID] = report; | ||
throttledUpdatePageTitleAndUnreadCount(); | ||
}, | ||
}); | ||
} | ||
|
||
/** | ||
* Remove the subscription callback when we no longer need it. | ||
*/ | ||
function stopListeningForReportChanges() { | ||
if (!connectionID) { | ||
return; | ||
} | ||
|
||
Onyx.disconnect(connectionID); | ||
} | ||
|
||
export default { | ||
listenForReportChanges, | ||
stopListeningForReportChanges, | ||
throttledUpdatePageTitleAndUnreadCount, | ||
}; | ||
Onyx.connect({ | ||
key: ONYXKEYS.COLLECTION.REPORT, | ||
waitForCollectionCallback: true, | ||
callback: (reportsFromOnyx) => { | ||
const unreadReports = _.filter(reportsFromOnyx, ReportUtils.isUnread); | ||
updateUnread(_.size(unreadReports)); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters