From e3d6c6434f570f77c0532f86c82f78bcafb399ec Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 27 Jul 2022 13:44:40 +0200 Subject: Add bulk action on following/followers --- .../shared-instance/instance-follow.service.ts | 69 ++++++++++++++++------ .../app/shared/shared-main/video/video.service.ts | 3 +- .../shared/shared-moderation/blocklist.service.ts | 3 +- .../shared-moderation/video-block.service.ts | 3 +- .../app/shared/shared-users/user-admin.service.ts | 7 ++- 5 files changed, 61 insertions(+), 24 deletions(-) (limited to 'client/src/app/shared') diff --git a/client/src/app/shared/shared-instance/instance-follow.service.ts b/client/src/app/shared/shared-instance/instance-follow.service.ts index 06484d938..5366fd068 100644 --- a/client/src/app/shared/shared-instance/instance-follow.service.ts +++ b/client/src/app/shared/shared-instance/instance-follow.service.ts @@ -1,9 +1,10 @@ import { SortMeta } from 'primeng/api' -import { Observable } from 'rxjs' -import { catchError, map } from 'rxjs/operators' +import { from, Observable } 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 { arrayify } from '@shared/core-utils' import { ActivityPubActorType, ActorFollow, FollowState, ResultList, ServerFollowCreate } from '@shared/models' import { environment } from '../../../environments/environment' import { AdvancedInputFilter } from '../shared-forms' @@ -81,32 +82,64 @@ export class InstanceFollowService { .pipe(catchError(res => this.restExtractor.handleError(res))) } - unfollow (follow: ActorFollow) { - const handle = follow.following.name + '@' + follow.following.host + unfollow (followsArg: ActorFollow[] | ActorFollow) { + const follows = arrayify(followsArg) - return this.authHttp.delete(InstanceFollowService.BASE_APPLICATION_URL + '/following/' + handle) - .pipe(catchError(res => this.restExtractor.handleError(res))) + return from(follows) + .pipe( + concatMap(follow => { + const handle = follow.following.name + '@' + follow.following.host + + return this.authHttp.delete(InstanceFollowService.BASE_APPLICATION_URL + '/following/' + handle) + }), + toArray(), + catchError(err => this.restExtractor.handleError(err)) + ) } - acceptFollower (follow: ActorFollow) { - const handle = follow.follower.name + '@' + follow.follower.host + acceptFollower (followsArg: ActorFollow[] | ActorFollow) { + const follows = arrayify(followsArg) - return this.authHttp.post(`${InstanceFollowService.BASE_APPLICATION_URL}/followers/${handle}/accept`, {}) - .pipe(catchError(res => this.restExtractor.handleError(res))) + return from(follows) + .pipe( + concatMap(follow => { + const handle = follow.follower.name + '@' + follow.follower.host + + return this.authHttp.post(`${InstanceFollowService.BASE_APPLICATION_URL}/followers/${handle}/accept`, {}) + }), + toArray(), + catchError(err => this.restExtractor.handleError(err)) + ) } - rejectFollower (follow: ActorFollow) { - const handle = follow.follower.name + '@' + follow.follower.host + rejectFollower (followsArg: ActorFollow[] | ActorFollow) { + const follows = arrayify(followsArg) - return this.authHttp.post(`${InstanceFollowService.BASE_APPLICATION_URL}/followers/${handle}/reject`, {}) - .pipe(catchError(res => this.restExtractor.handleError(res))) + return from(follows) + .pipe( + concatMap(follow => { + const handle = follow.follower.name + '@' + follow.follower.host + + return this.authHttp.post(`${InstanceFollowService.BASE_APPLICATION_URL}/followers/${handle}/reject`, {}) + }), + toArray(), + catchError(err => this.restExtractor.handleError(err)) + ) } - removeFollower (follow: ActorFollow) { - const handle = follow.follower.name + '@' + follow.follower.host + removeFollower (followsArg: ActorFollow[] | ActorFollow) { + const follows = arrayify(followsArg) - return this.authHttp.delete(`${InstanceFollowService.BASE_APPLICATION_URL}/followers/${handle}`) - .pipe(catchError(res => this.restExtractor.handleError(res))) + return from(follows) + .pipe( + concatMap(follow => { + const handle = follow.follower.name + '@' + follow.follower.host + + return this.authHttp.delete(`${InstanceFollowService.BASE_APPLICATION_URL}/followers/${handle}`) + }), + toArray(), + catchError(err => this.restExtractor.handleError(err)) + ) } buildFollowsListFilters (): AdvancedInputFilter[] { diff --git a/client/src/app/shared/shared-main/video/video.service.ts b/client/src/app/shared/shared-main/video/video.service.ts index 4fbc4f7f6..f2bf02695 100644 --- a/client/src/app/shared/shared-main/video/video.service.ts +++ b/client/src/app/shared/shared-main/video/video.service.ts @@ -5,6 +5,7 @@ import { HttpClient, HttpParams, HttpRequest } from '@angular/common/http' import { Injectable } from '@angular/core' import { AuthService, ComponentPaginationLight, RestExtractor, RestService, ServerService, UserService } from '@app/core' import { objectToFormData } from '@app/helpers' +import { arrayify } from '@shared/core-utils' import { BooleanBothQuery, FeedFormat, @@ -285,7 +286,7 @@ export class VideoService { } removeVideo (idArg: number | number[]) { - const ids = Array.isArray(idArg) ? idArg : [ idArg ] + const ids = arrayify(idArg) return from(ids) .pipe( diff --git a/client/src/app/shared/shared-moderation/blocklist.service.ts b/client/src/app/shared/shared-moderation/blocklist.service.ts index 3e92c2831..1169bf757 100644 --- a/client/src/app/shared/shared-moderation/blocklist.service.ts +++ b/client/src/app/shared/shared-moderation/blocklist.service.ts @@ -4,6 +4,7 @@ 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 { 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' @@ -122,7 +123,7 @@ export class BlocklistService { } blockAccountByInstance (accountsArg: Pick | Pick[]) { - const accounts = Array.isArray(accountsArg) ? accountsArg : [ accountsArg ] + const accounts = arrayify(accountsArg) return from(accounts) .pipe( diff --git a/client/src/app/shared/shared-moderation/video-block.service.ts b/client/src/app/shared/shared-moderation/video-block.service.ts index 5dfb0d7d4..6272b672f 100644 --- a/client/src/app/shared/shared-moderation/video-block.service.ts +++ b/client/src/app/shared/shared-moderation/video-block.service.ts @@ -4,6 +4,7 @@ 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 { arrayify } from '@shared/core-utils' import { ResultList, VideoBlacklist, VideoBlacklistType } from '@shared/models' import { environment } from '../../../environments/environment' @@ -53,7 +54,7 @@ export class VideoBlockService { } unblockVideo (videoIdArgs: number | number[]) { - const videoIds = Array.isArray(videoIdArgs) ? videoIdArgs : [ videoIdArgs ] + const videoIds = arrayify(videoIdArgs) return observableFrom(videoIds) .pipe( diff --git a/client/src/app/shared/shared-users/user-admin.service.ts b/client/src/app/shared/shared-users/user-admin.service.ts index 3db271c4a..422221d62 100644 --- a/client/src/app/shared/shared-users/user-admin.service.ts +++ b/client/src/app/shared/shared-users/user-admin.service.ts @@ -5,6 +5,7 @@ import { HttpClient, HttpParams } from '@angular/common/http' import { Injectable } from '@angular/core' import { RestExtractor, RestPagination, RestService, UserService } from '@app/core' import { getBytes } from '@root-helpers/bytes' +import { arrayify } from '@shared/core-utils' import { ResultList, User as UserServerModel, UserCreate, UserRole, UserUpdate } from '@shared/models' @Injectable() @@ -65,7 +66,7 @@ export class UserAdminService { } removeUser (usersArg: UserServerModel | UserServerModel[]) { - const users = Array.isArray(usersArg) ? usersArg : [ usersArg ] + const users = arrayify(usersArg) return from(users) .pipe( @@ -77,7 +78,7 @@ export class UserAdminService { banUsers (usersArg: UserServerModel | UserServerModel[], reason?: string) { const body = reason ? { reason } : {} - const users = Array.isArray(usersArg) ? usersArg : [ usersArg ] + const users = arrayify(usersArg) return from(users) .pipe( @@ -88,7 +89,7 @@ export class UserAdminService { } unbanUsers (usersArg: UserServerModel | UserServerModel[]) { - const users = Array.isArray(usersArg) ? usersArg : [ usersArg ] + const users = arrayify(usersArg) return from(users) .pipe( -- cgit v1.2.3