99} from '@angular/core' ;
1010
1111import { select , Store } from '@ngrx/store' ;
12- import { BehaviorSubject , Subscription } from 'rxjs' ;
12+ import { BehaviorSubject , Subscription , take } from 'rxjs' ;
1313import difference from 'lodash/difference' ;
1414
1515import { NotificationsService } from '../notifications.service' ;
@@ -18,6 +18,11 @@ import { notificationsStateSelector } from '../selectors';
1818import { INotification } from '../models/notification.model' ;
1919import { NotificationsState } from '../notifications.reducers' ;
2020import { INotificationBoardOptions } from '../../../../config/notifications-config.interfaces' ;
21+ import {
22+ AccessibilitySettingsService ,
23+ AccessibilitySetting
24+ } from '../../../accessibility/accessibility-settings.service' ;
25+ import cloneDeep from 'lodash/cloneDeep' ;
2126
2227@Component ( {
2328 selector : 'ds-notifications-board' ,
@@ -49,9 +54,12 @@ export class NotificationsBoardComponent implements OnInit, OnDestroy {
4954 */
5055 public isPaused$ : BehaviorSubject < boolean > = new BehaviorSubject < boolean > ( false ) ;
5156
52- constructor ( private service : NotificationsService ,
53- private store : Store < AppState > ,
54- private cdr : ChangeDetectorRef ) {
57+ constructor (
58+ protected service : NotificationsService ,
59+ protected store : Store < AppState > ,
60+ protected cdr : ChangeDetectorRef ,
61+ protected accessibilitySettingsService : AccessibilitySettingsService ,
62+ ) {
5563 }
5664
5765 ngOnInit ( ) : void {
@@ -84,7 +92,22 @@ export class NotificationsBoardComponent implements OnInit, OnDestroy {
8492 if ( this . notifications . length >= this . maxStack ) {
8593 this . notifications . splice ( this . notifications . length - 1 , 1 ) ;
8694 }
87- this . notifications . splice ( 0 , 0 , item ) ;
95+
96+ // It would be a bit better to handle the retrieval of configured settings in the NotificationsService.
97+ // Due to circular dependencies this is difficult to implement.
98+ this . accessibilitySettingsService . getAsNumber ( AccessibilitySetting . NotificationTimeOut , item . options . timeOut )
99+ . pipe ( take ( 1 ) ) . subscribe ( timeOut => {
100+ if ( timeOut < 0 ) {
101+ timeOut = 0 ;
102+ }
103+
104+ // Deep clone because the unaltered item is read-only
105+ const modifiedNotification = cloneDeep ( item ) ;
106+ modifiedNotification . options . timeOut = timeOut ;
107+ this . notifications . splice ( 0 , 0 , modifiedNotification ) ;
108+ this . cdr . detectChanges ( ) ;
109+ } ) ;
110+
88111 } else {
89112 // Remove the notification from the store
90113 // This notification was in the store, but not in this.notifications
0 commit comments