From dac2cbfabd98b48373df9e3fca3d5efa15a57f5c Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Wed, 3 Jul 2019 18:43:37 -0400 Subject: [PATCH] added mute block capability --- .../status/action-bar/action-bar.component.ts | 24 +++++++++++++++++-- src/app/services/mastodon.service.ts | 14 ++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/app/components/stream/status/action-bar/action-bar.component.ts b/src/app/components/stream/status/action-bar/action-bar.component.ts index 432124ba..44d711d5 100644 --- a/src/app/components/stream/status/action-bar/action-bar.component.ts +++ b/src/app/components/stream/status/action-bar/action-bar.component.ts @@ -71,6 +71,7 @@ export class ActionBarComponent implements OnInit, OnDestroy { username: string; private fullHandle: string; private displayedStatus: Status; + private loadedAccounts: AccountInfo[]; ngOnInit() { const status = this.statusWrapper.status; @@ -89,6 +90,7 @@ export class ActionBarComponent implements OnInit, OnDestroy { } this.accountSub = this.accounts$.subscribe((accounts: AccountInfo[]) => { + this.loadedAccounts = accounts; this.checkStatus(accounts); }); } @@ -271,6 +273,7 @@ export class ActionBarComponent implements OnInit, OnDestroy { } mentionAccount(): boolean { + return false; } @@ -281,13 +284,30 @@ export class ActionBarComponent implements OnInit, OnDestroy { } muteAccount(): boolean { - + this.loadedAccounts.forEach(acc => { + this.toolsService.findAccount(acc, this.fullHandle) + .then((target: Account) => { + this.mastodonService.mute(acc, target.id); + }) + .catch(err => { + this.notificationService.notifyHttpError(err); + }); + }); + return false; } blockAccount(): boolean { + this.loadedAccounts.forEach(acc => { + this.toolsService.findAccount(acc, this.fullHandle) + .then((target: Account) => { + this.mastodonService.block(acc, target.id); + }) + .catch(err => { + this.notificationService.notifyHttpError(err); + }); + }); return false; } - } diff --git a/src/app/services/mastodon.service.ts b/src/app/services/mastodon.service.ts index afbf664a..134276f8 100644 --- a/src/app/services/mastodon.service.ts +++ b/src/app/services/mastodon.service.ts @@ -7,7 +7,7 @@ import { AccountInfo } from '../states/accounts.state'; import { StreamTypeEnum, StreamElement } from '../states/streams.state'; @Injectable() -export class MastodonService { +export class MastodonService { private apiRoutes = new ApiRoutes(); constructor(private readonly httpClient: HttpClient) { } @@ -319,6 +319,18 @@ export class MastodonService { let route = `https://${account.instance}${this.apiRoutes.getPoll}`.replace('{0}', pollId); const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` }); return this.httpClient.get(route, { headers: headers }).toPromise(); + } + + mute(account: AccountInfo, accounId: number): Promise { + let route = `https://${account.instance}${this.apiRoutes.mute}`.replace('{0}', accounId.toString()); + const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` }); + return this.httpClient.post(route, null, { headers: headers }).toPromise(); + } + + block(account: AccountInfo, accounId: number): Promise { + let route = `https://${account.instance}${this.apiRoutes.block}`.replace('{0}', accounId.toString()); + const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` }); + return this.httpClient.post(route, null, { headers: headers }).toPromise(); } }