Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion core/app/core/src/lib/services/message/message.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@

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

@Injectable({
providedIn: 'root'
Expand All @@ -37,13 +38,40 @@ export class MessageService {
protected messages: Message[] = [];
protected messagesStage: BehaviorSubject<Message[]>;
protected timeout = 3;
private subscription: Subscription;

constructor(public config: SystemConfigStore) {
this.messagesStage = new BehaviorSubject<Message[]>([]);
this.messages$ = this.messagesStage.asObservable();
this.listenForConfigChanges();
this.initTimeOut();
}

/**
* Listens for configuration changes related to alert timeout settings.
*
* This method subscribes to changes in the configuration observable stream,
* specifically monitoring the 'alert_timeout' UI configuration. When a change
* is detected, it parses the new alert timeout value and updates the instance's
* timeout property accordingly if the parsed value is a valid number.
*
* @return {void}
*/
private listenForConfigChanges(): void {
this.subscription = this.config.configs$
.pipe(
map(() => this.config.getUi('alert_timeout')),
filter(alertTimeout => alertTimeout !== null),
distinctUntilChanged(),
)
.subscribe(alertTimeout => {
const parsedTimeout = parseInt(alertTimeout, 10);
if (!isNaN(parsedTimeout)) {
this.timeout = parsedTimeout;
}
});
}

updateState(messages: Message[]): void {
this.messagesStage.next(this.messages = messages);
}
Expand Down