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] 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); + } } /**