From a4c32b3464592cdc30bce0ef72a285bdc185b331 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Wed, 3 Oct 2018 20:58:39 -0400 Subject: [PATCH] better displaying of favs and boosts states --- .../status/action-bar/action-bar.component.ts | 51 +++++++++++++++---- .../services/models/mastodon.interfaces.ts | 7 +-- 2 files changed, 46 insertions(+), 12 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 b6403040..f0fe0602 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 @@ -26,6 +26,9 @@ export class ActionBarComponent implements OnInit, OnDestroy { private isProviderSelected: boolean; private selectedAccounts: AccountInfo[]; + private favoriteStatePerAccountId: { [id: string]: boolean; } = {}; + private bootedStatePerAccountId: { [id: string]: boolean; } = {}; + private accounts$: Observable; private accountSub: Subscription; @@ -40,8 +43,12 @@ export class ActionBarComponent implements OnInit, OnDestroy { // const selectedAccounts = this.getSelectedAccounts(); // this.checkStatus(selectedAccounts); + const status = this.statusWrapper.status; + const account = this.statusWrapper.provider; + this.favoriteStatePerAccountId[account.id] = status.favourited; + this.bootedStatePerAccountId[account.id] = status.reblogged; + this.accountSub = this.accounts$.subscribe((accounts: AccountInfo[]) => { - console.warn('selectedAccounts'); this.checkStatus(accounts); }); } @@ -67,6 +74,9 @@ export class ActionBarComponent implements OnInit, OnDestroy { } else { this.isLocked = false; } + + this.checkIfFavorited(); + this.checkIfBoosted(); } reply(): boolean { @@ -93,20 +103,22 @@ export class ActionBarComponent implements OnInit, OnDestroy { pipeline .then((status: Status) => { - if(this.isBoosted) { + if (this.isBoosted) { return this.mastodonService.unreblog(account, status); } else { return this.mastodonService.reblog(account, status); } }) - .then(() => { - this.isBoosted = !this.isBoosted; + .then((boostedStatus: Status) => { + this.bootedStatePerAccountId[account.id] = boostedStatus.reblogged; + this.checkIfBoosted(); + // this.isBoosted = !this.isBoosted; }) .catch(err => { console.error(err); }); }); - + return false; } @@ -129,22 +141,43 @@ export class ActionBarComponent implements OnInit, OnDestroy { pipeline .then((status: Status) => { - if(this.isFavorited) { + if (this.isFavorited) { return this.mastodonService.unfavorite(account, status); } else { return this.mastodonService.favorite(account, status); } }) - .then(() => { - this.isFavorited = !this.isFavorited; + .then((favoritedStatus: Status) => { + this.favoriteStatePerAccountId[account.id] = favoritedStatus.favourited; + this.checkIfFavorited(); + // this.isFavorited = !this.isFavorited; }) .catch(err => { console.error(err); }); - }); + }); return false; } + private checkIfBoosted() { + const selectedAccount = this.selectedAccounts[0]; + if (selectedAccount) { + this.isBoosted = this.bootedStatePerAccountId[selectedAccount.id]; + } else { + this.isBoosted = false; + } + } + + private checkIfFavorited() { + const selectedAccount = this.selectedAccounts[0]; + + if (selectedAccount) { + this.isFavorited = this.favoriteStatePerAccountId[selectedAccount.id]; + } else { + this.isFavorited = false; + } + } + more(): boolean { console.warn('more'); return false; diff --git a/src/app/services/models/mastodon.interfaces.ts b/src/app/services/models/mastodon.interfaces.ts index 2d4aeb0a..e2b50740 100644 --- a/src/app/services/models/mastodon.interfaces.ts +++ b/src/app/services/models/mastodon.interfaces.ts @@ -116,15 +116,16 @@ export interface Status { created_at: string; reblogs_count: string; favourites_count: string; - reblogged: string; - favourited: string; - sensitive: string; + reblogged: boolean; + favourited: boolean; + sensitive: boolean; spoiler_text: string; visibility: string; media_attachments: Attachment[]; mentions: string; tags: string; application: Application; + emojis: any[]; } export interface Tag { name: string;