added mute block capability

This commit is contained in:
Nicolas Constant 2019-07-03 18:43:37 -04:00
parent a35c7e911d
commit dac2cbfabd
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
2 changed files with 35 additions and 3 deletions

View File

@ -71,6 +71,7 @@ export class ActionBarComponent implements OnInit, OnDestroy {
username: string; username: string;
private fullHandle: string; private fullHandle: string;
private displayedStatus: Status; private displayedStatus: Status;
private loadedAccounts: AccountInfo[];
ngOnInit() { ngOnInit() {
const status = this.statusWrapper.status; const status = this.statusWrapper.status;
@ -89,6 +90,7 @@ export class ActionBarComponent implements OnInit, OnDestroy {
} }
this.accountSub = this.accounts$.subscribe((accounts: AccountInfo[]) => { this.accountSub = this.accounts$.subscribe((accounts: AccountInfo[]) => {
this.loadedAccounts = accounts;
this.checkStatus(accounts); this.checkStatus(accounts);
}); });
} }
@ -271,6 +273,7 @@ export class ActionBarComponent implements OnInit, OnDestroy {
} }
mentionAccount(): boolean { mentionAccount(): boolean {
return false; return false;
} }
@ -281,13 +284,30 @@ export class ActionBarComponent implements OnInit, OnDestroy {
} }
muteAccount(): boolean { 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; return false;
} }
blockAccount(): boolean { 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; return false;
} }
} }

View File

@ -7,7 +7,7 @@ import { AccountInfo } from '../states/accounts.state';
import { StreamTypeEnum, StreamElement } from '../states/streams.state'; import { StreamTypeEnum, StreamElement } from '../states/streams.state';
@Injectable() @Injectable()
export class MastodonService { export class MastodonService {
private apiRoutes = new ApiRoutes(); private apiRoutes = new ApiRoutes();
constructor(private readonly httpClient: HttpClient) { } constructor(private readonly httpClient: HttpClient) { }
@ -319,6 +319,18 @@ export class MastodonService {
let route = `https://${account.instance}${this.apiRoutes.getPoll}`.replace('{0}', pollId); let route = `https://${account.instance}${this.apiRoutes.getPoll}`.replace('{0}', pollId);
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` }); const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });
return this.httpClient.get<Poll>(route, { headers: headers }).toPromise(); return this.httpClient.get<Poll>(route, { headers: headers }).toPromise();
}
mute(account: AccountInfo, accounId: number): Promise<Relationship> {
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<Relationship>(route, null, { headers: headers }).toPromise();
}
block(account: AccountInfo, accounId: number): Promise<Relationship> {
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<Relationship>(route, null, { headers: headers }).toPromise();
} }
} }