MOBILE-2921 notification: Mark as read when push clicked
This commit is contained in:
		
							parent
							
								
									34d77d8d14
								
							
						
					
					
						commit
						881b7675cf
					
				@ -76,7 +76,8 @@ export class AddonMessagesMainMenuHandler implements CoreMainMenuHandler, CoreCr
 | 
				
			|||||||
        // If a message push notification is received, refresh the count.
 | 
					        // If a message push notification is received, refresh the count.
 | 
				
			||||||
        pushNotificationsDelegate.on('receive').subscribe((notification) => {
 | 
					        pushNotificationsDelegate.on('receive').subscribe((notification) => {
 | 
				
			||||||
            // New message received. If it's from current site, refresh the data.
 | 
					            // 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);
 | 
					                this.refreshBadge(notification.site);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
				
			|||||||
@ -1864,15 +1864,18 @@ export class AddonMessagesProvider {
 | 
				
			|||||||
     * Mark message as read.
 | 
					     * 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.
 | 
					     * @returns {Promise<any>} Promise resolved with boolean marking success or not.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    markMessageRead(messageId: number): Promise<any> {
 | 
					    markMessageRead(messageId: number, siteId?: string): Promise<any> {
 | 
				
			||||||
 | 
					        return this.sitesProvider.getSite(siteId).then((site) => {
 | 
				
			||||||
            const params = {
 | 
					            const params = {
 | 
				
			||||||
                messageid: messageId,
 | 
					                messageid: messageId,
 | 
				
			||||||
                timeread: this.timeUtils.timestamp()
 | 
					                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.
 | 
					     * 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
 | 
				
			||||||
 | 
					     * @param {string} [siteId] Site ID. If not defined, current site.
 | 
				
			||||||
     * @returns {Promise<any>} Resolved when done.
 | 
					     * @returns {Promise<any>} Resolved when done.
 | 
				
			||||||
     * @since 3.5
 | 
					     * @since 3.5
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    markNotificationRead(notificationId: number): Promise<any> {
 | 
					    markNotificationRead(notificationId: number, siteId?: string): Promise<any> {
 | 
				
			||||||
        const currentSite = this.sitesProvider.getCurrentSite();
 | 
					        return this.sitesProvider.getSite(siteId).then((site) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (currentSite.wsAvailable('core_message_mark_notification_read')) {
 | 
					            if (site.wsAvailable('core_message_mark_notification_read')) {
 | 
				
			||||||
                const params = {
 | 
					                const params = {
 | 
				
			||||||
                    notificationid: notificationId,
 | 
					                    notificationid: notificationId,
 | 
				
			||||||
                    timeread: this.timeUtils.timestamp()
 | 
					                    timeread: this.timeUtils.timestamp()
 | 
				
			||||||
                };
 | 
					                };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return currentSite.write('core_message_mark_notification_read', params);
 | 
					                return site.write('core_message_mark_notification_read', params);
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                // Fallback for versions prior to 3.5.
 | 
					                // Fallback for versions prior to 3.5.
 | 
				
			||||||
            return this.messageProvider.markMessageRead(notificationId);
 | 
					                return this.messageProvider.markMessageRead(notificationId, site.id);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
				
			|||||||
@ -13,6 +13,7 @@
 | 
				
			|||||||
// limitations under the License.
 | 
					// limitations under the License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { Injectable } from '@angular/core';
 | 
					import { Injectable } from '@angular/core';
 | 
				
			||||||
 | 
					import { CoreEventsProvider } from '@providers/events';
 | 
				
			||||||
import { CoreUtilsProvider } from '@providers/utils/utils';
 | 
					import { CoreUtilsProvider } from '@providers/utils/utils';
 | 
				
			||||||
import { CorePushNotificationsClickHandler } from '@core/pushnotifications/providers/delegate';
 | 
					import { CorePushNotificationsClickHandler } from '@core/pushnotifications/providers/delegate';
 | 
				
			||||||
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
 | 
					import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
 | 
				
			||||||
@ -28,7 +29,7 @@ export class AddonNotificationsPushClickHandler implements CorePushNotifications
 | 
				
			|||||||
    featureName = 'CoreMainMenuDelegate_AddonNotifications';
 | 
					    featureName = 'CoreMainMenuDelegate_AddonNotifications';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructor(private utils: CoreUtilsProvider, private notificationsProvider: AddonNotificationsProvider,
 | 
					    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.
 | 
					     * 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
 | 
					     * @return {boolean} Whether the notification click is handled by this handler
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    handles(notification: any): boolean | Promise<boolean> {
 | 
					    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…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user