From 9f2d0a40aab46f7b9e126829cae2de055323ffca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Tue, 8 Jan 2019 10:33:09 +0100 Subject: [PATCH 1/3] MOBILE-2795 forum: Error when navigating to invalid discussion --- src/addon/mod/forum/pages/discussion/discussion.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/addon/mod/forum/pages/discussion/discussion.ts b/src/addon/mod/forum/pages/discussion/discussion.ts index e652dab7c..16d5537b2 100644 --- a/src/addon/mod/forum/pages/discussion/discussion.ts +++ b/src/addon/mod/forum/pages/discussion/discussion.ts @@ -253,6 +253,10 @@ export class AddonModForumDiscussionPage implements OnDestroy { const posts = offlineReplies.concat(onlinePosts); this.discussion = this.forumProvider.extractStartingPost(posts); + if (!this.discussion) { + return Promise.reject('Invalid forum discussion'); + } + // If sort type is nested, normal sorting is disabled and nested posts will be displayed. if (this.sort == 'nested') { // Sort first by creation date to make format tree work. 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 2/3] 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 From 65b6b98c6e3f1559a827d0191c3b140e3ca6fca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Tue, 8 Jan 2019 12:07:19 +0100 Subject: [PATCH 3/3] MOBILE-2795 notifications: Mark as read on versions greater than 3.5 --- .../notifications/providers/notifications.ts | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/addon/notifications/providers/notifications.ts b/src/addon/notifications/providers/notifications.ts index 68ad278a2..ebe5a1359 100644 --- a/src/addon/notifications/providers/notifications.ts +++ b/src/addon/notifications/providers/notifications.ts @@ -19,6 +19,7 @@ import { CoreSitesProvider } from '@providers/sites'; import { CoreTimeUtilsProvider } from '@providers/utils/time'; import { CoreUserProvider } from '@core/user/providers/user'; import { CoreEmulatorHelperProvider } from '@core/emulator/providers/helper'; +import { AddonMessagesProvider } from '@addon/messages/providers/messages'; /** * Service to handle notifications. @@ -36,7 +37,7 @@ export class AddonNotificationsProvider { constructor(logger: CoreLoggerProvider, private appProvider: CoreAppProvider, private sitesProvider: CoreSitesProvider, private timeUtils: CoreTimeUtilsProvider, private userProvider: CoreUserProvider, - private emulatorHelper: CoreEmulatorHelperProvider) { + private emulatorHelper: CoreEmulatorHelperProvider, private messageProvider: AddonMessagesProvider) { this.logger = logger.getInstance('AddonNotificationsProvider'); } @@ -258,18 +259,26 @@ export class AddonNotificationsProvider { } /** - * Mark message notification as read. + * Mark a single notification as read. * * @param {number} notificationId ID of notification to mark as read * @returns {Promise} Resolved when done. + * @since 3.5 */ markNotificationRead(notificationId: number): Promise { - const params = { - messageid: notificationId, - timeread: this.timeUtils.timestamp() - }; + const currentSite = this.sitesProvider.getCurrentSite(); - return this.sitesProvider.getCurrentSite().write('core_message_mark_message_read', params); + if (currentSite.wsAvailable('core_message_mark_notification_read')) { + const params = { + notificationid: notificationId, + timeread: this.timeUtils.timestamp() + }; + + return currentSite.write('core_message_mark_notification_read', params); + } else { + // Fallback for versions prior to 3.5. + return this.messageProvider.markMessageRead(notificationId); + } } /**