MOBILE-2921 notification: Mark as read when push clicked
parent
34d77d8d14
commit
881b7675cf
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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<any>} Promise resolved with boolean marking success or not.
|
||||
*/
|
||||
markMessageRead(messageId: number): Promise<any> {
|
||||
const params = {
|
||||
messageid: messageId,
|
||||
timeread: this.timeUtils.timestamp()
|
||||
};
|
||||
markMessageRead(messageId: number, siteId?: string): Promise<any> {
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<any>} Resolved when done.
|
||||
* @since 3.5
|
||||
*/
|
||||
markNotificationRead(notificationId: number): Promise<any> {
|
||||
const currentSite = this.sitesProvider.getCurrentSite();
|
||||
markNotificationRead(notificationId: number, siteId?: string): Promise<any> {
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<boolean> {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue