MOBILE-2795 notifications: Mark as read on versions greater than 3.5

main
Pau Ferrer Ocaña 2019-01-08 12:07:19 +01:00
parent 74cbeb403a
commit 65b6b98c6e
1 changed files with 16 additions and 7 deletions

View File

@ -19,6 +19,7 @@ import { CoreSitesProvider } from '@providers/sites';
import { CoreTimeUtilsProvider } from '@providers/utils/time'; import { CoreTimeUtilsProvider } from '@providers/utils/time';
import { CoreUserProvider } from '@core/user/providers/user'; import { CoreUserProvider } from '@core/user/providers/user';
import { CoreEmulatorHelperProvider } from '@core/emulator/providers/helper'; import { CoreEmulatorHelperProvider } from '@core/emulator/providers/helper';
import { AddonMessagesProvider } from '@addon/messages/providers/messages';
/** /**
* Service to handle notifications. * Service to handle notifications.
@ -36,7 +37,7 @@ export class AddonNotificationsProvider {
constructor(logger: CoreLoggerProvider, private appProvider: CoreAppProvider, private sitesProvider: CoreSitesProvider, constructor(logger: CoreLoggerProvider, private appProvider: CoreAppProvider, private sitesProvider: CoreSitesProvider,
private timeUtils: CoreTimeUtilsProvider, private userProvider: CoreUserProvider, private timeUtils: CoreTimeUtilsProvider, private userProvider: CoreUserProvider,
private emulatorHelper: CoreEmulatorHelperProvider) { private emulatorHelper: CoreEmulatorHelperProvider, private messageProvider: AddonMessagesProvider) {
this.logger = logger.getInstance('AddonNotificationsProvider'); 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 * @param {number} notificationId ID of notification to mark as read
* @returns {Promise<any>} Resolved when done. * @returns {Promise<any>} Resolved when done.
* @since 3.5
*/ */
markNotificationRead(notificationId: number): Promise<any> { markNotificationRead(notificationId: number): Promise<any> {
const currentSite = this.sitesProvider.getCurrentSite();
if (currentSite.wsAvailable('core_message_mark_notification_read')) {
const params = { const params = {
messageid: notificationId, notificationid: notificationId,
timeread: this.timeUtils.timestamp() timeread: this.timeUtils.timestamp()
}; };
return this.sitesProvider.getCurrentSite().write('core_message_mark_message_read', params); return currentSite.write('core_message_mark_notification_read', params);
} else {
// Fallback for versions prior to 3.5.
return this.messageProvider.markMessageRead(notificationId);
}
} }
/** /**