@@ -3,7 +3,7 @@ import { Injectable } from '@angular/core';
3
3
import { AddNotification , DeleteNotification , MarkAllAsRead , MarkAsRead } from './notifications.actions' ;
4
4
import { SendWebSocketAction } from '@ngx-starter-kit/socketio-plugin' ;
5
5
import { SwPush } from '@angular/service-worker' ;
6
- import { AppNotification } from '@ngx-starter-kit/notifications ' ;
6
+ import { AppNotification } from './app-notification.model ' ;
7
7
8
8
@Injectable ( {
9
9
providedIn : 'root' ,
@@ -12,7 +12,7 @@ export class NotificationsHandler {
12
12
constructor ( private actions$ : Actions , private store : Store , private readonly swPush : SwPush ) {
13
13
this . actions$
14
14
. pipe ( ofActionSuccessful ( DeleteNotification ) )
15
- . subscribe ( action => { console . log ( action ) ; this . store . dispatch ( new SendWebSocketAction ( action ) ) } ) ;
15
+ . subscribe ( action => this . store . dispatch ( new SendWebSocketAction ( action ) ) ) ;
16
16
this . actions$
17
17
. pipe ( ofActionSuccessful ( MarkAsRead ) )
18
18
. subscribe ( action => this . store . dispatch ( new SendWebSocketAction ( action ) ) ) ;
@@ -21,11 +21,10 @@ export class NotificationsHandler {
21
21
. subscribe ( action => this . store . dispatch ( new SendWebSocketAction ( action ) ) ) ;
22
22
23
23
if ( this . swPush . isEnabled ) {
24
- // subscribe for new messages for testing
25
- this . swPush . messages . subscribe ( message => {
26
- console . log ( 'received push notification in NotificationsHandler' , message ) ;
27
- // TODO:
28
- // this.store.dispatch(new AddNotification(message as AppNotification));
24
+ this . swPush . messages . subscribe ( ( message : { notification : Notification } ) => {
25
+ if ( message . notification . data . targetType ) {
26
+ this . store . dispatch ( new AddNotification ( new AppNotification ( message . notification . data ) ) ) ;
27
+ }
29
28
} ) ;
30
29
}
31
30
}
0 commit comments