From 72fc5bd38741988b9b21fb1cdcf86f8520ac0107 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Sun, 31 Mar 2019 19:08:11 -0400 Subject: [PATCH] fix boosting/faving when not up to date --- .../stream/status/action-bar/action-bar.component.ts | 12 ++++++++---- src/app/services/mastodon.service.ts | 4 ++-- 2 files changed, 10 insertions(+), 6 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 96db14bd..db21919f 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 @@ -119,10 +119,12 @@ export class ActionBarComponent implements OnInit, OnDestroy { const usableStatus = this.toolsService.getStatusUsableByAccount(account, this.statusWrapper); usableStatus .then((status: Status) => { - if (this.isBoosted) { + if (this.isBoosted && status.reblogged) { return this.mastodonService.unreblog(account, status); - } else { + } else if(!this.isBoosted && !status.reblogged){ return this.mastodonService.reblog(account, status); + } else { + return Promise.resolve(status); } }) .then((boostedStatus: Status) => { @@ -144,10 +146,12 @@ export class ActionBarComponent implements OnInit, OnDestroy { const usableStatus = this.toolsService.getStatusUsableByAccount(account, this.statusWrapper); usableStatus .then((status: Status) => { - if (this.isFavorited) { + if (this.isFavorited && status.favourited) { return this.mastodonService.unfavorite(account, status); - } else { + } else if(!this.isFavorited && !status.favourited) { return this.mastodonService.favorite(account, status); + } else { + return Promise.resolve(status); } }) .then((favoritedStatus: Status) => { diff --git a/src/app/services/mastodon.service.ts b/src/app/services/mastodon.service.ts index b106831f..68048f6b 100644 --- a/src/app/services/mastodon.service.ts +++ b/src/app/services/mastodon.service.ts @@ -173,13 +173,13 @@ export class MastodonService { return this.httpClient.post(route, null, { headers: headers }).toPromise() } - favorite(account: AccountInfo, status: Status): any { + favorite(account: AccountInfo, status: Status): Promise { 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(route, null, { headers: headers }).toPromise() } - unfavorite(account: AccountInfo, status: Status): any { + unfavorite(account: AccountInfo, status: Status): Promise { 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(route, null, { headers: headers }).toPromise()