From 987ff6ad439996a0ca1d6a1b838d82e96b4964f8 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 4 Jan 2019 14:26:53 +0100 Subject: [PATCH] MOBILE-2795 notifications: Refresh list when mark all as read --- src/addon/notifications/pages/list/list.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/addon/notifications/pages/list/list.ts b/src/addon/notifications/pages/list/list.ts index 3d0d5aa85..62add77ad 100644 --- a/src/addon/notifications/pages/list/list.ts +++ b/src/addon/notifications/pages/list/list.ts @@ -139,13 +139,15 @@ export class AddonNotificationsListPage { this.loadingMarkAllNotificationsAsRead = true; this.notificationsProvider.markAllNotificationsAsRead().catch(() => { // Omit failure. - }).finally(() => { + }).then(() => { const siteId = this.sitesProvider.getCurrentSiteId(); this.eventsProvider.trigger(AddonNotificationsProvider.READ_CHANGED_EVENT, null, siteId); - this.notificationsProvider.getUnreadNotificationsCount().then((unread) => { - this.canMarkAllNotificationsAsRead = unread > 0; - this.loadingMarkAllNotificationsAsRead = false; + // All marked as read, refresh the list. + this.notificationsLoaded = false; + + return this.refreshNotifications().finally(() => { + this.notificationsLoaded = true; }); }); } @@ -182,6 +184,7 @@ export class AddonNotificationsListPage { return this.notificationsProvider.getUnreadNotificationsCount().then((unread) => { this.canMarkAllNotificationsAsRead = unread > 0; + }).finally(() => { this.loadingMarkAllNotificationsAsRead = false; }); } @@ -193,9 +196,10 @@ export class AddonNotificationsListPage { * Refresh notifications. * * @param {any} [refresher] Refresher. + * @return Promise Promise resolved when done. */ - refreshNotifications(refresher?: any): void { - this.notificationsProvider.invalidateNotificationsList().finally(() => { + refreshNotifications(refresher?: any): Promise { + return this.notificationsProvider.invalidateNotificationsList().finally(() => { return this.fetchNotifications(true).finally(() => { if (refresher) { refresher.complete();