reblogs and favorites now working
This commit is contained in:
parent
589cb8330c
commit
afed572916
@ -5,6 +5,7 @@ import { StatusWrapper } from '../../stream.component';
|
||||
import { MastodonService } from '../../../../services/mastodon.service';
|
||||
import { AccountInfo } from '../../../../states/accounts.state';
|
||||
import { Observable, Subscription } from 'rxjs';
|
||||
import { Status, Results } from '../../../../services/models/mastodon.interfaces';
|
||||
// import { map } from "rxjs/operators";
|
||||
|
||||
@Component({
|
||||
@ -49,7 +50,7 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
||||
this.accountSub.unsubscribe();
|
||||
}
|
||||
|
||||
private checkStatus(accounts: AccountInfo[]): void {
|
||||
private checkStatus(accounts: AccountInfo[]): void {
|
||||
const status = this.statusWrapper.status;
|
||||
const provider = this.statusWrapper.provider;
|
||||
this.selectedAccounts = accounts.filter(x => x.isSelected);
|
||||
@ -74,17 +75,73 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
boost(): boolean {
|
||||
this.selectedAccounts.forEach((account: AccountInfo) => {
|
||||
const isProvider = this.statusWrapper.provider.id === account.id;
|
||||
|
||||
let pipeline: Promise<Status> = Promise.resolve(this.statusWrapper.status);
|
||||
|
||||
if (!isProvider) {
|
||||
pipeline = pipeline.then((foreignStatus: Status) => {
|
||||
const statusUrl = foreignStatus.url;
|
||||
return this.mastodonService.search(account, statusUrl)
|
||||
.then((results: Results) => {
|
||||
//TODO check and type errors
|
||||
return results.statuses[0];
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
console.warn('boost');
|
||||
this.isBoosted = !this.isBoosted;
|
||||
pipeline
|
||||
.then((status: Status) => {
|
||||
if(this.isBoosted) {
|
||||
return this.mastodonService.unreblog(account, status);
|
||||
} else {
|
||||
return this.mastodonService.reblog(account, status);
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
this.isBoosted = !this.isBoosted;
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
favorite(): boolean {
|
||||
console.warn('favorite');
|
||||
this.isFavorited = !this.isFavorited;
|
||||
this.selectedAccounts.forEach((account: AccountInfo) => {
|
||||
const isProvider = this.statusWrapper.provider.id === account.id;
|
||||
|
||||
let pipeline: Promise<Status> = Promise.resolve(this.statusWrapper.status);
|
||||
|
||||
if (!isProvider) {
|
||||
pipeline = pipeline.then((foreignStatus: Status) => {
|
||||
const statusUrl = foreignStatus.url;
|
||||
return this.mastodonService.search(account, statusUrl)
|
||||
.then((results: Results) => {
|
||||
//TODO check and type errors
|
||||
return results.statuses[0];
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
pipeline
|
||||
.then((status: Status) => {
|
||||
if(this.isFavorited) {
|
||||
return this.mastodonService.unfavorite(account, status);
|
||||
} else {
|
||||
return this.mastodonService.favorite(account, status);
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
this.isFavorited = !this.isFavorited;
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -5,10 +5,11 @@ import { ApiRoutes } from './models/api.settings';
|
||||
import { Account, Status, Results } from "./models/mastodon.interfaces";
|
||||
import { AccountInfo } from '../states/accounts.state';
|
||||
import { StreamTypeEnum } from '../states/streams.state';
|
||||
import { stat } from 'fs';
|
||||
|
||||
@Injectable()
|
||||
export class MastodonService {
|
||||
|
||||
|
||||
private apiRoutes = new ApiRoutes();
|
||||
|
||||
constructor(private readonly httpClient: HttpClient) { }
|
||||
@ -115,6 +116,30 @@ export class MastodonService {
|
||||
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });
|
||||
return this.httpClient.get<Results>(route, { headers: headers }).toPromise()
|
||||
}
|
||||
|
||||
reblog(account: AccountInfo, status: Status): Promise<Status> {
|
||||
const route = `https://${account.instance}${this.apiRoutes.reblogStatus}`.replace('{0}', status.id);
|
||||
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });
|
||||
return this.httpClient.post<Status>(route, null, { headers: headers }).toPromise()
|
||||
}
|
||||
|
||||
unreblog(account: AccountInfo, status: Status): Promise<Status> {
|
||||
const route = `https://${account.instance}${this.apiRoutes.unreblogStatus}`.replace('{0}', status.id);
|
||||
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });
|
||||
return this.httpClient.post<Status>(route, null, { headers: headers }).toPromise()
|
||||
}
|
||||
|
||||
favorite(account: AccountInfo, status: Status): any {
|
||||
const route = `https://${account.instance}${this.apiRoutes.favouritingStatus}`.replace('{0}', status.id);
|
||||
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });
|
||||
return this.httpClient.post<Status>(route, null, { headers: headers }).toPromise()
|
||||
}
|
||||
|
||||
unfavorite(account: AccountInfo, status: Status): any {
|
||||
const route = `https://${account.instance}${this.apiRoutes.unfavouritingStatus}`.replace('{0}', status.id);
|
||||
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });
|
||||
return this.httpClient.post<Status>(route, null, { headers: headers }).toPromise()
|
||||
}
|
||||
}
|
||||
|
||||
export enum VisibilityEnum {
|
||||
|
Loading…
x
Reference in New Issue
Block a user