diff --git a/src/addon/messages/providers/mainmenu-handler.ts b/src/addon/messages/providers/mainmenu-handler.ts index 0e530613a..4b83ae499 100644 --- a/src/addon/messages/providers/mainmenu-handler.ts +++ b/src/addon/messages/providers/mainmenu-handler.ts @@ -76,7 +76,8 @@ export class AddonMessagesMainMenuHandler implements CoreMainMenuHandler, CoreCr // If a message push notification is received, refresh the count. pushNotificationsDelegate.on('receive').subscribe((notification) => { // New message received. If it's from current site, refresh the data. - if (utils.isFalseOrZero(notification.notif) && this.sitesProvider.isCurrentSite(notification.site)) { + const isMessage = utils.isFalseOrZero(notification.notif) || notification.name == 'messagecontactrequests'; + if (isMessage && this.sitesProvider.isCurrentSite(notification.site)) { this.refreshBadge(notification.site); } }); diff --git a/src/addon/messages/providers/messages.ts b/src/addon/messages/providers/messages.ts index c81d27e65..6bf99d882 100644 --- a/src/addon/messages/providers/messages.ts +++ b/src/addon/messages/providers/messages.ts @@ -1863,16 +1863,19 @@ export class AddonMessagesProvider { /** * Mark message as read. * - * @param {number} messageId ID of message to mark as read + * @param {number} messageId ID of message to mark as read + * @param {string} [siteId] Site ID. If not defined, current site. * @returns {Promise} Promise resolved with boolean marking success or not. */ - markMessageRead(messageId: number): Promise { - const params = { - messageid: messageId, - timeread: this.timeUtils.timestamp() - }; + markMessageRead(messageId: number, siteId?: string): Promise { + return this.sitesProvider.getSite(siteId).then((site) => { + const params = { + messageid: messageId, + timeread: this.timeUtils.timestamp() + }; - return this.sitesProvider.getCurrentSite().write('core_message_mark_message_read', params); + return site.write('core_message_mark_message_read', params); + }); } /** diff --git a/src/addon/notifications/providers/notifications.ts b/src/addon/notifications/providers/notifications.ts index ebe5a1359..1b9219fe8 100644 --- a/src/addon/notifications/providers/notifications.ts +++ b/src/addon/notifications/providers/notifications.ts @@ -262,23 +262,25 @@ export class AddonNotificationsProvider { * Mark a single notification as read. * * @param {number} notificationId ID of notification to mark as read + * @param {string} [siteId] Site ID. If not defined, current site. * @returns {Promise} Resolved when done. * @since 3.5 */ - markNotificationRead(notificationId: number): Promise { - const currentSite = this.sitesProvider.getCurrentSite(); + markNotificationRead(notificationId: number, siteId?: string): Promise { + return this.sitesProvider.getSite(siteId).then((site) => { - if (currentSite.wsAvailable('core_message_mark_notification_read')) { - const params = { - notificationid: notificationId, - timeread: this.timeUtils.timestamp() - }; + if (site.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); - } + return site.write('core_message_mark_notification_read', params); + } else { + // Fallback for versions prior to 3.5. + return this.messageProvider.markMessageRead(notificationId, site.id); + } + }); } /** diff --git a/src/addon/notifications/providers/push-click-handler.ts b/src/addon/notifications/providers/push-click-handler.ts index 74baeaa4d..4d8d2f382 100644 --- a/src/addon/notifications/providers/push-click-handler.ts +++ b/src/addon/notifications/providers/push-click-handler.ts @@ -13,6 +13,7 @@ // limitations under the License. import { Injectable } from '@angular/core'; +import { CoreEventsProvider } from '@providers/events'; import { CoreUtilsProvider } from '@providers/utils/utils'; import { CorePushNotificationsClickHandler } from '@core/pushnotifications/providers/delegate'; import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper'; @@ -28,7 +29,7 @@ export class AddonNotificationsPushClickHandler implements CorePushNotifications featureName = 'CoreMainMenuDelegate_AddonNotifications'; constructor(private utils: CoreUtilsProvider, private notificationsProvider: AddonNotificationsProvider, - private linkHelper: CoreContentLinksHelperProvider) {} + private linkHelper: CoreContentLinksHelperProvider, private eventsProvider: CoreEventsProvider) {} /** * Check if a notification click is handled by this handler. @@ -37,7 +38,18 @@ export class AddonNotificationsPushClickHandler implements CorePushNotifications * @return {boolean} Whether the notification click is handled by this handler */ handles(notification: any): boolean | Promise { - return this.utils.isTrueOrOne(notification.notif); + if (this.utils.isTrueOrOne(notification.notif)) { + // Notification clicked, mark as read. Don't block for this. + this.notificationsProvider.markNotificationRead(notification.savedmessageid, notification.site).then(() => { + this.eventsProvider.trigger(AddonNotificationsProvider.READ_CHANGED_EVENT, null, notification.site); + }).catch(() => { + // Ignore errors. + }); + + return true; + } + + return false; } /**