From 65b21c961c69c4a63c7c0c34be3d6d034a1176c7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 15 Oct 2018 16:43:14 +0200 Subject: Add ability to mute a user/instance by server in client --- .../app/shared/blocklist/account-block.model.ts | 2 +- .../src/app/shared/blocklist/blocklist.service.ts | 56 ++++++++++++++++++++++ client/src/app/shared/blocklist/index.ts | 2 +- 3 files changed, 58 insertions(+), 2 deletions(-) (limited to 'client/src/app/shared/blocklist') diff --git a/client/src/app/shared/blocklist/account-block.model.ts b/client/src/app/shared/blocklist/account-block.model.ts index 336680f65..e7b433d88 100644 --- a/client/src/app/shared/blocklist/account-block.model.ts +++ b/client/src/app/shared/blocklist/account-block.model.ts @@ -11,4 +11,4 @@ export class AccountBlock implements AccountBlockServer { this.blockedAccount = new Account(block.blockedAccount) this.createdAt = block.createdAt } -} \ No newline at end of file +} diff --git a/client/src/app/shared/blocklist/blocklist.service.ts b/client/src/app/shared/blocklist/blocklist.service.ts index d9c318258..c1f7312f0 100644 --- a/client/src/app/shared/blocklist/blocklist.service.ts +++ b/client/src/app/shared/blocklist/blocklist.service.ts @@ -11,6 +11,7 @@ import { AccountBlock } from '@app/shared/blocklist/account-block.model' @Injectable() export class BlocklistService { static BASE_USER_BLOCKLIST_URL = environment.apiUrl + '/api/v1/users/me/blocklist' + static BASE_SERVER_BLOCKLIST_URL = environment.apiUrl + '/api/v1/server/blocklist' constructor ( private authHttp: HttpClient, @@ -73,6 +74,61 @@ export class BlocklistService { .pipe(catchError(err => this.restExtractor.handleError(err))) } + /*********************** Instance -> Account blocklist ***********************/ + + getInstanceAccountBlocklist (pagination: RestPagination, sort: SortMeta) { + let params = new HttpParams() + params = this.restService.addRestGetParams(params, pagination, sort) + + 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: Account) { + const body = { accountName: account.nameWithHost } + + return this.authHttp.post(BlocklistService.BASE_SERVER_BLOCKLIST_URL + '/accounts', body) + .pipe(catchError(err => this.restExtractor.handleError(err))) + } + + unblockAccountByInstance (account: Account) { + const path = BlocklistService.BASE_SERVER_BLOCKLIST_URL + '/accounts/' + account.nameWithHost + + return this.authHttp.delete(path) + .pipe(catchError(err => this.restExtractor.handleError(err))) + } + + /*********************** Instance -> Server blocklist ***********************/ + + getInstanceServerBlocklist (pagination: RestPagination, sort: SortMeta) { + let params = new HttpParams() + params = this.restService.addRestGetParams(params, pagination, sort) + + return this.authHttp.get>(BlocklistService.BASE_SERVER_BLOCKLIST_URL + '/servers', { params }) + .pipe( + map(res => this.restExtractor.convertResultListDateToHuman(res)), + catchError(err => this.restExtractor.handleError(err)) + ) + } + + blockServerByInstance (host: string) { + const body = { host } + + return this.authHttp.post(BlocklistService.BASE_SERVER_BLOCKLIST_URL + '/servers', body) + .pipe(catchError(err => this.restExtractor.handleError(err))) + } + + unblockServerByInstance (host: string) { + const path = BlocklistService.BASE_SERVER_BLOCKLIST_URL + '/servers/' + host + + return this.authHttp.delete(path) + .pipe(catchError(err => this.restExtractor.handleError(err))) + } + private formatAccountBlock (accountBlock: AccountBlockServer) { return new AccountBlock(accountBlock) } diff --git a/client/src/app/shared/blocklist/index.ts b/client/src/app/shared/blocklist/index.ts index 8cf6a55f7..5886ca07e 100644 --- a/client/src/app/shared/blocklist/index.ts +++ b/client/src/app/shared/blocklist/index.ts @@ -1,2 +1,2 @@ export * from './blocklist.service' -export * from './account-block.model' \ No newline at end of file +export * from './account-block.model' -- cgit v1.2.3