X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2F%2Badmin%2Fmoderation%2Fvideo-abuse-list%2Fvideo-abuse-list.component.ts;h=ca37bccf30e975585b346e05ba9338cd68ec9cb8;hb=5baee5fca418487e72ddcd6419d31bca8659b668;hp=f04efa9fcb4b570af6fe96b7f59135c09b308966;hpb=0251197e249cc03b65805ed6805da72bf4573529;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts b/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts index f04efa9fc..ca37bccf3 100644 --- a/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts +++ b/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts @@ -3,7 +3,7 @@ import { Account } from '@app/shared/account/account.model' import { Notifier } from '@app/core' import { SortMeta } from 'primeng/api' import { VideoAbuse, VideoAbuseState } from '../../../../../../shared' -import { RestPagination, RestTable, VideoAbuseService, VideoBlacklistService } from '../../../shared' +import { RestPagination, RestTable, VideoAbuseService, VideoBlockService } from '../../../shared' import { I18n } from '@ngx-translate/i18n-polyfill' import { DropdownAction } from '../../../shared/buttons/action-dropdown.component' import { ConfirmService } from '../../../core/index' @@ -16,9 +16,23 @@ import { getAbsoluteAPIUrl } from '@app/shared/misc/utils' import { DomSanitizer } from '@angular/platform-browser' import { BlocklistService } from '@app/shared/blocklist' import { VideoService } from '@app/shared/video/video.service' -import { ActivatedRoute } from '@angular/router' +import { ActivatedRoute, Params, Router } from '@angular/router' import { filter } from 'rxjs/operators' +export type ProcessedVideoAbuse = VideoAbuse & { + moderationCommentHtml?: string, + reasonHtml?: string + embedHtml?: string + updatedAt?: Date + // override bare server-side definitions with rich client-side definitions + reporterAccount: Account + video: VideoAbuse['video'] & { + channel: VideoAbuse['video']['channel'] & { + ownerAccount: Account + } + } +} + @Component({ selector: 'my-video-abuse-list', templateUrl: './video-abuse-list.component.html', @@ -27,7 +41,7 @@ import { filter } from 'rxjs/operators' export class VideoAbuseListComponent extends RestTable implements OnInit, AfterViewInit { @ViewChild('moderationCommentModal', { static: true }) moderationCommentModal: ModerationCommentModalComponent - videoAbuses: (VideoAbuse & { moderationCommentHtml?: string, reasonHtml?: string })[] = [] + videoAbuses: ProcessedVideoAbuse[] = [] totalRecords = 0 sort: SortMeta = { field: 'createdAt', order: 1 } pagination: RestPagination = { count: this.rowsPerPage, start: 0 } @@ -39,12 +53,13 @@ export class VideoAbuseListComponent extends RestTable implements OnInit, AfterV private videoAbuseService: VideoAbuseService, private blocklistService: BlocklistService, private videoService: VideoService, - private videoBlacklistService: VideoBlacklistService, + private videoBlocklistService: VideoBlockService, private confirmService: ConfirmService, private i18n: I18n, private markdownRenderer: MarkdownService, private sanitizer: DomSanitizer, - private route: ActivatedRoute + private route: ActivatedRoute, + private router: Router ) { super() @@ -86,13 +101,13 @@ export class VideoAbuseListComponent extends RestTable implements OnInit, AfterV isDisplayed: videoAbuse => !videoAbuse.video.deleted }, { - label: this.i18n('Blacklist video'), + label: this.i18n('Block video'), isDisplayed: videoAbuse => !videoAbuse.video.deleted && !videoAbuse.video.blacklisted, handler: videoAbuse => { - this.videoBlacklistService.blacklistVideo(videoAbuse.video.id, undefined, true) + this.videoBlocklistService.blockVideo(videoAbuse.video.id, undefined, true) .subscribe( () => { - this.notifier.success(this.i18n('Video blacklisted.')) + this.notifier.success(this.i18n('Video blocklisted.')) this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED) }, @@ -102,13 +117,13 @@ export class VideoAbuseListComponent extends RestTable implements OnInit, AfterV } }, { - label: this.i18n('Unblacklist video'), + label: this.i18n('Unblock video'), isDisplayed: videoAbuse => !videoAbuse.video.deleted && videoAbuse.video.blacklisted, handler: videoAbuse => { - this.videoBlacklistService.removeVideoFromBlacklist(videoAbuse.video.id) + this.videoBlocklistService.unblockVideo(videoAbuse.video.id) .subscribe( () => { - this.notifier.success(this.i18n('Video unblacklisted.')) + this.notifier.success(this.i18n('Video unblocklisted.')) this.updateVideoAbuseState(videoAbuse, VideoAbuseState.ACCEPTED) }, @@ -212,14 +227,24 @@ export class VideoAbuseListComponent extends RestTable implements OnInit, AfterV this.loadData() } - createByString (account: Account) { - return Account.CREATE_BY_STRING(account.name, account.host) + /* Table filter functions */ + onAbuseSearch (event: Event) { + this.onSearch(event) + this.setQueryParams((event.target as HTMLInputElement).value) + } + + setQueryParams (search: string) { + const queryParams: Params = {} + if (search) Object.assign(queryParams, { search }) + this.router.navigate([ '/admin/moderation/video-abuses/list' ], { queryParams }) } - setTableFilter (filter: string) { - const filterInput = document.getElementById('table-filter') as HTMLInputElement - if (filterInput) filterInput.value = filter + resetTableFilter () { + this.setTableFilter('') + this.setQueryParams('') + this.resetSearch() } + /* END Table filter functions */ isVideoAbuseAccepted (videoAbuse: VideoAbuse) { return videoAbuse.state.id === VideoAbuseState.ACCEPTED @@ -267,7 +292,6 @@ export class VideoAbuseListComponent extends RestTable implements OnInit, AfterV err => this.notifier.error(err.message) ) - } protected loadData () { @@ -278,18 +302,23 @@ export class VideoAbuseListComponent extends RestTable implements OnInit, AfterV }).subscribe( async resultList => { this.totalRecords = resultList.total + const videoAbuses = [] - this.videoAbuses = resultList.data - - for (const abuse of this.videoAbuses) { + for (const abuse of resultList.data) { Object.assign(abuse, { reasonHtml: await this.toHtml(abuse.reason), moderationCommentHtml: await this.toHtml(abuse.moderationComment), embedHtml: this.sanitizer.bypassSecurityTrustHtml(this.getVideoEmbed(abuse)), reporterAccount: new Account(abuse.reporterAccount) }) + + if (abuse.video.channel?.ownerAccount) abuse.video.channel.ownerAccount = new Account(abuse.video.channel.ownerAccount) + if (abuse.updatedAt === abuse.createdAt) delete abuse.updatedAt + + videoAbuses.push(abuse as ProcessedVideoAbuse) } + this.videoAbuses = videoAbuses }, err => this.notifier.error(err.message)