Skip to content

Commit 93baa5b

Browse files
author
Carlos Villaronga
committed
Add Listener for Configurable Alert Timeout
1 parent 582636a commit 93baa5b

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

core/app/core/src/lib/services/message/message.service.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626

2727
import {Injectable} from '@angular/core';
2828
import {Message, MessageTypes} from 'common';
29-
import {BehaviorSubject, Observable} from 'rxjs';
29+
import {BehaviorSubject, Observable, Subscription} from 'rxjs';
3030
import {SystemConfigStore} from '../../store/system-config/system-config.store';
31+
import {distinctUntilChanged, filter, map} from 'rxjs/operators';
3132

3233
@Injectable({
3334
providedIn: 'root'
@@ -37,13 +38,40 @@ export class MessageService {
3738
protected messages: Message[] = [];
3839
protected messagesStage: BehaviorSubject<Message[]>;
3940
protected timeout = 3;
41+
private subscription: Subscription;
4042

4143
constructor(public config: SystemConfigStore) {
4244
this.messagesStage = new BehaviorSubject<Message[]>([]);
4345
this.messages$ = this.messagesStage.asObservable();
46+
this.listenForConfigChanges();
4447
this.initTimeOut();
4548
}
4649

50+
/**
51+
* Listens for configuration changes related to alert timeout settings.
52+
*
53+
* This method subscribes to changes in the configuration observable stream,
54+
* specifically monitoring the 'alert_timeout' UI configuration. When a change
55+
* is detected, it parses the new alert timeout value and updates the instance's
56+
* timeout property accordingly if the parsed value is a valid number.
57+
*
58+
* @return {void}
59+
*/
60+
private listenForConfigChanges(): void {
61+
this.subscription = this.config.configs$
62+
.pipe(
63+
map(() => this.config.getUi('alert_timeout')),
64+
filter(alertTimeout => alertTimeout !== null),
65+
distinctUntilChanged(),
66+
)
67+
.subscribe(alertTimeout => {
68+
const parsedTimeout = parseInt(alertTimeout, 10);
69+
if (!isNaN(parsedTimeout)) {
70+
this.timeout = parsedTimeout;
71+
}
72+
});
73+
}
74+
4775
updateState(messages: Message[]): void {
4876
this.messagesStage.next(this.messages = messages);
4977
}

0 commit comments

Comments
 (0)