ActivityPub-federated video streaming platform using P2P directly in your web browser
Refactor bulk actions
Chocobozzzb1a5bc3ac93f
diff --git a/client/src/app/+admin/moderation/registration-list/registration-list.component.ts b/client/src/app/+admin/moderation/registration-list/registration-list.component.tsindex 51a8c1b23b..f5a0accc5d 100644--- a/client/src/app/+admin/moderation/registration-list/registration-list.component.ts+++ b/client/src/app/+admin/moderation/registration-list/registration-list.component.ts@@ -1,6 +1,7 @@import { Component, OnInit, inject, viewChild } from '@angular/core'import { ConfirmService, MarkdownService, Notifier, ServerService } from '@app/core'import { formatICU } from '@app/helpers'+import { buildDropdownSimpleAndBulkActions } from '@app/shared/shared-main/buttons/action-dropdown-helpers'import { PTDatePipe } from '@app/shared/shared-main/common/date.pipe'import { NgbTooltip } from '@ng-bootstrap/ng-bootstrap'import { ResultList, UserRegistration as UserRegistrationServer, UserRegistrationState } from '@peertube/peertube-models'@@ -61,46 +62,33 @@ export class RegistrationListComponent implements OnInit {constructor () {this.dataLoader = this._dataLoader.bind(this)- this.registrationActions = [- [- {- label: $localize`Accept this request`,- handler: registration => this.openRegistrationRequestProcessModal(registration, 'accept'),- isDisplayed: registration => registration.state.id === UserRegistrationState.PENDING- },- {- label: $localize`Reject this request`,- handler: registration => this.openRegistrationRequestProcessModal(registration, 'reject'),- isDisplayed: registration => registration.state.id === UserRegistrationState.PENDING- },- {- label: $localize`Remove this request`,- description: $localize`Remove the request from the list. The user can register again.`,- handler: registration => this.removeRegistrations([ registration ])- }- ]- ]-- this.bulkActions = [+ const { simpleActions, bulkActions } = buildDropdownSimpleAndBulkActions<UserRegistration>([[{label: $localize`Accept`,handler: registrations => this.openRegistrationRequestProcessModal(registrations, 'accept'),- isDisplayed: registrations => registrations.every(registration => registration.state.id === UserRegistrationState.PENDING)+ isDisplayed: registration => registration.state.id === UserRegistrationState.PENDING,+ enableBulk: true},{label: $localize`Reject`,handler: registrations => this.openRegistrationRequestProcessModal(registrations, 'reject'),- isDisplayed: registrations => registrations.every(registration => registration.state.id === UserRegistrationState.PENDING)+ isDisplayed: registration => registration.state.id === UserRegistrationState.PENDING,+ enableBulk: true}],[{- label: $localize`Delete`,- handler: registrations => this.removeRegistrations(registrations)+ label: $localize`Remove`,+ description: $localize`Remove the request from the list. User can register again.`,+ handler: registrations => this.removeRegistrations(registrations),+ enableBulk: true}]- ]+ ])++ this.registrationActions = simpleActions+ this.bulkActions = bulkActions}ngOnInit () {diff --git a/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts b/client/src/app/+admin/moderation/video-block-list/video-block-list.component.tsindex 26fc175420..416b64cb26 100644--- a/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts+++ b/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts@@ -17,6 +17,7 @@ import { EmbedComponent } from '../../../shared/shared-main/video/embed.componenimport { DataLoaderOptionsBase, TableColumnInfo, TableComponent } from '../../../shared/shared-tables/table.component'import { VideoCellComponent } from '../../../shared/shared-tables/video-cell.component'import { VideoNSFWBadgeComponent } from '../../../shared/shared-video/video-nsfw-badge.component'+import { buildDropdownSimpleAndBulkActions } from '@app/shared/shared-main/buttons/action-dropdown-helpers'type DataLoaderParameter = Parameters<VideoBlockListComponent['_dataLoader']>[0]type VideoBlacklist = VideoBlacklistServer & { reasonHtml?: string }@@ -77,64 +78,42 @@ export class VideoBlockListComponent implements OnInit {constructor () {this.dataLoader = this._dataLoader.bind(this)- this.videoBlocklistActions = [+ const { simpleActions, bulkActions } = buildDropdownSimpleAndBulkActions<VideoBlacklist>([[{label: $localize`Internal actions`,isHeader: true,- isDisplayed: videoBlock => videoBlock.type === VideoBlacklistType.AUTO_BEFORE_PUBLISHED+ isDisplayed: videoBlock => videoBlock.type === VideoBlacklistType.AUTO_BEFORE_PUBLISHED,+ enableBulk: true},{label: $localize`Switch video block to manual`,- handler: videoBlock => this.switchVideosBlockToManual([ videoBlock ]),- isDisplayed: videoBlock => videoBlock.type === VideoBlacklistType.AUTO_BEFORE_PUBLISHED- }- ],- [- {- label: $localize`Actions for the video`,- isHeader: true- },- {- label: $localize`Unblock`,- handler: videoBlock => this.unblockVideos([ videoBlock ])- },-- {- label: $localize`Delete video`,- handler: videoBlock => this.deleteVideos([ videoBlock ])- }- ]- ]-- this.bulkActions = [- [- {- label: $localize`Internal actions`,- isHeader: true,- isDisplayed: entries => entries.every(entry => entry.type === VideoBlacklistType.AUTO_BEFORE_PUBLISHED)- },- {- label: $localize`Switch videos block to manual`,- handler: entries => this.switchVideosBlockToManual(entries),- isDisplayed: entries => entries.every(entry => entry.type === VideoBlacklistType.AUTO_BEFORE_PUBLISHED)+ handler: videoBlocks => this.switchVideosBlockToManual(videoBlocks),+ isDisplayed: videoBlock => videoBlock.type === VideoBlacklistType.AUTO_BEFORE_PUBLISHED,+ enableBulk: true}],[{label: $localize`Actions for videos`,- isHeader: true+ isHeader: true,+ enableBulk: true},{label: $localize`Unblock`,- handler: entries => this.unblockVideos(entries)+ handler: entries => this.unblockVideos(entries),+ enableBulk: true},{label: $localize`Delete video`,- handler: entries => this.deleteVideos(entries)+ handler: entries => this.deleteVideos(entries),+ enableBulk: true}]- ]+ ])++ this.videoBlocklistActions = simpleActions+ this.bulkActions = bulkActions}ngOnInit () {diff --git a/client/src/app/+admin/system/runners/runner-job-list/runner-job-list.component.ts b/client/src/app/+admin/system/runners/runner-job-list/runner-job-list.component.tsindex 9f2cf4f79a..dbeaad0842 100644--- a/client/src/app/+admin/system/runners/runner-job-list/runner-job-list.component.ts+++ b/client/src/app/+admin/system/runners/runner-job-list/runner-job-list.component.ts@@ -2,6 +2,7 @@ import { CommonModule } from '@angular/common'import { Component, OnInit, inject, viewChild } from '@angular/core'import { ConfirmService, Notifier } from '@app/core'import { formatICU } from '@app/helpers'+import { buildDropdownSimpleAndBulkActions } from '@app/shared/shared-main/buttons/action-dropdown-helpers'import { PeerTubeBadgeService } from '@app/shared/shared-main/common/peertube-badge.service'import { RunnerJob, RunnerJobState, RunnerJobStateType, RunnerJobType } from '@peertube/peertube-models'import { AdvancedFilterDef } from '../../../../shared/shared-forms/advanced-input-filter.component'@@ -94,37 +95,26 @@ export class RunnerJobListComponent implements OnInit {}ngOnInit () {- this.actions = [- [- {- label: $localize`Cancel this job`,- handler: job => this.cancelJobs([ job ]),- isDisplayed: job => this.canCancelJob(job)- }- ],- [- {- label: $localize`Delete this job`,- handler: job => this.removeJobs([ job ])- }- ]- ]-- this.bulkActions = [+ const { simpleActions, bulkActions } = buildDropdownSimpleAndBulkActions<RunnerJob>([[{label: $localize`Cancel`,handler: jobs => this.cancelJobs(jobs),- isDisplayed: jobs => jobs.every(j => this.canCancelJob(j))+ isDisplayed: job => this.canCancelJob(job),+ enableBulk: true}],[{label: $localize`Delete`,- handler: jobs => this.removeJobs(jobs)+ handler: jobs => this.removeJobs(jobs),+ enableBulk: true}]- ]+ ])++ this.actions = simpleActions+ this.bulkActions = bulkActions}// ---------------------------------------------------------------------------diff --git a/client/src/app/+video-watch/shared/comment/video-comments.component.ts b/client/src/app/+video-watch/shared/comment/video-comments.component.tsindex f38b1104c2..fa3917ee50 100644--- a/client/src/app/+video-watch/shared/comment/video-comments.component.ts+++ b/client/src/app/+video-watch/shared/comment/video-comments.component.ts@@ -223,7 +223,7 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {const res = await this.confirmService.confirm(message, title)if (res === false) return false- this.videoCommentService.deleteVideoComment(commentToDelete.videoId, commentToDelete.id)+ this.videoCommentService.deleteComments([ { videoId: commentToDelete.videoId, commentId: commentToDelete.id } ]).subscribe({next: () => {if (this.highlightedThread?.id === commentToDelete.id) {diff --git a/client/src/app/shared/shared-abuse-list/abuse-list-table.component.ts b/client/src/app/shared/shared-abuse-list/abuse-list-table.component.tsindex e1d360658c..52a3d7c1b8 100644--- a/client/src/app/shared/shared-abuse-list/abuse-list-table.component.ts+++ b/client/src/app/shared/shared-abuse-list/abuse-list-table.component.ts@@ -12,6 +12,7 @@ import { GlobalIconComponent } from '../shared-icons/global-icon.component'import { Account } from '../shared-main/account/account.model'import { Actor } from '../shared-main/account/actor.model'import { ActionDropdownComponent, DropdownAction } from '../shared-main/buttons/action-dropdown.component'+import { buildDropdownSimpleAndBulkActions } from '../shared-main/buttons/action-dropdown-helpers'import { PTDatePipe } from '../shared-main/common/date.pipe'import { NumberFormatterPipe } from '../shared-main/common/number-formatter.pipe'import { Video } from '../shared-main/video/video.model'@@ -30,6 +31,25 @@ import { ProcessedAbuse } from './processed-abuse.model'const debugLogger = debug('peertube:moderation:AbuseListTableComponent')type DataLoaderParameter = Parameters<AbuseListTableComponent['_dataLoader']>[0]+type DropdownActionForBuilder<T, D = never> =+ & Omit<DropdownAction<T, D>, 'linkBuilder' | 'queryParamsBuilder' | 'handler'>+ & {+ handler?: (a: T[]) => any+ }+ & (+ | {+ enableBulk: true++ linkBuilder?: never+ queryParamsBuilder?: never+ }+ | {+ enableBulk: false++ linkBuilder?: DropdownAction<T, D>['linkBuilder']+ queryParamsBuilder?: DropdownAction<T, D>['queryParamsBuilder']+ }+ )@Component({selector: 'my-abuse-list-table',@@ -148,7 +168,7 @@ export class AbuseListTableComponent implements OnInit, OnDestroy {]}- const abuseActions: DropdownAction<ProcessedAbuse>[][] = [+ const { simpleActions, bulkActions } = buildDropdownSimpleAndBulkActions<ProcessedAbuse>([this.buildInternalActions(),this.buildFlaggedAccountActions(),@@ -158,13 +178,13 @@ export class AbuseListTableComponent implements OnInit, OnDestroy {this.buildVideoActions(),this.buildAccountActions()- ]+ ])this.abuseActions = viewType === 'admin'- ? await this.hooks.wrapObject(abuseActions, 'admin-comments', 'filter:admin-abuse-list.actions.create.result')- : abuseActions+ ? await this.hooks.wrapObject(simpleActions, 'admin-comments', 'filter:admin-abuse-list.actions.create.result')+ : simpleActions- this.bulkActions = this.buildBulkActions()+ this.bulkActions = bulkActions.filter(actions => actions.length !== 0)}ngOnDestroy () {@@ -298,227 +318,162 @@ export class AbuseListTableComponent implements OnInit, OnDestroy {}))}- private buildInternalActions (): DropdownAction<ProcessedAbuse>[] {+ private buildInternalActions (): DropdownActionForBuilder<ProcessedAbuse>[] {return [{label: $localize`Internal actions`,- isHeader: true+ isHeader: true,+ enableBulk: true},{label: this.isAdminView()? $localize`Messages with reporter`: $localize`Messages with moderators`,- handler: abuse => this.openAbuseMessagesModal(abuse),- isDisplayed: abuse => this.isLocalAbuse(abuse)+ handler: abuses => this.openAbuseMessagesModal(abuses[0]),+ isDisplayed: abuse => this.isLocalAbuse(abuse),+ enableBulk: false},{- label: $localize`Update internal note`,- handler: abuse => this.openModerationCommentModal([ abuse ]),- isDisplayed: abuse => this.isAdminView() && !!abuse.moderationComment+ label: $localize`Set internal note`,+ handler: abuses => this.openModerationCommentModal(abuses),+ isDisplayed: abuse => this.isAdminView(),+ enableBulk: true},{label: $localize`Mark as accepted`,- handler: abuse => this.updateAbuseState(abuse, AbuseState.ACCEPTED),- isDisplayed: abuse => this.isAdminView() && !this.isAbuseAccepted(abuse)+ handler: abuses => this.updateAbusesState(abuses, AbuseState.ACCEPTED),+ isDisplayed: abuse => this.isAdminView() && !this.isAbuseAccepted(abuse),+ enableBulk: true},{label: $localize`Mark as rejected`,- handler: abuse => this.updateAbuseState(abuse, AbuseState.REJECTED),- isDisplayed: abuse => this.isAdminView() && !this.isAbuseRejected(abuse)- },- {- label: $localize`Add internal note`,- handler: abuse => this.openModerationCommentModal([ abuse ]),- isDisplayed: abuse => this.isAdminView() && !abuse.moderationComment+ handler: abuses => this.updateAbusesState(abuses, AbuseState.REJECTED),+ isDisplayed: abuse => this.isAdminView() && !this.isAbuseRejected(abuse),+ enableBulk: true},{label: $localize`Delete report`,- handler: abuse => this.removeAbuses([ abuse ]),- isDisplayed: () => this.isAdminView()+ handler: abuses => this.removeAbuses(abuses),+ isDisplayed: () => this.isAdminView(),+ enableBulk: true}]}- private buildBulkActions (): DropdownAction<ProcessedAbuse[]>[][] {- return [- [- {- label: $localize`Update internal note`,- handler: abuses => this.openModerationCommentModal(abuses),- isDisplayed: abuses => this.isAdminView() && abuses.every(abuse => !!abuse.moderationComment)- },- {- label: $localize`Mark as accepted`,- handler: abuses => this.updateAbusesState(abuses, AbuseState.ACCEPTED),- isDisplayed: abuses => this.isAdminView() && abuses.every(abuse => !this.isAbuseAccepted(abuse))- },- {- label: $localize`Mark as rejected`,- handler: abuses => this.updateAbusesState(abuses, AbuseState.REJECTED),- isDisplayed: abuses => this.isAdminView() && abuses.every(abuse => !this.isAbuseRejected(abuse))- },- {- label: $localize`Add internal note`,- handler: abuses => this.openModerationCommentModal(abuses),- isDisplayed: abuses => this.isAdminView() && abuses.every(abuse => !abuse.moderationComment)- },- {- label: $localize`Delete report`,- handler: abuses => this.removeAbuses(abuses),- isDisplayed: () => this.isAdminView()- }- ],- [- {- label: $localize`Mute account`,- handler: abuses => this.muteFlaggedAccounts(abuses),- isDisplayed: abuses => {- return this.isAdminView() && abuses.every(abuse => abuse.flaggedAccount && !abuse.comment && !abuse.video)- }- },- {- label: $localize`Mute server account`,- handler: abuses => this.muteFlaggedAccountServers(abuses),- isDisplayed: abuses => {- return this.isAdminView() && abuses.every(abuse => abuse.flaggedAccount && !abuse.comment && !abuse.video)- }- },- {- label: $localize`Mute reporter`,- handler: abuses => this.muteReporters(abuses),- isDisplayed: abuses => this.isAdminView() && abuses.every(abuse => !!abuse.reporterAccount)- },- {- label: $localize`Mute reporter server`,- handler: abuses => this.muteReporterServers(abuses),- isDisplayed: abuses => {- return this.isAdminView() && abuses.every(abuse => abuse.reporterAccount && !abuse.reporterAccount.userId)- }- }- ],- [- {- label: $localize`Block video`,- handler: abuses => this.blockAbuseVideos(abuses),- isDisplayed: abuses => {- return this.isAdminView() && abuses.every(abuse => abuse.video && !abuse.video.deleted && !abuse.video.blacklisted)- }- },- {- label: $localize`Unblock video`,- handler: abuses => this.unblockAbuseVideos(abuses),- isDisplayed: abuses => {- return this.isAdminView() && abuses.every(abuse => abuse.video && !abuse.video.deleted && abuse.video.blacklisted)- }- },- {- label: $localize`Delete video`,- handler: abuses => this.deleteAbuseVideos(abuses),- isDisplayed: abuses => this.isAdminView() && abuses.every(abuse => abuse.video && !abuse.video.deleted)- },- {- label: $localize`Delete comment`,- handler: abuses => this.deleteAbuseComments(abuses),- isDisplayed: abuses => this.isAdminView() && abuses.every(abuse => abuse.comment && !abuse.comment.deleted)- }- ]- ]- }-- private buildFlaggedAccountActions (): DropdownAction<ProcessedAbuse>[] {+ private buildFlaggedAccountActions (): DropdownActionForBuilder<ProcessedAbuse>[] {if (!this.isAdminView()) return []return [{label: $localize`Actions for the flagged account`,isHeader: true,- isDisplayed: abuse => abuse.flaggedAccount && !abuse.comment && !abuse.video+ isDisplayed: abuse => abuse.flaggedAccount && !abuse.comment && !abuse.video,+ enableBulk: true},{label: $localize`Mute account`,isDisplayed: abuse => abuse.flaggedAccount && !abuse.comment && !abuse.video,- handler: abuse => this.muteFlaggedAccounts([ abuse ])+ handler: abuses => this.muteFlaggedAccounts(abuses),+ enableBulk: true},{label: $localize`Mute server account`,isDisplayed: abuse => abuse.flaggedAccount && !abuse.comment && !abuse.video,- handler: abuse => this.muteFlaggedAccountServers([ abuse ])+ handler: abuses => this.muteFlaggedAccountServers(abuses),+ enableBulk: true}]}- private buildAccountActions (): DropdownAction<ProcessedAbuse>[] {+ private buildAccountActions (): DropdownActionForBuilder<ProcessedAbuse>[] {if (!this.isAdminView()) return []return [{label: $localize`Actions for the reporter`,isHeader: true,- isDisplayed: abuse => !!abuse.reporterAccount+ isDisplayed: abuse => !!abuse.reporterAccount,+ enableBulk: true},{label: $localize`Mute reporter`,isDisplayed: abuse => !!abuse.reporterAccount,- handler: abuse => this.muteReporters([ abuse ])+ handler: abuses => this.muteReporters(abuses),+ enableBulk: true},{- label: $localize`Mute server`,+ label: $localize`Mute reporter server`,isDisplayed: abuse => abuse.reporterAccount && !abuse.reporterAccount.userId,- handler: abuse => this.muteReporterServers([ abuse ])+ handler: abuses => this.muteReporterServers(abuses),+ enableBulk: true}]}- private buildVideoActions (): DropdownAction<ProcessedAbuse>[] {+ private buildVideoActions (): DropdownActionForBuilder<ProcessedAbuse>[] {if (!this.isAdminView()) return []return [{label: $localize`Actions for the video`,isHeader: true,- isDisplayed: abuse => abuse.video && !abuse.video.deleted+ isDisplayed: abuse => abuse.video && !abuse.video.deleted,+ enableBulk: true},{label: $localize`Block video`,isDisplayed: abuse => abuse.video && !abuse.video.deleted && !abuse.video.blacklisted,- handler: abuse => this.blockAbuseVideos([ abuse ])+ handler: abuses => this.blockAbuseVideos(abuses),+ enableBulk: true},{label: $localize`Unblock video`,isDisplayed: abuse => abuse.video && !abuse.video.deleted && abuse.video.blacklisted,- handler: abuse => this.unblockAbuseVideos([ abuse ])+ handler: abuses => this.unblockAbuseVideos(abuses),+ enableBulk: true},{label: $localize`Delete video`,isDisplayed: abuse => abuse.video && !abuse.video.deleted,- handler: abuse => this.deleteAbuseVideos([ abuse ])+ handler: abuses => this.deleteAbuseVideos(abuses),+ enableBulk: true}]}- private buildCommentActions (): DropdownAction<ProcessedAbuse>[] {+ private buildCommentActions (): DropdownActionForBuilder<ProcessedAbuse>[] {if (!this.isAdminView()) return []return [{label: $localize`Actions for the comment`,isHeader: true,- isDisplayed: abuse => abuse.comment && !abuse.comment.deleted+ isDisplayed: abuse => abuse.comment && !abuse.comment.deleted,+ enableBulk: true},{label: $localize`Delete comment`,isDisplayed: abuse => abuse.comment && !abuse.comment.deleted,- handler: abuse => this.deleteAbuseComments([ abuse ])+ handler: abuses => this.deleteAbuseComments(abuses),+ enableBulk: true}]}- private removeAbuses (abuses: AdminAbuse[]) {+ private async removeAbuses (abuses: AdminAbuse[]) {+ const message = formatICU(+ $localize`Do you really want to delete {count, plural, =1 {this report?} other {{count} reports?}}`,+ { count: abuses.length }+ )++ const res = await this.confirmService.confirm(message, $localize`Delete`)+ if (res === false) return+this.abuseService.removeAbuse(abuses).subscribe({next: () => {@@ -707,7 +662,7 @@ export class AbuseListTableComponent implements OnInit, OnDestroy {)if (res === false) return- this.commentService.deleteVideoComments(+ this.commentService.deleteComments(abuses.map(abuse => ({videoId: abuse.comment.video.id,commentId: abuse.comment.iddiff --git a/client/src/app/shared/shared-main/buttons/action-dropdown-helpers.ts b/client/src/app/shared/shared-main/buttons/action-dropdown-helpers.tsnew file mode 100644index 0000000000..4736adbafc--- /dev/null+++ b/client/src/app/shared/shared-main/buttons/action-dropdown-helpers.ts@@ -0,0 +1,193 @@+import { CommonModule, NgTemplateOutlet } from '@angular/common'+import { booleanAttribute, ChangeDetectionStrategy, Component, ContentChild, input, OnChanges, output, TemplateRef } from '@angular/core'+import { Params, RouterLink } from '@angular/router'+import { ActorAvatarComponent, ActorAvatarInput, ActorAvatarType } from '@app/shared/shared-actor-image/actor-avatar.component'+import { GlobalIconName } from '@app/shared/shared-icons/global-icon.component'+import { NgbDropdownMenu, NgbDropdownModule, NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap'+import { GlobalIconComponent } from '../../shared-icons/global-icon.component'+import { CollaboratorStateType } from '../channel/collaborator-state.component'++type DropdownActionForBuilder<T, D = never> =+ & Omit<DropdownAction<T, D>, 'linkBuilder' | 'queryParamsBuilder' | 'handler'>+ & {+ handler?: (a: T[]) => any+ }+ & (+ | {+ enableBulk: true++ linkBuilder?: never+ queryParamsBuilder?: never+ }+ | {+ enableBulk: false++ linkBuilder?: DropdownAction<T, D>['linkBuilder']+ queryParamsBuilder?: DropdownAction<T, D>['queryParamsBuilder']+ }+ )++export function buildDropdownSimpleAndBulkActions<T, D = never> (actions: DropdownActionForBuilder<T, D>[]): {+ simpleActions: DropdownAction<T, D>[]+ bulkActions: DropdownAction<T[], D>[]+}++export function buildDropdownSimpleAndBulkActions<T, D = never> (actions: DropdownActionForBuilder<T, D>[][]): {+ simpleActions: DropdownAction<T, D>[][]+ bulkActions: DropdownAction<T[], D>[][]+}++export function buildDropdownSimpleAndBulkActions<T, D = never> (+ actions: DropdownActionForBuilder<T, D>[] | DropdownActionForBuilder<T, D>[][]+) {+ if (actions.length !== 0 && Array.isArray(actions[0])) {+ const simpleActions: DropdownAction<T, D>[][] = []+ const bulkActions: DropdownAction<T[], D>[][] = []++ for (const group of actions as DropdownActionForBuilder<T, D>[][]) {+ const result = buildDropdownSimpleAndBulkActions(group)+ simpleActions.push(result.simpleActions)+ bulkActions.push(result.bulkActions)+ }++ return { simpleActions, bulkActions }+ }++ const simpleActions: DropdownAction<T, D>[] = []+ const bulkActions: DropdownAction<T[], D>[] = []++ for (const action of actions as DropdownActionForBuilder<T, D>[]) {+ simpleActions.push({+ ...action,+ handler: (a: T) => {+ if (action.handler) action.handler([ a ])+ }+ })++ if (action.enableBulk) {+ bulkActions.push({+ ...action,++ isDisplayed: (entries: T[]) => {+ if (!action.isDisplayed) return true++ return entries.every(entry => action.isDisplayed(entry))+ }+ })+ }+ }++ return { simpleActions, bulkActions }+}++export type DropdownAction<T, D = never> = {+ label: string++ iconName?: GlobalIconName++ actorAvatar?: {+ actor: ActorAvatarInput+ type: ActorAvatarType+ }+ collaboratorBadge?: CollaboratorStateType++ description?: string+ title?: string+ handler?: (a: T) => any++ linkBuilder?: (a: T) => (string | number)[]+ queryParamsBuilder?: (a: T) => Params++ isDisplayed?: (a: T) => boolean++ class?: string[]+ isHeader?: boolean++ ownerOrModeratorPrivilege?: () => string++ data?: D+}++export type DropdownButtonSize = 'normal' | 'small'+export type DropdownTheme = 'primary' | 'secondary'+export type DropdownButtonIcon = 'more-horizontal' | 'more-vertical' | 'chevron-down'++@Component({+ selector: 'my-action-dropdown',+ styleUrls: [ './action-dropdown.component.scss' ],+ templateUrl: './action-dropdown.component.html',+ changeDetection: ChangeDetectionStrategy.OnPush,+ imports: [+ CommonModule,+ NgbTooltipModule,+ NgbDropdownModule,+ GlobalIconComponent,+ NgbDropdownMenu,+ RouterLink,+ NgTemplateOutlet,+ ActorAvatarComponent+ ]+})+export class ActionDropdownComponent<T, D = never> implements OnChanges {+ readonly actions = input<DropdownAction<T, D>[] | DropdownAction<T, D>[][]>([])+ readonly entry = input<T>(undefined)++ readonly placement = input('bottom-left auto')+ readonly container = input<null | 'body'>(undefined)++ readonly buttonSize = input<DropdownButtonSize>('normal')+ readonly buttonIcon = input<DropdownButtonIcon>('more-horizontal')+ readonly buttonStyled = input(true, { transform: booleanAttribute })++ readonly label = input<string>(undefined)+ readonly theme = input<DropdownTheme>('secondary')++ readonly openChange = output<boolean>()++ @ContentChild('dropdownItemExtra', { descendants: false })+ dropdownItemExtra: TemplateRef<any>++ @ContentChild('labelExtra', { descendants: false })+ labelExtra: TemplateRef<any>++ buttonClasses: Record<string, boolean> = {}++ ngOnChanges () {+ this.buttonClasses = {+ 'icon-only': !this.label(),+ 'peertube-button': this.buttonStyled(),+ 'peertube-button-small': this.buttonSize() === 'small',+ 'secondary-button': this.buttonStyled() && this.theme() === 'secondary',+ 'primary-button': this.buttonStyled() && this.theme() === 'primary',+ 'button-unstyle': !this.buttonStyled()+ }+ }++ getActions (): DropdownAction<T, D>[][] {+ const actions = this.actions()+ if (actions.length !== 0 && Array.isArray(actions[0])) return actions as DropdownAction<T, D>[][]++ return [ actions as DropdownAction<T, D>[] ]+ }++ getQueryParams (action: DropdownAction<T, D>, entry: T) {+ if (action.queryParamsBuilder) return action.queryParamsBuilder(entry)++ return {}+ }++ areActionsDisplayed (actions: (DropdownAction<T, D> | DropdownAction<T, D>[])[], entry: T): boolean {+ return actions.some(a => {+ if (Array.isArray(a)) return this.areActionsDisplayed(a, entry)++ return a.isHeader !== true && (a.isDisplayed === undefined || a.isDisplayed(entry))+ })+ }++ isBlockDisplayed (allActions: (DropdownAction<T, D> | DropdownAction<T, D>[])[], action: DropdownAction<T, D>, entry: T) {+ // Do not display only the header+ if (action.isHeader && !this.areActionsDisplayed(allActions, entry)) return false++ return action.isDisplayed === undefined || action.isDisplayed(entry) === true+ }+}diff --git a/client/src/app/shared/shared-video-comment/video-comment-list-admin-owner.component.ts b/client/src/app/shared/shared-video-comment/video-comment-list-admin-owner.component.tsindex b59213f06c..d5b2397cf9 100644--- a/client/src/app/shared/shared-video-comment/video-comment-list-admin-owner.component.ts+++ b/client/src/app/shared/shared-video-comment/video-comment-list-admin-owner.component.ts@@ -10,6 +10,7 @@ import { switchMap } from 'rxjs'import { ActorAvatarComponent } from '../shared-actor-image/actor-avatar.component'import { AdvancedFilterDef } from '../shared-forms/advanced-input-filter.component'import { GlobalIconComponent } from '../shared-icons/global-icon.component'+import { buildDropdownSimpleAndBulkActions } from '../shared-main/buttons/action-dropdown-helpers'import { ActionDropdownComponent, DropdownAction } from '../shared-main/buttons/action-dropdown.component'import { CollaboratorStateComponent } from '../shared-main/channel/collaborator-state.component'import { PTDatePipe } from '../shared-main/common/date.pipe'@@ -56,7 +57,7 @@ export class VideoCommentListAdminOwnerComponent implements OnInit, OnDestroy {readonly table = viewChild<TableComponent<VideoCommentForAdminOrUser, DataLoaderParameter, ColumnName>>('table')videoCommentActions: DropdownAction<VideoCommentForAdminOrUser>[][] = []- bulkActions: DropdownAction<VideoCommentForAdminOrUser[]>[] = []+ bulkActions: DropdownAction<VideoCommentForAdminOrUser[]>[][] = []inputFilters: AdvancedFilterDef<DataLoaderParameter>[] = []columns: TableColumnInfo<ColumnName>[] = [@@ -85,7 +86,6 @@ export class VideoCommentListAdminOwnerComponent implements OnInit, OnDestroy {this.buildInputFilters()await this.buildCommentActions()- await this.buildBulkActions()}ngOnDestroy () {@@ -95,12 +95,13 @@ export class VideoCommentListAdminOwnerComponent implements OnInit, OnDestroy {}private async buildCommentActions () {- const videoCommentActions: DropdownAction<VideoCommentForAdminOrUser>[][] = [+ const { simpleActions, bulkActions } = buildDropdownSimpleAndBulkActions<VideoCommentForAdminOrUser>([[{label: $localize`Delete this comment`,- handler: comment => this.removeComment(comment),- isDisplayed: () => this.mode() === 'user' || this.user.hasRight(UserRight.MANAGE_ANY_VIDEO_COMMENT)+ handler: comments => this.removeComments(comments),+ isDisplayed: () => this.mode() === 'user' || this.user.hasRight(UserRight.MANAGE_ANY_VIDEO_COMMENT),+ enableBulk: true},{label: $localize`Delete all comments of this account`,@@ -111,43 +112,30 @@ export class VideoCommentListAdminOwnerComponent implements OnInit, OnDestroy {: $localize`This will delete comments on all your videos`: $localize`This will delete comments on all videos from your platform`,- handler: comment => this.removeCommentsOfAccount(comment),+ handler: comments => this.removeCommentsOfAccount(comments[0]),+isDisplayed: () => {if (this.mode() === 'user') return truereturn this.mode() === 'admin' && this.user.hasRight(UserRight.MANAGE_ANY_VIDEO_COMMENT)- }+ },++ enableBulk: false}],[{label: $localize`Approve this comment`,- handler: comment => this.approveComments([ comment ]),- isDisplayed: comment => this.mode() === 'user' && comment.heldForReview+ handler: comments => this.approveComments(comments),+ isDisplayed: comment => this.mode() === 'user' && comment.heldForReview,+ enableBulk: true}]- ]+ ])this.videoCommentActions = this.mode() === 'admin'- ? await this.hooks.wrapObject(videoCommentActions, 'admin-comments', 'filter:admin-video-comments-list.actions.create.result')- : videoCommentActions- }-- private async buildBulkActions () {- const bulkActions: DropdownAction<VideoCommentForAdminOrUser[]>[] = [- {- label: $localize`Delete`,- handler: comments => this.removeComments(comments),- isDisplayed: () => this.mode() === 'user' || this.user.hasRight(UserRight.MANAGE_ANY_VIDEO_COMMENT),- iconName: 'delete'- },- {- label: $localize`Approve`,- handler: comments => this.approveComments(comments),- isDisplayed: comments => this.mode() === 'user' && comments.every(c => c.heldForReview),- iconName: 'tick'- }- ]+ ? await this.hooks.wrapObject(simpleActions, 'admin-comments', 'filter:admin-video-comments-list.actions.create.result')+ : simpleActionsthis.bulkActions = this.mode() === 'admin'? await this.hooks.wrapObject(bulkActions, 'admin-comments', 'filter:admin-video-comments-list.bulk-actions.create.result')@@ -270,10 +258,18 @@ export class VideoCommentListAdminOwnerComponent implements OnInit, OnDestroy {})}- private removeComments (comments: VideoCommentForAdminOrUser[]) {+ private async removeComments (comments: VideoCommentForAdminOrUser[]) {+ const message = formatICU(+ $localize`Do you really want to remove {count, plural, =1 {this comment} other {{count} comments}}?`,+ { count: comments.length }+ )++ const res = await this.confirmService.confirm(message, $localize`Remove`)+ if (res === false) return+const commentArgs = comments.map(c => ({ videoId: c.video.id, commentId: c.id }))- this.videoCommentService.deleteVideoComments(commentArgs)+ this.videoCommentService.deleteComments(commentArgs).subscribe({next: () => {this.notifier.success(@@ -290,15 +286,6 @@ export class VideoCommentListAdminOwnerComponent implements OnInit, OnDestroy {})}- private removeComment (comment: VideoCommentForAdminOrUser) {- this.videoCommentService.deleteVideoComment(comment.video.id, comment.id)- .subscribe({- next: () => this.table().loadData(),-- error: err => this.notifier.handleError(err)- })- }-private async removeCommentsOfAccount (comment: VideoCommentForAdminOrUser) {const message = $localize`Do you really want to delete all comments of ${comment.by}? Comments are deleted after a few minutes.`const res = await this.confirmService.confirm(message, $localize`Delete`)diff --git a/client/src/app/shared/shared-video-comment/video-comment.service.ts b/client/src/app/shared/shared-video-comment/video-comment.service.tsindex 3b704f43e0..8e3712c979 100644--- a/client/src/app/shared/shared-video-comment/video-comment.service.ts+++ b/client/src/app/shared/shared-video-comment/video-comment.service.ts@@ -185,19 +185,16 @@ export class VideoCommentService {// ---------------------------------------------------------------------------- deleteVideoComment (videoId: number | string, commentId: number) {- const url = `${VideoCommentService.BASE_VIDEO_URL + videoId}/comments/${commentId}`-- return this.authHttp- .delete(url)- .pipe(catchError(err => this.restExtractor.handleError(err)))- }-- deleteVideoComments (comments: { videoId: number | string, commentId: number }[]) {+ deleteComments (comments: { videoId: number | string, commentId: number }[]) {return from(comments).pipe(- concatMap(c => this.deleteVideoComment(c.videoId, c.commentId)),- toArray()+ concatMap(c => {+ const url = `${VideoCommentService.BASE_VIDEO_URL + c.videoId}/comments/${c.commentId}`++ return this.authHttp.delete(url)+ }),+ toArray(),+ catchError(err => this.restExtractor.handleError(err)))}