X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fshared-moderation%2Fblocklist.service.ts;h=0fb7536e57266b4ebb2a18df2566caae439ccc88;hb=77239b425a8e00822a53c9907415832a473c3eb6;hp=db2a8c5846ea920cfda02045344f5c6f8cd6aa3b;hpb=9df52d660feb722404be00a50f3c8a612bec1c15;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/shared/shared-moderation/blocklist.service.ts b/client/src/app/shared/shared-moderation/blocklist.service.ts index db2a8c584..0fb7536e5 100644 --- a/client/src/app/shared/shared-moderation/blocklist.service.ts +++ b/client/src/app/shared/shared-moderation/blocklist.service.ts @@ -1,9 +1,11 @@ import { SortMeta } from 'primeng/api' -import { catchError, map } from 'rxjs/operators' +import { from } from 'rxjs' +import { catchError, concatMap, map, toArray } from 'rxjs/operators' import { HttpClient, HttpParams } from '@angular/common/http' import { Injectable } from '@angular/core' import { RestExtractor, RestPagination, RestService } from '@app/core' -import { AccountBlock as AccountBlockServer, ResultList, ServerBlock } from '@shared/models' +import { arrayify } from '@shared/core-utils' +import { AccountBlock as AccountBlockServer, BlockStatus, ResultList, ServerBlock } from '@shared/models' import { environment } from '../../../environments/environment' import { Account } from '../shared-main' import { AccountBlock } from './account-block.model' @@ -12,6 +14,7 @@ export enum BlocklistComponentType { Account, Instance } @Injectable() export class BlocklistService { + static BASE_BLOCKLIST_URL = environment.apiUrl + '/api/v1/blocklist' static BASE_USER_BLOCKLIST_URL = environment.apiUrl + '/api/v1/users/me/blocklist' static BASE_SERVER_BLOCKLIST_URL = environment.apiUrl + '/api/v1/server/blocklist' @@ -21,6 +24,23 @@ export class BlocklistService { private restService: RestService ) { } + /** ********************* Blocklist status ***********************/ + + getStatus (options: { + accounts?: string[] + hosts?: string[] + }) { + const { accounts, hosts } = options + + let params = new HttpParams() + + if (accounts) params = this.restService.addArrayParams(params, 'accounts', accounts) + if (hosts) params = this.restService.addArrayParams(params, 'hosts', hosts) + + return this.authHttp.get(BlocklistService.BASE_BLOCKLIST_URL + '/status', { params }) + .pipe(catchError(err => this.restExtractor.handleError(err))) + } + /** ********************* User -> Account blocklist ***********************/ getUserAccountBlocklist (options: { pagination: RestPagination, sort: SortMeta, search?: string }) { @@ -33,7 +53,6 @@ export class BlocklistService { return this.authHttp.get>(BlocklistService.BASE_USER_BLOCKLIST_URL + '/accounts', { params }) .pipe( - map(res => this.restExtractor.convertResultListDateToHuman(res)), map(res => this.restExtractor.applyToResultListData(res, this.formatAccountBlock.bind(this))), catchError(err => this.restExtractor.handleError(err)) ) @@ -64,10 +83,7 @@ export class BlocklistService { if (search) params = params.append('search', search) return this.authHttp.get>(BlocklistService.BASE_USER_BLOCKLIST_URL + '/servers', { params }) - .pipe( - map(res => this.restExtractor.convertResultListDateToHuman(res)), - catchError(err => this.restExtractor.handleError(err)) - ) + .pipe(catchError(err => this.restExtractor.handleError(err))) } blockServerByUser (host: string) { @@ -96,17 +112,20 @@ export class BlocklistService { return this.authHttp.get>(BlocklistService.BASE_SERVER_BLOCKLIST_URL + '/accounts', { params }) .pipe( - map(res => this.restExtractor.convertResultListDateToHuman(res)), map(res => this.restExtractor.applyToResultListData(res, this.formatAccountBlock.bind(this))), catchError(err => this.restExtractor.handleError(err)) ) } - blockAccountByInstance (account: Pick) { - const body = { accountName: account.nameWithHost } + blockAccountByInstance (accountsArg: Pick | Pick[]) { + const accounts = arrayify(accountsArg) - return this.authHttp.post(BlocklistService.BASE_SERVER_BLOCKLIST_URL + '/accounts', body) - .pipe(catchError(err => this.restExtractor.handleError(err))) + return from(accounts) + .pipe( + concatMap(a => this.authHttp.post(BlocklistService.BASE_SERVER_BLOCKLIST_URL + '/accounts', { accountName: a.nameWithHost })), + toArray(), + catchError(err => this.restExtractor.handleError(err)) + ) } unblockAccountByInstance (account: Pick) { @@ -127,10 +146,7 @@ export class BlocklistService { if (search) params = params.append('search', search) return this.authHttp.get>(BlocklistService.BASE_SERVER_BLOCKLIST_URL + '/servers', { params }) - .pipe( - map(res => this.restExtractor.convertResultListDateToHuman(res)), - catchError(err => this.restExtractor.handleError(err)) - ) + .pipe(catchError(err => this.restExtractor.handleError(err))) } blockServerByInstance (host: string) {