Skip to content

Commit

Permalink
Only clear channel notifications when have an active session
Browse files Browse the repository at this point in the history
  • Loading branch information
davidisaaclee committed Feb 6, 2025
1 parent 7398b56 commit 686ba3a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/app/lib/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,16 @@ const channelIdFromNotification = (notif: Notifications.Notification) => {
* Imprecise method to sync internal unreads with presented notifications.
* We should move to a serverside badge + dismiss notification system, and remove this.
*/
async function updatePresentedNotifications(badgeCount?: number) {
async function updatePresentedNotifications() {
if (store.getSession()?.channelStatus !== 'active') {
// If the session is not active, we can't be sure that our "fully-read"
// status is up-to-date - e.g. we may have messages that we've received
// over notifications, but which are not yet synced, in which case the DB
// looks like we're fully-read, but we have message notifications that we
// don't want to dismiss.
return;
}

const presentedNotifs = await Notifications.getPresentedNotificationsAsync();
const allChannelIds = new Set(
compact(presentedNotifs.map(channelIdFromNotification))
Expand Down Expand Up @@ -131,7 +140,7 @@ async function updatePresentedNotifications(badgeCount?: number) {
export function useUpdatePresentedNotifications() {
const { data: unreadCount } = store.useUnreadsCountWithoutMuted();
useEffect(() => {
updatePresentedNotifications(unreadCount).catch((err) => {
updatePresentedNotifications().catch((err) => {
console.error('Failed to update presented notifications:', err);
});
}, [unreadCount]);
Expand Down

0 comments on commit 686ba3a

Please sign in to comment.