From 74cbeb403a32158da268b4fdf4280f7b55067f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Tue, 8 Jan 2019 11:23:47 +0100 Subject: [PATCH] MOBILE-2795 notifications: Show user avatars --- .../notifications/providers/notifications.ts | 29 ++++++++++++------- .../user-avatar/core-user-avatar.html | 3 +- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/addon/notifications/providers/notifications.ts b/src/addon/notifications/providers/notifications.ts index 4bc082d81..68ad278a2 100644 --- a/src/addon/notifications/providers/notifications.ts +++ b/src/addon/notifications/providers/notifications.ts @@ -44,9 +44,10 @@ export class AddonNotificationsProvider { * Function to format notification data. * * @param {any[]} notifications List of notifications. + * @return {Promise} Promise resolved with notifications. */ - protected formatNotificationsData(notifications: any[]): void { - notifications.forEach((notification) => { + protected formatNotificationsData(notifications: any[]): Promise { + const promises = notifications.map((notification) => { // Set message to show. if (notification.contexturl && notification.contexturl.indexOf('/mod/forum/') >= 0) { notification.mobiletext = notification.smallmessage; @@ -60,13 +61,19 @@ export class AddonNotificationsProvider { } if (notification.useridfrom > 0) { // Try to get the profile picture of the user. - this.userProvider.getProfile(notification.useridfrom, notification.courseid, true).then((user) => { + return this.userProvider.getProfile(notification.useridfrom, notification.courseid, true).then((user) => { notification.profileimageurlfrom = user.profileimageurl; + + return notification; }).catch(() => { // Error getting user. This can happen if device is offline or the user is deleted. }); } + + return Promise.resolve(notification); }); + + return Promise.all(promises); } /** @@ -145,14 +152,16 @@ export class AddonNotificationsProvider { return site.read('core_message_get_messages', data, preSets).then((response) => { if (response.messages) { const notifications = response.messages; - this.formatNotificationsData(notifications); - if (this.appProvider.isDesktop() && toDisplay && !read && limitFrom === 0) { - // Store the last received notification. Don't block the user for this. - this.emulatorHelper.storeLastReceivedNotification( - AddonNotificationsProvider.PUSH_SIMULATION_COMPONENT, notifications[0], siteId); - } - return notifications; + return this.formatNotificationsData(notifications).then(() => { + if (this.appProvider.isDesktop() && toDisplay && !read && limitFrom === 0) { + // Store the last received notification. Don't block the user for this. + this.emulatorHelper.storeLastReceivedNotification( + AddonNotificationsProvider.PUSH_SIMULATION_COMPONENT, notifications[0], siteId); + } + + return notifications; + }); } else { return Promise.reject(null); } diff --git a/src/components/user-avatar/core-user-avatar.html b/src/components/user-avatar/core-user-avatar.html index d9b0c7228..4eeffcd06 100644 --- a/src/components/user-avatar/core-user-avatar.html +++ b/src/components/user-avatar/core-user-avatar.html @@ -1,3 +1,4 @@ - + + \ No newline at end of file