X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fshared-abuse-list%2Fabuse-message-modal.component.ts;h=9abb4c094e21fe93151dc3cf976bf6895964d374;hb=4024c44f9027a32809931de0692d40d001df721c;hp=03f5ad735980b427905b3d10f2a17ed2d0fff2dd;hpb=94148c9028829b5576a5dcbfba2c7fb9cf6443d3;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/shared/shared-abuse-list/abuse-message-modal.component.ts b/client/src/app/shared/shared-abuse-list/abuse-message-modal.component.ts index 03f5ad735..9abb4c094 100644 --- a/client/src/app/shared/shared-abuse-list/abuse-message-modal.component.ts +++ b/client/src/app/shared/shared-abuse-list/abuse-message-modal.component.ts @@ -1,10 +1,10 @@ -import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' -import { AuthService, Notifier } from '@app/core' -import { AbuseValidatorsService, FormReactive, FormValidatorService } from '@app/shared/shared-forms' +import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' +import { AuthService, HtmlRendererService, Notifier } from '@app/core' +import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' -import { I18n } from '@ngx-translate/i18n-polyfill' import { AbuseMessage, UserAbuse } from '@shared/models' +import { ABUSE_MESSAGE_VALIDATOR } from '../form-validators/abuse-validators' import { AbuseService } from '../shared-moderation' @Component({ @@ -14,13 +14,12 @@ import { AbuseService } from '../shared-moderation' }) export class AbuseMessageModalComponent extends FormReactive implements OnInit { @ViewChild('modal', { static: true }) modal: NgbModal - @ViewChild('messagesBlock', { static: false }) messagesBlock: ElementRef @Input() isAdminView: boolean @Output() countMessagesUpdated = new EventEmitter<{ abuseId: number, countMessages: number }>() - abuseMessages: AbuseMessage[] = [] + abuseMessages: (AbuseMessage & { messageHtml: string })[] = [] textareaMessage: string sendingMessage = false noResults = false @@ -30,9 +29,8 @@ export class AbuseMessageModalComponent extends FormReactive implements OnInit { constructor ( protected formValidatorService: FormValidatorService, - private abuseValidatorsService: AbuseValidatorsService, private modalService: NgbModal, - private i18n: I18n, + private htmlRenderer: HtmlRendererService, private auth: AuthService, private notifier: Notifier, private abuseService: AbuseService @@ -42,7 +40,7 @@ export class AbuseMessageModalComponent extends FormReactive implements OnInit { ngOnInit () { this.buildForm({ - message: this.abuseValidatorsService.ABUSE_MESSAGE + message: ABUSE_MESSAGE_VALIDATOR }) } @@ -99,24 +97,30 @@ export class AbuseMessageModalComponent extends FormReactive implements OnInit { getPlaceholderMessage () { if (this.isAdminView) { - return this.i18n('Add a message to communicate with the reporter') + return $localize`Add a message to communicate with the reporter` } - return this.i18n('Add a message to communicate with the moderation team') + return $localize`Add a message to communicate with the moderation team` } private loadMessages () { this.abuseService.listAbuseMessages(this.abuse) .subscribe( - res => { - this.abuseMessages = res.data + async res => { + this.abuseMessages = [] + + for (const m of res.data) { + this.abuseMessages.push(Object.assign(m, { + messageHtml: await this.htmlRenderer.convertToBr(m.message) + })) + } + this.noResults = this.abuseMessages.length === 0 setTimeout(() => { - if (!this.messagesBlock) return - - const element = this.messagesBlock.nativeElement as HTMLElement - element.scrollIntoView({ block: 'end', inline: 'nearest' }) + // Don't use ViewChild: it is not supported inside a ng-template + const messagesBlock = document.querySelector('.messages') + messagesBlock.scroll(0, messagesBlock.scrollHeight) }) },