Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Add mute features to comments page

Chocobozzz1fc9f7122765
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.ts
index 9f08504e8b..6a200121e2 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
@@ -88,13 +88,13 @@ export class RegistrationListComponent implements OnInit {
const { simpleActions, bulkActions } = buildDropdownSimpleAndBulkActions<UserRegistration>([
[
{
- label: $localize`Accept`,
+ label: () => $localize`Accept`,
handler: registrations => this.openRegistrationRequestProcessModal(registrations, 'accept'),
isDisplayed: registration => registration.state.id === UserRegistrationState.PENDING,
enableBulk: true
},
{
- label: $localize`Reject`,
+ label: () => $localize`Reject`,
handler: registrations => this.openRegistrationRequestProcessModal(registrations, 'reject'),
isDisplayed: registration => registration.state.id === UserRegistrationState.PENDING,
enableBulk: true
@@ -102,7 +102,7 @@ export class RegistrationListComponent implements OnInit {
],
[
{
- label: $localize`Remove`,
+ label: () => $localize`Remove`,
description: $localize`Remove the request from the list. User can register again.`,
handler: registrations => this.removeRegistrations(registrations),
enableBulk: true
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.ts
index c81334586b..a6ba45a24e 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
@@ -81,13 +81,13 @@ export class VideoBlockListComponent implements OnInit {
const { simpleActions, bulkActions } = buildDropdownSimpleAndBulkActions<VideoBlacklist>([
[
{
- label: $localize`Internal actions`,
+ label: () => $localize`Internal actions`,
isHeader: true,
isDisplayed: videoBlock => videoBlock.type === VideoBlacklistType.AUTO_BEFORE_PUBLISHED,
enableBulk: true
},
{
- label: $localize`Switch video block to manual`,
+ label: () => $localize`Switch to manual block`,
handler: videoBlocks => this.switchVideosBlockToManual(videoBlocks),
isDisplayed: videoBlock => videoBlock.type === VideoBlacklistType.AUTO_BEFORE_PUBLISHED,
enableBulk: true
@@ -95,17 +95,17 @@ export class VideoBlockListComponent implements OnInit {
],
[
{
- label: $localize`Actions for videos`,
+ label: () => $localize`Actions for videos`,
isHeader: true,
enableBulk: true
},
{
- label: $localize`Unblock`,
+ label: () => $localize`Unblock`,
handler: entries => this.unblockVideos(entries),
enableBulk: true
},
{
- label: $localize`Delete video`,
+ label: entries => formatICU($localize`{count, plural, =1 {Delete video} other {Delete videos}}`, { count: entries.length }),
handler: entries => this.deleteVideos(entries),
enableBulk: true
}
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.ts
index ed9826b3e3..ccf492019a 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
@@ -98,7 +98,7 @@ export class RunnerJobListComponent implements OnInit {
const { simpleActions, bulkActions } = buildDropdownSimpleAndBulkActions<RunnerJob>([
[
{
- label: $localize`Cancel`,
+ label: () => $localize`Cancel`,
handler: jobs => this.cancelJobs(jobs),
isDisplayed: job => this.canCancelJob(job),
enableBulk: true
@@ -106,7 +106,7 @@ export class RunnerJobListComponent implements OnInit {
],
[
{
- label: $localize`Delete`,
+ label: () => $localize`Delete`,
handler: jobs => this.removeJobs(jobs),
enableBulk: true
}
diff --git a/client/src/app/+my-library/my-ownership-changes/my-video-ownership-changes/my-video-ownership-changes.component.ts b/client/src/app/+my-library/my-ownership-changes/my-video-ownership-changes/my-video-ownership-changes.component.ts
index 9d2768046e..cdc79f1580 100644
--- a/client/src/app/+my-library/my-ownership-changes/my-video-ownership-changes/my-video-ownership-changes.component.ts
+++ b/client/src/app/+my-library/my-ownership-changes/my-video-ownership-changes/my-video-ownership-changes.component.ts
@@ -55,13 +55,13 @@ export class MyVideoOwnershipChangesComponent {
const { simpleActions, bulkActions } = buildDropdownSimpleAndBulkActions<ChangeOwnership>([
[
{
- label: $localize`Accept`,
+ label: () => $localize`Accept`,
handler: changeOwnership => this.openAcceptModal(changeOwnership),
isDisplayed: changeOwnership => this.canAcceptOrReject(changeOwnership),
enableBulk: true
},
{
- label: $localize`Reject`,
+ label: () => $localize`Reject`,
handler: changeOwnership => this.reject(changeOwnership),
isDisplayed: changeOwnership => this.canAcceptOrReject(changeOwnership),
enableBulk: true
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.ts
index 9c0481f2b4..42c64461f0 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
@@ -1,8 +1,8 @@
-import { Component, OnDestroy, OnInit, inject, input, viewChild } from '@angular/core'
+import { Component, inject, input, OnDestroy, OnInit, viewChild } from '@angular/core'
import { ConfirmService, HooksService, MarkdownService, Notifier, PluginService } from '@app/core'
import { formatICU } from '@app/helpers'
import { NgbTooltip } from '@ng-bootstrap/ng-bootstrap'
-import { AbuseState, AbuseStateType, AdminAbuse, ResultList } from '@peertube/peertube-models'
+import { AbuseState, AbuseStateType, AdminAbuse, ResultList, UserAbuse } from '@peertube/peertube-models'
import { logger } from '@root-helpers/logger'
import debug from 'debug'
import { map, switchMap } from 'rxjs'
@@ -11,7 +11,7 @@ import { AdvancedFilterDef } from '../shared-forms/advanced-input-filter.compone
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 { buildDropdownSimpleAndBulkActions } from '../shared-main/buttons/action-dropdown-helpers'
+import { buildDropdownSimpleAndBulkActions, DropdownActionForBuilder } from '../shared-main/buttons/action-dropdown-helpers'
import { ActionDropdownComponent, DropdownAction } from '../shared-main/buttons/action-dropdown.component'
import { PTDatePipe } from '../shared-main/common/date.pipe'
import { NumberFormatterPipe } from '../shared-main/common/number-formatter.pipe'
@@ -32,25 +32,6 @@ 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',
@@ -280,41 +261,54 @@ export class AbuseListTableComponent implements OnInit, OnDestroy {
: this.abuseService.listUserAbuses(options)
return observable.pipe(
- switchMap(async (resultList: ResultList<ProcessedAbuse>) => {
+ switchMap(async (resultList: ResultList<UserAbuse | AdminAbuse>) => {
const abuses: ProcessedAbuse[] = []
for (const abuse of resultList.data) {
- abuse.reasonHtml = await this.toHtml(abuse.reason)
+ const video = abuse.video as ProcessedAbuse['video']
- if (abuse.moderationComment) {
- abuse.moderationCommentHtml = await this.toHtml(abuse.moderationComment)
+ if (abuse.video?.channel?.ownerAccount) {
+ video.channel.ownerAccount = new Account(abuse.video.channel.ownerAccount)
}
- if (abuse.video) {
- if (abuse.video.channel?.ownerAccount) {
- abuse.video.channel.ownerAccount = new Account(abuse.video.channel.ownerAccount)
- }
- }
+ let commentHTML: string
if (abuse.comment) {
if (abuse.comment.deleted) {
- abuse.commentHTML = $localize`Deleted comment`
+ commentHTML = $localize`Deleted comment`
} else {
- abuse.commentHTML = await this.markdownRenderer.textMarkdownToHTML({ markdown: abuse.comment.text, withHtml: true })
+ commentHTML = await this.markdownRenderer.textMarkdownToHTML({
+ markdown: abuse.comment.text,
+ withHtml: true
+ })
}
}
- if (abuse.reporterAccount) {
- abuse.reporterAccount = new Account(abuse.reporterAccount)
- }
+ if (abuse.updatedAt === abuse.createdAt) delete abuse.updatedAt
- if (abuse.flaggedAccount) {
- abuse.flaggedAccount = new Account(abuse.flaggedAccount)
- }
+ abuses.push({
+ ...abuse,
- if (abuse.updatedAt === abuse.createdAt) delete abuse.updatedAt
+ video,
+
+ commentHTML,
+
+ reasonHtml: abuse.reason
+ ? await this.toHtml(abuse.reason)
+ : undefined,
+
+ moderationCommentHtml: (abuse as AdminAbuse).moderationComment
+ ? await this.toHtml((abuse as AdminAbuse).moderationComment)
+ : undefined,
- abuses.push(abuse)
+ reporterAccount: (abuse as AdminAbuse).reporterAccount
+ ? new Account((abuse as AdminAbuse).reporterAccount)
+ : undefined,
+
+ flaggedAccount: abuse.flaggedAccount
+ ? new Account(abuse.flaggedAccount)
+ : undefined
+ })
}
return { total: resultList.total, data: abuses }
@@ -355,7 +349,7 @@ export class AbuseListTableComponent implements OnInit, OnDestroy {
return [
{
- label: $localize`Internal actions`,
+ label: () => $localize`Internal actions`,
isHeader: true,
enableBulk: true
},
@@ -363,25 +357,25 @@ export class AbuseListTableComponent implements OnInit, OnDestroy {
messagesAction,
{
- label: $localize`Set internal note`,
+ label: () => $localize`Set internal note`,
handler: abuses => this.openModerationCommentModal(abuses),
isDisplayed: () => this.isAdminView(),
enableBulk: true
},
{
- label: $localize`Mark as accepted`,
+ label: () => $localize`Mark as accepted`,
handler: abuses => this.updateAbusesState(abuses, AbuseState.ACCEPTED),
isDisplayed: abuse => this.isAdminView() && !this.isAbuseAccepted(abuse),
enableBulk: true
},
{
- label: $localize`Mark as rejected`,
+ label: () => $localize`Mark as rejected`,
handler: abuses => this.updateAbusesState(abuses, AbuseState.REJECTED),
isDisplayed: abuse => this.isAdminView() && !this.isAbuseRejected(abuse),
enableBulk: true
},
{
- label: $localize`Delete report`,
+ label: abuses => formatICU($localize`{count, plural, =1 {Delete report} other {Delete reports}}`, { count: abuses.length }),
handler: abuses => this.removeAbuses(abuses),
isDisplayed: () => this.isAdminView(),
enableBulk: true
@@ -394,21 +388,23 @@ export class AbuseListTableComponent implements OnInit, OnDestroy {
return [
{
- label: $localize`Actions for the flagged account`,
+ label: entries => {
+ return formatICU($localize`Actions for the flagged {count, plural, =1 {account} other {accounts}}`, { count: entries.length })
+ },
isHeader: true,
isDisplayed: abuse => abuse.flaggedAccount && !abuse.comment && !abuse.video,
enableBulk: true
},
{
- label: $localize`Mute account`,
+ label: entries => formatICU($localize`Mute flagged {count, plural, =1 {account} other {accounts}}`, { count: entries.length }),
isDisplayed: abuse => abuse.flaggedAccount && !abuse.comment && !abuse.video,
handler: abuses => this.muteFlaggedAccounts(abuses),
enableBulk: true
},
{
- label: $localize`Mute server account`,
+ label: entries => formatICU($localize`Mute flagged {count, plural, =1 {platform} other {platforms}}`, { count: entries.length }),
isDisplayed: abuse => abuse.flaggedAccount && !abuse.comment && !abuse.video,
handler: abuses => this.muteFlaggedAccountServers(abuses),
enableBulk: true
@@ -421,21 +417,21 @@ export class AbuseListTableComponent implements OnInit, OnDestroy {
return [
{
- label: $localize`Actions for the reporter`,
+ label: entries => formatICU($localize`Actions for the {count, plural, =1 {reporter} other {reporters}}`, { count: entries.length }),
isHeader: true,
isDisplayed: abuse => !!abuse.reporterAccount,
enableBulk: true
},
{
- label: $localize`Mute reporter`,
+ label: entries => formatICU($localize`Mute {count, plural, =1 {reporter} other {reporters}}`, { count: entries.length }),
isDisplayed: abuse => !!abuse.reporterAccount,
handler: abuses => this.muteReporters(abuses),
enableBulk: true
},
{
- label: $localize`Mute reporter server`,
+ label: entries => formatICU($localize`Mute reporter {count, plural, =1 {platform} other {platforms}}`, { count: entries.length }),
isDisplayed: abuse => abuse.reporterAccount && !abuse.reporterAccount.userId,
handler: abuses => this.muteReporterServers(abuses),
enableBulk: true
@@ -448,25 +444,25 @@ export class AbuseListTableComponent implements OnInit, OnDestroy {
return [
{
- label: $localize`Actions for the video`,
+ label: entries => formatICU($localize`Actions for the {count, plural, =1 {video} other {videos}}`, { count: entries.length }),
isHeader: true,
isDisplayed: abuse => abuse.video && !abuse.video.deleted,
enableBulk: true
},
{
- label: $localize`Block video`,
+ label: entries => formatICU($localize`Block the {count, plural, =1 {video} other {videos}}`, { count: entries.length }),
isDisplayed: abuse => abuse.video && !abuse.video.deleted && !abuse.video.blacklisted,
handler: abuses => this.blockAbuseVideos(abuses),
enableBulk: true
},
{
- label: $localize`Unblock video`,
+ label: entries => formatICU($localize`Unblock the {count, plural, =1 {video} other {videos}}`, { count: entries.length }),
isDisplayed: abuse => abuse.video && !abuse.video.deleted && abuse.video.blacklisted,
handler: abuses => this.unblockAbuseVideos(abuses),
enableBulk: true
},
{
- label: $localize`Delete video`,
+ label: entries => formatICU($localize`Delete the {count, plural, =1 {video} other {videos}}`, { count: entries.length }),
isDisplayed: abuse => abuse.video && !abuse.video.deleted,
handler: abuses => this.deleteAbuseVideos(abuses),
enableBulk: true
@@ -479,14 +475,16 @@ export class AbuseListTableComponent implements OnInit, OnDestroy {
return [
{
- label: $localize`Actions for the comment`,
+ label: entries => {
+ return formatICU($localize`Actions for {count, plural, =1 {the comment} other {the comments}}`, { count: entries.length })
+ },
isHeader: true,
isDisplayed: abuse => abuse.comment && !abuse.comment.deleted,
enableBulk: true
},
{
- label: $localize`Delete comment`,
+ label: entries => formatICU($localize`Delete {count, plural, =1 {comment} other {comments}}`, { count: entries.length }),
isDisplayed: abuse => abuse.comment && !abuse.comment.deleted,
handler: abuses => this.deleteAbuseComments(abuses),
enableBulk: true
diff --git a/client/src/app/shared/shared-abuse-list/processed-abuse.model.ts b/client/src/app/shared/shared-abuse-list/processed-abuse.model.ts
index a4b87445ae..bbc09ebcf5 100644
--- a/client/src/app/shared/shared-abuse-list/processed-abuse.model.ts
+++ b/client/src/app/shared/shared-abuse-list/processed-abuse.model.ts
@@ -3,7 +3,7 @@ import { Account } from '../shared-main/account/account.model'
// Don't use an abuse model because we need external services to compute some properties
// And this model is only used in this component
-export type ProcessedAbuse = AdminAbuse & {
+export type ProcessedAbuse = Omit<AdminAbuse, 'reporterAccount' | 'flaggedAccount'> & {
moderationCommentHtml?: string
reasonHtml?: string
updatedAt?: Date
diff --git a/client/src/app/shared/shared-main/buttons/action-dropdown-helpers.ts b/client/src/app/shared/shared-main/buttons/action-dropdown-helpers.ts
index 0a7cf796e0..8325ea5c4a 100644
--- a/client/src/app/shared/shared-main/buttons/action-dropdown-helpers.ts
+++ b/client/src/app/shared/shared-main/buttons/action-dropdown-helpers.ts
@@ -1,19 +1,23 @@
import { DropdownAction } from './action-dropdown.component'
-type DropdownActionForBuilder<T, D = never> =
- & Omit<DropdownAction<T, D>, 'linkBuilder' | 'queryParamsBuilder' | 'handler'>
+export type DropdownActionForBuilder<T, D = never> =
+ & Omit<DropdownAction<T, D>, 'linkBuilder' | 'queryParamsBuilder' | 'handler' | 'label'>
& {
handler?: (a: T[]) => any
}
& (
| {
enableBulk: true
+ // Force label to be a function to avoid mistakes where the developer forgets to use the entry parameter
+ // which is often needed to build the label for bulk actions
+ label: (a: T[]) => string
linkBuilder?: never
queryParamsBuilder?: never
}
| {
enableBulk: false
+ label: string | ((a: T[]) => string)
linkBuilder?: DropdownAction<T, D>['linkBuilder']
queryParamsBuilder?: DropdownAction<T, D>['queryParamsBuilder']
@@ -52,6 +56,11 @@ export function buildDropdownSimpleAndBulkActions<T, D = never> (
for (const action of actions as DropdownActionForBuilder<T, D>[]) {
simpleActions.push({
...action,
+
+ label: typeof action.label === 'string'
+ ? action.label
+ : (entry: T) => (action.label as ((a: T[]) => string))([ entry ]),
+
handler: (a: T) => {
if (action.handler) action.handler([ a ])
}
diff --git a/client/src/app/shared/shared-main/buttons/action-dropdown.component.html b/client/src/app/shared/shared-main/buttons/action-dropdown.component.html
index 232723d314..de3c0317e9 100644
--- a/client/src/app/shared/shared-main/buttons/action-dropdown.component.html
+++ b/client/src/app/shared/shared-main/buttons/action-dropdown.component.html
@@ -17,6 +17,7 @@
<span class="dropdown-toggle me-2">
<span class="d-inline-flex align-items-center gap-2">
{{ label() }}
+
@if (labelExtra) {
<ng-template *ngTemplateOutlet="labelExtra"></ng-template>
}
@@ -31,6 +32,7 @@
<div class="chevron-down"></div>
}
</button>
+
<div ngbDropdownMenu class="dropdown-menu">
@for (actions of getActions(); track $index) {
@for (action of actions; track action.label) {
@@ -45,7 +47,7 @@
<div class="item-label">
<span class="d-inline-flex align-items-center">
- {{ action.label }}
+ {{ getActionLabel(action, entry()) }}
@if (dropdownItemExtra) {
<ng-template *ngTemplateOutlet="dropdownItemExtra; context: { action }"></ng-template>
diff --git a/client/src/app/shared/shared-main/buttons/action-dropdown.component.ts b/client/src/app/shared/shared-main/buttons/action-dropdown.component.ts
index 635f474aa8..f41c09f0e4 100644
--- a/client/src/app/shared/shared-main/buttons/action-dropdown.component.ts
+++ b/client/src/app/shared/shared-main/buttons/action-dropdown.component.ts
@@ -8,7 +8,7 @@ import { GlobalIconComponent } from '../../shared-icons/global-icon.component'
import { CollaboratorStateType } from '../channel/collaborator-state.component'
export type DropdownAction<T, D = never> = {
- label: string
+ label: string | ((a: T) => string)
iconName?: GlobalIconName
@@ -117,4 +117,10 @@ export class ActionDropdownComponent<T, D = never> implements OnChanges {
return action.isDisplayed === undefined || action.isDisplayed(entry) === true
}
+
+ getActionLabel (action: DropdownAction<T, D>, entry: T) {
+ if (typeof action.label === 'function') return action.label(entry)
+
+ return action.label
+ }
}
diff --git a/client/src/app/shared/shared-moderation/account-block-badges.component.html b/client/src/app/shared/shared-moderation/account-block-badges.component.html
index c4ed017d59..b2265c2aec 100644
--- a/client/src/app/shared/shared-moderation/account-block-badges.component.html
+++ b/client/src/app/shared/shared-moderation/account-block-badges.component.html
@@ -1,15 +1,17 @@
-@if (account().mutedByUser) {
+@if (account().mutedByUser || (platformOnly() && account().mutedByInstance)) {
<span class="pt-badge badge-danger" i18n>Muted</span>
}
-@if (account().mutedServerByUser) {
+@if (account().mutedServerByUser || (platformOnly() && account().mutedServerByInstance)) {
<span class="pt-badge badge-danger" i18n>Platform muted</span>
}
-@if (account().mutedByInstance) {
- <span class="pt-badge badge-danger" i18n>Muted by your platform</span>
-}
+@if (!platformOnly()) {
+ @if (account().mutedByInstance) {
+ <span class="pt-badge badge-danger" i18n>Muted by your platform</span>
+ }
-@if (account().mutedServerByInstance) {
- <span class="pt-badge badge-danger" i18n>Platform muted by your platform</span>
+ @if (account().mutedServerByInstance) {
+ <span class="pt-badge badge-danger" i18n>Platform muted by your platform</span>
+ }
}
diff --git a/client/src/app/shared/shared-moderation/account-block-badges.component.ts b/client/src/app/shared/shared-moderation/account-block-badges.component.ts
index a18bd8420d..a1fc86f525 100644
--- a/client/src/app/shared/shared-moderation/account-block-badges.component.ts
+++ b/client/src/app/shared/shared-moderation/account-block-badges.component.ts
@@ -1,4 +1,4 @@
-import { Component, input } from '@angular/core'
+import { booleanAttribute, Component, input } from '@angular/core'
import { Account } from '../shared-main/account/account.model'
@Component({
@@ -8,5 +8,9 @@ import { Account } from '../shared-main/account/account.model'
imports: []
})
export class AccountBlockBadgesComponent {
- readonly account = input<Account>(undefined)
+ readonly account = input.required<
+ Partial<Pick<Account, 'mutedByUser' | 'mutedServerByUser' | 'mutedByInstance' | 'mutedServerByInstance'>>
+ >()
+
+ readonly platformOnly = input(false, { transform: booleanAttribute })
}
diff --git a/client/src/app/shared/shared-moderation/blocklist.service.ts b/client/src/app/shared/shared-moderation/blocklist.service.ts
index 0b7858e45b..a307ea9040 100644
--- a/client/src/app/shared/shared-moderation/blocklist.service.ts
+++ b/client/src/app/shared/shared-moderation/blocklist.service.ts
@@ -1,11 +1,11 @@
-import { SortMeta } from 'primeng/api'
-import { from } from 'rxjs'
-import { catchError, concatMap, map, toArray } from 'rxjs/operators'
import { HttpClient, HttpParams } from '@angular/common/http'
import { Injectable, inject } from '@angular/core'
import { RestExtractor, RestPagination, RestService } from '@app/core'
import { arrayify } from '@peertube/peertube-core-utils'
import { AccountBlock as AccountBlockServer, BlockStatus, ResultList, ServerBlock } from '@peertube/peertube-models'
+import { SortMeta } from 'primeng/api'
+import { from } from 'rxjs'
+import { catchError, concatMap, map, toArray } from 'rxjs/operators'
import { environment } from '../../../environments/environment'
import { Account } from '../shared-main/account/account.model'
import { AccountBlock } from './account-block.model'
@@ -129,11 +129,15 @@ export class BlocklistService {
)
}
- unblockAccountByInstance (account: Pick<Account, 'nameWithHost'>) {
- const path = BlocklistService.BASE_SERVER_BLOCKLIST_URL + '/accounts/' + account.nameWithHost
+ unblockAccountByInstance (accountsArg: Pick<Account, 'nameWithHost'> | Pick<Account, 'nameWithHost'>[]) {
+ const accounts = arrayify(accountsArg)
- return this.authHttp.delete(path)
- .pipe(catchError(err => this.restExtractor.handleError(err)))
+ return from(accounts)
+ .pipe(
+ concatMap(a => this.authHttp.delete(BlocklistService.BASE_SERVER_BLOCKLIST_URL + '/accounts/' + a.nameWithHost)),
+ toArray(),
+ catchError(err => this.restExtractor.handleError(err))
+ )
}
/** ********************* Instance -> Server blocklist ***********************/
@@ -161,11 +165,15 @@ export class BlocklistService {
)
}
- unblockServerByInstance (host: string) {
- const path = BlocklistService.BASE_SERVER_BLOCKLIST_URL + '/servers/' + host
+ unblockServerByInstance (hostsArg: string | string[]) {
+ const hosts = arrayify(hostsArg)
- return this.authHttp.delete(path)
- .pipe(catchError(err => this.restExtractor.handleError(err)))
+ return from(hosts)
+ .pipe(
+ concatMap(host => this.authHttp.delete(BlocklistService.BASE_SERVER_BLOCKLIST_URL + '/servers/' + host)),
+ toArray(),
+ catchError(err => this.restExtractor.handleError(err))
+ )
}
private formatAccountBlock (accountBlock: AccountBlockServer) {
diff --git a/client/src/app/shared/shared-tables/table.component.ts b/client/src/app/shared/shared-tables/table.component.ts
index 963ad90cfa..3843012033 100644
--- a/client/src/app/shared/shared-tables/table.component.ts
+++ b/client/src/app/shared/shared-tables/table.component.ts
@@ -171,6 +171,7 @@ export class TableComponent<
readonly rowReorder = output<TableRowReorderEvent>()
readonly filtersChange = output<Partial<DataLoaderOptions>>()
readonly searchChange = output<string>()
+ readonly dataLoaded = output<Data[]>()
selectedRows: Data[] = []
expandedRows = {}
@@ -546,6 +547,8 @@ export class TableComponent<
this.totalRecords = resultList.total
this.loaded = true
+ this.dataLoaded.emit(resultList.data)
+
res()
},
diff --git a/client/src/app/shared/shared-video-comment/video-comment-list-admin-owner.component.html b/client/src/app/shared/shared-video-comment/video-comment-list-admin-owner.component.html
index e3acfe06c5..bce967c237 100644
--- a/client/src/app/shared/shared-video-comment/video-comment-list-admin-owner.component.html
+++ b/client/src/app/shared/shared-video-comment/video-comment-list-admin-owner.component.html
@@ -10,6 +10,7 @@
[inputFilters]="inputFilters"
searchInput="true"
refreshButton="true"
+ (dataLoaded)="onDataLoaded()"
>
<ng-template #totalTitle let-totalRecords>
@@ -45,15 +46,19 @@
@if (table.isColumnDisplayed('account')) {
<td>
- <a routerLink="." [queryParams]="{ searchAccount: comment.account.name }" i18n-title title="Filter by this account">
- <div class="chip two-lines">
- <my-actor-avatar [actor]="comment.account" actorType="account" size="32"></my-actor-avatar>
- <div>
- {{ comment.account.displayName }}
- <span>{{ comment.by }}</span>
+ <div class="d-flex flex-column gap-1">
+ <a routerLink="." [queryParams]="{ searchAccount: comment.account.name }" i18n-title title="Filter by this account">
+ <div class="chip two-lines">
+ <my-actor-avatar [actor]="comment.account" actorType="account" size="32"></my-actor-avatar>
+ <div>
+ {{ comment.account.displayName }}
+ <span>{{ comment.by }}</span>
+ </div>
</div>
- </div>
- </a>
+ </a>
+
+ <my-account-block-badges [account]="comment.account" platformOnly="true"></my-account-block-badges>
+ </div>
</td>
}
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.ts
index d5b2397cf9..1a0f3d5c31 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
@@ -8,6 +8,7 @@ import { VideoCommentService } from '@app/shared/shared-video-comment/video-comm
import { BulkRemoveCommentsOfBody, UserRight } from '@peertube/peertube-models'
import { switchMap } from 'rxjs'
import { ActorAvatarComponent } from '../shared-actor-image/actor-avatar.component'
+import { Actor } from '../shared-main/account/actor.model'
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'
@@ -15,6 +16,8 @@ import { ActionDropdownComponent, DropdownAction } from '../shared-main/buttons/
import { CollaboratorStateComponent } from '../shared-main/channel/collaborator-state.component'
import { PTDatePipe } from '../shared-main/common/date.pipe'
import { NumberFormatterPipe } from '../shared-main/common/number-formatter.pipe'
+import { AccountBlockBadgesComponent } from '../shared-moderation/account-block-badges.component'
+import { BlocklistService } from '../shared-moderation/blocklist.service'
import { DataLoaderOptionsBase, TableColumnInfo, TableComponent } from '../shared-tables/table.component'
type DataLoaderParameter = Parameters<VideoCommentListAdminOwnerComponent['_dataLoader']>[0]
@@ -38,7 +41,8 @@ type ColumnName =
TableComponent,
NumberFormatterPipe,
GlobalIconComponent,
- CollaboratorStateComponent
+ CollaboratorStateComponent,
+ AccountBlockBadgesComponent
]
})
export class VideoCommentListAdminOwnerComponent implements OnInit, OnDestroy {
@@ -50,6 +54,7 @@ export class VideoCommentListAdminOwnerComponent implements OnInit, OnDestroy {
private bulkService = inject(BulkService)
private hooks = inject(HooksService)
private pluginService = inject(PluginService)
+ private blocklist = inject(BlocklistService)
readonly key = input.required<string>()
readonly mode = input.required<'user' | 'admin'>()
@@ -98,7 +103,15 @@ export class VideoCommentListAdminOwnerComponent implements OnInit, OnDestroy {
const { simpleActions, bulkActions } = buildDropdownSimpleAndBulkActions<VideoCommentForAdminOrUser>([
[
{
- label: $localize`Delete this comment`,
+ label: $localize`Go to account page`,
+ linkBuilder: comment => [ comment.account.localUrl ],
+ isDisplayed: () => this.mode() === 'admin',
+ enableBulk: false
+ }
+ ],
+ [
+ {
+ label: comments => formatICU($localize`{count, plural, =1 {Delete comment} other {Delete comments}}`, { count: comments.length }),
handler: comments => this.removeComments(comments),
isDisplayed: () => this.mode() === 'user' || this.user.hasRight(UserRight.MANAGE_ANY_VIDEO_COMMENT),
enableBulk: true
@@ -125,11 +138,83 @@ export class VideoCommentListAdminOwnerComponent implements OnInit, OnDestroy {
],
[
{
- label: $localize`Approve this comment`,
+ label: comments => {
+ return formatICU($localize`{count, plural, =1 {Approve comment} other {Approve comments}}`, { count: comments.length })
+ },
+
handler: comments => this.approveComments(comments),
isDisplayed: comment => this.mode() === 'user' && comment.heldForReview,
enableBulk: true
}
+ ],
+ [
+ {
+ label: comments => {
+ return formatICU(
+ $localize`{count, plural, =1 {Mute account} other {Mute accounts}}`,
+ { count: this.getUniqueAccounts(comments).length }
+ )
+ },
+
+ handler: comments => this.muteAccount(comments),
+ isDisplayed: comment => {
+ return this.mode() === 'admin' &&
+ comment.account &&
+ !comment.account.mutedByInstance &&
+ this.user.hasRight(UserRight.MANAGE_ACCOUNTS_BLOCKLIST)
+ },
+
+ enableBulk: true
+ },
+ {
+ label: comments => {
+ return formatICU(
+ $localize`{count, plural, =1 {Unmute account} other {Unmute accounts}}`,
+ { count: this.getUniqueAccounts(comments).length }
+ )
+ },
+ handler: comments => this.unmuteAccount(comments),
+ isDisplayed: comment => {
+ return this.mode() === 'admin' &&
+ comment.account &&
+ comment.account.mutedByInstance &&
+ this.user.hasRight(UserRight.MANAGE_ACCOUNTS_BLOCKLIST)
+ },
+ enableBulk: true
+ },
+ {
+ label: comments => {
+ return formatICU(
+ $localize`{count, plural, =1 {Mute platform} other {Mute platforms}}`,
+ { count: this.getUniqueHosts(comments).length }
+ )
+ },
+ handler: comments => this.muteServer(comments),
+ isDisplayed: comment => {
+ return this.mode() === 'admin' &&
+ comment.account &&
+ !comment.account.mutedServerByInstance &&
+ this.user.hasRight(UserRight.MANAGE_SERVERS_BLOCKLIST)
+ },
+ enableBulk: true
+ },
+ {
+ label: comments => {
+ return formatICU(
+ $localize`{count, plural, =1 {Unmute platform} other {Unmute platforms}}`,
+ { count: this.getUniqueHosts(comments).length }
+ )
+ },
+ handler: comments => this.unmuteServer(comments),
+ isDisplayed: comment => {
+ return this.mode() === 'admin' &&
+ comment.account &&
+ !Actor.IS_LOCAL(comment.account.host) &&
+ comment.account.mutedServerByInstance &&
+ this.user.hasRight(UserRight.MANAGE_SERVERS_BLOCKLIST)
+ },
+ enableBulk: true
+ }
]
])
@@ -238,6 +323,25 @@ export class VideoCommentListAdminOwnerComponent implements OnInit, OnDestroy {
)
}
+ onDataLoaded () {
+ if (this.mode() === 'admin') {
+ this.loadBlockStatus()
+ }
+ }
+
+ private loadBlockStatus () {
+ const accounts = this.table().data.map(c => c.account)
+ const hosts = [ ...new Set(accounts.map(a => a.host)) ]
+
+ this.blocklist.getStatus({ accounts: accounts.map(a => a.nameWithHostForced), hosts })
+ .subscribe(status => {
+ for (const a of accounts) {
+ a.mutedByInstance = status.accounts[a.nameWithHostForced].blockedByServer
+ a.mutedServerByInstance = status.hosts[a.host].blockedByServer
+ }
+ })
+ }
+
private approveComments (comments: VideoCommentForAdminOrUser[]) {
const commentArgs = comments.map(c => ({ videoId: c.video.id, commentId: c.id }))
@@ -307,4 +411,102 @@ export class VideoCommentListAdminOwnerComponent implements OnInit, OnDestroy {
error: err => this.notifier.handleError(err)
})
}
+
+ private getUniqueAccounts (comments: VideoCommentForAdminOrUser[]) {
+ const accountsDone = new Set<number>()
+
+ return comments
+ .map(a => {
+ if (!a.account || accountsDone.has(a.account.id)) return null
+
+ accountsDone.add(a.account.id)
+ return a.account
+ }).filter(a => !!a)
+ }
+
+ private getUniqueHosts (comments: VideoCommentForAdminOrUser[]) {
+ return Array.from(new Set(comments.map(c => c.account?.host).filter(h => !!h)))
+ }
+
+ private muteAccount (comments: VideoCommentForAdminOrUser[]) {
+ const accounts = this.getUniqueAccounts(comments)
+ .map(account => ({ nameWithHost: Actor.CREATE_BY_STRING(account.name, account.host) }))
+
+ this.blocklist.blockAccountByInstance(accounts)
+ .subscribe({
+ next: () => {
+ this.notifier.success(
+ formatICU(
+ $localize`{count, plural, =1 {Account muted.} other {{count} accounts muted.}}`,
+ { count: accounts.length }
+ )
+ )
+
+ this.loadBlockStatus()
+ },
+
+ error: err => this.notifier.handleError(err)
+ })
+ }
+
+ private unmuteAccount (comments: VideoCommentForAdminOrUser[]) {
+ const accounts = this.getUniqueAccounts(comments)
+ .map(account => ({ nameWithHost: Actor.CREATE_BY_STRING(account.name, account.host) }))
+
+ this.blocklist.unblockAccountByInstance(accounts)
+ .subscribe({
+ next: () => {
+ this.notifier.success(
+ formatICU(
+ $localize`{count, plural, =1 {Account unmuted.} other {{count} accounts unmuted.}}`,
+ { count: accounts.length }
+ )
+ )
+
+ this.loadBlockStatus()
+ },
+
+ error: err => this.notifier.handleError(err)
+ })
+ }
+
+ private muteServer (comments: VideoCommentForAdminOrUser[]) {
+ const hosts = this.getUniqueHosts(comments)
+
+ this.blocklist.blockServerByInstance(hosts)
+ .subscribe({
+ next: () => {
+ this.notifier.success(
+ formatICU(
+ $localize`{count, plural, =1 {Platform muted.} other {{count} platforms muted.}}`,
+ { count: hosts.length }
+ )
+ )
+
+ this.loadBlockStatus()
+ },
+
+ error: err => this.notifier.handleError(err)
+ })
+ }
+
+ private unmuteServer (comments: VideoCommentForAdminOrUser[]) {
+ const hosts = this.getUniqueHosts(comments)
+
+ this.blocklist.unblockServerByInstance(hosts)
+ .subscribe({
+ next: () => {
+ this.notifier.success(
+ formatICU(
+ $localize`{count, plural, =1 {Platform unmuted.} other {{count} platforms unmuted.}}`,
+ { count: hosts.length }
+ )
+ )
+
+ this.loadBlockStatus()
+ },
+
+ error: err => this.notifier.handleError(err)
+ })
+ }
}
diff --git a/client/src/app/shared/shared-video-comment/video-comment.model.ts b/client/src/app/shared/shared-video-comment/video-comment.model.ts
index b1c2f40691..15b1600fc1 100644
--- a/client/src/app/shared/shared-video-comment/video-comment.model.ts
+++ b/client/src/app/shared/shared-video-comment/video-comment.model.ts
@@ -63,7 +63,14 @@ export class VideoCommentForAdminOrUser implements VideoCommentForAdminOrUserSer
createdAt: Date | string
updatedAt: Date | string
- account: AccountInterface & { localUrl?: string }
+ account: AccountInterface & {
+ mutedByInstance: boolean
+ mutedServerByInstance: boolean
+
+ localUrl: string
+ nameWithHostForced: string
+ }
+
localUrl: string
video: {
@@ -108,12 +115,18 @@ export class VideoCommentForAdminOrUser implements VideoCommentForAdminOrUserSer
this.localUrl = this.video.localUrl + ';threadId=' + this.threadId
- this.account = hash.account
+ if (hash.account) {
+ this.by = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
- if (this.account) {
- this.by = Actor.CREATE_BY_STRING(this.account.name, this.account.host)
+ this.account = {
+ ...hash.account,
+
+ mutedByInstance: false,
+ mutedServerByInstance: false,
- this.account.localUrl = '/a/' + this.by
+ localUrl: '/a/' + this.by,
+ nameWithHostForced: Actor.CREATE_BY_STRING(hash.account.name, hash.account.host, true)
+ }
}
}
}
diff --git a/packages/models/src/moderation/abuse/abuse.model.ts b/packages/models/src/moderation/abuse/abuse.model.ts
index 9e25bff91c..386172edf1 100644
--- a/packages/models/src/moderation/abuse/abuse.model.ts
+++ b/packages/models/src/moderation/abuse/abuse.model.ts
@@ -52,8 +52,8 @@ export interface AdminAbuse {
reason: string
predefinedReasons?: AbusePredefinedReasonsString[]
- reporterAccount: Account
- flaggedAccount: Account
+ reporterAccount?: Account
+ flaggedAccount?: Account
state: ConstantLabel<AbuseStateType>
moderationComment?: string