MOBILE-2795 notifications: Refresh list when mark all as read

main
Dani Palou 2019-01-04 14:26:53 +01:00
parent c41cb6bb19
commit 987ff6ad43
1 changed files with 10 additions and 6 deletions

View File

@ -139,13 +139,15 @@ export class AddonNotificationsListPage {
this.loadingMarkAllNotificationsAsRead = true; this.loadingMarkAllNotificationsAsRead = true;
this.notificationsProvider.markAllNotificationsAsRead().catch(() => { this.notificationsProvider.markAllNotificationsAsRead().catch(() => {
// Omit failure. // Omit failure.
}).finally(() => { }).then(() => {
const siteId = this.sitesProvider.getCurrentSiteId(); const siteId = this.sitesProvider.getCurrentSiteId();
this.eventsProvider.trigger(AddonNotificationsProvider.READ_CHANGED_EVENT, null, siteId); this.eventsProvider.trigger(AddonNotificationsProvider.READ_CHANGED_EVENT, null, siteId);
this.notificationsProvider.getUnreadNotificationsCount().then((unread) => { // All marked as read, refresh the list.
this.canMarkAllNotificationsAsRead = unread > 0; this.notificationsLoaded = false;
this.loadingMarkAllNotificationsAsRead = false;
return this.refreshNotifications().finally(() => {
this.notificationsLoaded = true;
}); });
}); });
} }
@ -182,6 +184,7 @@ export class AddonNotificationsListPage {
return this.notificationsProvider.getUnreadNotificationsCount().then((unread) => { return this.notificationsProvider.getUnreadNotificationsCount().then((unread) => {
this.canMarkAllNotificationsAsRead = unread > 0; this.canMarkAllNotificationsAsRead = unread > 0;
}).finally(() => {
this.loadingMarkAllNotificationsAsRead = false; this.loadingMarkAllNotificationsAsRead = false;
}); });
} }
@ -193,9 +196,10 @@ export class AddonNotificationsListPage {
* Refresh notifications. * Refresh notifications.
* *
* @param {any} [refresher] Refresher. * @param {any} [refresher] Refresher.
* @return Promise<any> Promise resolved when done.
*/ */
refreshNotifications(refresher?: any): void { refreshNotifications(refresher?: any): Promise<any> {
this.notificationsProvider.invalidateNotificationsList().finally(() => { return this.notificationsProvider.invalidateNotificationsList().finally(() => {
return this.fetchNotifications(true).finally(() => { return this.fetchNotifications(true).finally(() => {
if (refresher) { if (refresher) {
refresher.complete(); refresher.complete();