From 01fd05a16858f29c5c2419bb6de3cc49c72b01f4 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 3 Jan 2019 08:37:33 +0100 Subject: [PATCH] MOBILE-2630 message: Always try to fetch contacts and requests --- .../confirmed-contacts/confirmed-contacts.ts | 19 +++++++++++++++---- .../contact-requests/contact-requests.ts | 19 +++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/addon/messages/components/confirmed-contacts/confirmed-contacts.ts b/src/addon/messages/components/confirmed-contacts/confirmed-contacts.ts index f7efb6f76..528b48a9a 100644 --- a/src/addon/messages/components/confirmed-contacts/confirmed-contacts.ts +++ b/src/addon/messages/components/confirmed-contacts/confirmed-contacts.ts @@ -87,8 +87,20 @@ export class AddonMessagesConfirmedContactsComponent implements OnInit, OnDestro this.loadMoreError = false; const limitFrom = refresh ? 0 : this.contacts.length; + let promise; - return this.messagesProvider.getUserContacts(limitFrom).then((result) => { + if (limitFrom === 0) { + // Always try to get latest data from server. + promise = this.messagesProvider.invalidateUserContacts().catch(() => { + // Shouldn't happen. + }); + } else { + promise = Promise.resolve(); + } + + return promise.then(() => { + return this.messagesProvider.getUserContacts(limitFrom); + }).then((result) => { this.contacts = refresh ? result.contacts : this.contacts.concat(result.contacts); this.canLoadMore = result.canLoadMore; }).catch((error) => { @@ -104,9 +116,8 @@ export class AddonMessagesConfirmedContactsComponent implements OnInit, OnDestro * @return {Promise} Promise resolved when done. */ refreshData(refresher?: any): Promise { - return this.messagesProvider.invalidateUserContacts().then(() => { - return this.fetchData(true); - }).finally(() => { + // No need to invalidate contacts, we always try to get the latest. + return this.fetchData(true).finally(() => { refresher && refresher.complete(); }); } diff --git a/src/addon/messages/components/contact-requests/contact-requests.ts b/src/addon/messages/components/contact-requests/contact-requests.ts index 854bd90bb..4a77bfdd1 100644 --- a/src/addon/messages/components/contact-requests/contact-requests.ts +++ b/src/addon/messages/components/contact-requests/contact-requests.ts @@ -78,8 +78,20 @@ export class AddonMessagesContactRequestsComponent implements OnInit, OnDestroy this.loadMoreError = false; const limitFrom = refresh ? 0 : this.requests.length; + let promise; - return this.messagesProvider.getContactRequests(limitFrom).then((result) => { + if (limitFrom === 0) { + // Always try to get latest data from server. + promise = this.messagesProvider.invalidateContactRequestsCache().catch(() => { + // Shouldn't happen. + }); + } else { + promise = Promise.resolve(); + } + + return promise.then(() => { + return this.messagesProvider.getContactRequests(limitFrom); + }).then((result) => { this.requests = refresh ? result.requests : this.requests.concat(result.requests); this.canLoadMore = result.canLoadMore; }).catch((error) => { @@ -98,9 +110,8 @@ export class AddonMessagesContactRequestsComponent implements OnInit, OnDestroy // Refresh the number of contacts requests to update badges. this.messagesProvider.refreshContactRequestsCount(); - return this.messagesProvider.invalidateContactRequestsCache().then(() => { - return this.fetchData(true); - }).finally(() => { + // No need to invalidate contact requests, we always try to get the latest. + return this.fetchData(true).finally(() => { refresher && refresher.complete(); }); }