Headless CMS and Content Managment Hub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

56 lines
1.4 KiB

/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
// tslint:disable: no-pipe-impure
import { ChangeDetectorRef, OnDestroy, Pipe, PipeTransform } from '@angular/core';
import { formatHistoryMessage, HistoryEventDto, UsersProviderService } from '@app/shared/internal';
import { Subscription } from 'rxjs';
@Pipe({
name: 'sqxHistoryMessage',
pure: false
})
export class HistoryMessagePipe implements OnDestroy, PipeTransform {
private subscription: Subscription;
private lastMessage: string;
private lastValue: string | null = null;
constructor(
private readonly changeDetector: ChangeDetectorRef,
private readonly users: UsersProviderService
) {
}
public ngOnDestroy() {
if (this.subscription) {
this.subscription.unsubscribe();
}
}
public transform(event: HistoryEventDto): string | null {
if (!event) {
return this.lastValue;
}
if (this.lastMessage !== event.message) {
this.lastMessage = event.message;
if (this.subscription) {
this.subscription.unsubscribe();
}
this.subscription = formatHistoryMessage(event.message, this.users).subscribe(value => {
this.lastValue = value;
this.changeDetector.markForCheck();
});
}
return this.lastValue;
}
}