From 03bcc95d65a777ff12f34d0ca7d17402ec5885a6 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Thu, 11 Mar 2021 23:09:12 -0500 Subject: [PATCH 1/5] fix polls count --- .../components/stream/status/poll/poll.component.html | 2 +- .../components/stream/status/poll/poll.component.ts | 11 ++++++++--- src/app/services/models/mastodon.interfaces.ts | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/app/components/stream/status/poll/poll.component.html b/src/app/components/stream/status/poll/poll.component.html index 2b91918e..6801c025 100644 --- a/src/app/components/stream/status/poll/poll.component.html +++ b/src/app/components/stream/status/poll/poll.component.html @@ -25,7 +25,7 @@ refresh -
·{{poll.votes_count}} votes· {{ poll.expires_at | timeLeft | async }}
+
·{{poll.votes_count}} votes·{{poll.voters_count}} people· {{ poll.expires_at | timeLeft | async }}
Error occured when retrieving the poll diff --git a/src/app/components/stream/status/poll/poll.component.ts b/src/app/components/stream/status/poll/poll.component.ts index 1009d666..ef227e2d 100644 --- a/src/app/components/stream/status/poll/poll.component.ts +++ b/src/app/components/stream/status/poll/poll.component.ts @@ -48,7 +48,7 @@ export class PollComponent implements OnInit { const maxVotes = Math.max(...this.poll.options.map(x => x.votes_count)); let i = 0; for (let opt of this.poll.options) { - let optWrapper = new PollOptionWrapper(i, opt, this.poll.votes_count, opt.votes_count === maxVotes); + let optWrapper = new PollOptionWrapper(i, opt, this.poll.votes_count, this.poll.voters_count, opt.votes_count === maxVotes); this.options.push(optWrapper); i++; } @@ -183,14 +183,19 @@ export class PollComponent implements OnInit { } class PollOptionWrapper implements PollOption { - constructor(index: number, option: PollOption, totalVotes: number, isMax: boolean) { + constructor(index: number, option: PollOption, totalVotes: number, totalVoters: number, isMax: boolean) { + let votesDivider = totalVotes; + if(totalVoters && totalVoters > 0){ + votesDivider = totalVoters; + } + this.id = index; this.title = option.title; this.votes_count = option.votes_count; if (totalVotes === 0) { this.percentage = '0'; } else { - this.percentage = ((this.votes_count / totalVotes) * 100).toFixed(0); + this.percentage = ((this.votes_count / votesDivider) * 100).toFixed(0); } this.isMax = isMax; } diff --git a/src/app/services/models/mastodon.interfaces.ts b/src/app/services/models/mastodon.interfaces.ts index c1668a7a..8debd55a 100644 --- a/src/app/services/models/mastodon.interfaces.ts +++ b/src/app/services/models/mastodon.interfaces.ts @@ -223,6 +223,7 @@ export interface Poll { expired: boolean; multiple: boolean; votes_count: number; + voters_count: number; options: PollOption[]; voted: boolean; } From 21ad2cffb6c7a5d5a48189d7eb5e3ae731ed0f69 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Fri, 12 Mar 2021 18:44:03 -0500 Subject: [PATCH 2/5] fix app reload on double-clic on fav/boost/etc --- .../stream/status/action-bar/action-bar.component.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 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 16a36390..259afcba 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 @@ -185,7 +185,7 @@ export class ActionBarComponent implements OnInit, OnDestroy { } boost(): boolean { - if (this.boostIsLoading) return; + if (this.boostIsLoading) return false; this.boostIsLoading = true; const account = this.toolsService.getSelectedAccounts()[0]; @@ -223,9 +223,9 @@ export class ActionBarComponent implements OnInit, OnDestroy { return false; } - + favorite(): boolean { - if (this.favoriteIsLoading) return; + if (this.favoriteIsLoading) return false; this.favoriteIsLoading = true; const account = this.toolsService.getSelectedAccounts()[0]; @@ -260,7 +260,7 @@ export class ActionBarComponent implements OnInit, OnDestroy { } bookmark(): boolean { - if (this.bookmarkingIsLoading) return; + if (this.bookmarkingIsLoading) return false; this.bookmarkingIsLoading = true; From aa705d7c5bbf503b6f1c1c8e6014a3f399418495 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Fri, 12 Mar 2021 18:59:15 -0500 Subject: [PATCH 3/5] chaining calls --- .../status/action-bar/action-bar.component.ts | 58 +++++++++++-------- 1 file changed, 34 insertions(+), 24 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 259afcba..a22c5bb9 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 @@ -138,7 +138,7 @@ export class ActionBarComponent implements OnInit, OnDestroy { private checkStatus(accounts: AccountInfo[]): void { const status = this.statusWrapper.status; const provider = this.statusWrapper.provider; - this.selectedAccounts = accounts.filter(x => x.isSelected); + this.selectedAccounts = accounts.filter(x => x.isSelected); if (!this.statusWrapper.isRemote) { this.isProviderSelected = this.selectedAccounts.filter(x => x.id === provider.id).length > 0; @@ -184,13 +184,18 @@ export class ActionBarComponent implements OnInit, OnDestroy { return false; } + private boostPromise: Promise; boost(): boolean { - if (this.boostIsLoading) return false; + if (!this.boostPromise) { + this.boostPromise = Promise.resolve(true); + } - this.boostIsLoading = true; - const account = this.toolsService.getSelectedAccounts()[0]; - const usableStatus = this.toolsService.getStatusUsableByAccount(account, this.statusWrapper); - usableStatus + const account = this.toolsService.getSelectedAccounts()[0]; + this.boostPromise = this.boostPromise + .then(() => { + this.boostIsLoading = true; + return this.toolsService.getStatusUsableByAccount(account, this.statusWrapper); + }) .then((status: Status) => { if (this.isBoosted && status.reblogged) { return this.mastodonService.unreblog(account, status); @@ -219,18 +224,24 @@ export class ActionBarComponent implements OnInit, OnDestroy { .then(() => { this.statusStateService.statusReblogStatusChanged(this.displayedStatus.url, account.id, this.bootedStatePerAccountId[account.id]); this.boostIsLoading = false; + this.boostPromise = null; }); return false; } - - favorite(): boolean { - if (this.favoriteIsLoading) return false; - this.favoriteIsLoading = true; + private favoritePromise: Promise; + favorite(): boolean { + if (!this.favoritePromise) { + this.favoritePromise = Promise.resolve(true); + } + const account = this.toolsService.getSelectedAccounts()[0]; - const usableStatus = this.toolsService.getStatusUsableByAccount(account, this.statusWrapper); - usableStatus + this.favoritePromise = this.favoritePromise + .then(() => { + this.favoriteIsLoading = true; + return this.toolsService.getStatusUsableByAccount(account, this.statusWrapper); + }) .then((status: Status) => { if (this.isFavorited && status.favourited) { return this.mastodonService.unfavorite(account, status); @@ -254,19 +265,24 @@ export class ActionBarComponent implements OnInit, OnDestroy { .then(() => { this.statusStateService.statusFavoriteStatusChanged(this.displayedStatus.url, account.id, this.favoriteStatePerAccountId[account.id]); this.favoriteIsLoading = false; + this.favoritePromise = null; }); return false; } + private bookmarkPromise: Promise; bookmark(): boolean { - if (this.bookmarkingIsLoading) return false; - - this.bookmarkingIsLoading = true; + if (!this.bookmarkPromise) { + this.bookmarkPromise = Promise.resolve(true); + } const account = this.toolsService.getSelectedAccounts()[0]; - const usableStatus = this.toolsService.getStatusUsableByAccount(account, this.statusWrapper); - usableStatus + this.bookmarkPromise = this.bookmarkPromise + .then(() => { + this.bookmarkingIsLoading = true; + return this.toolsService.getStatusUsableByAccount(account, this.statusWrapper); + }) .then((status: Status) => { if (this.isBookmarked && status.bookmarked) { return this.mastodonService.unbookmark(account, status); @@ -290,15 +306,9 @@ export class ActionBarComponent implements OnInit, OnDestroy { .then(() => { this.statusStateService.statusBookmarkStatusChanged(this.displayedStatus.url, account.id, this.bookmarkStatePerAccountId[account.id]); this.bookmarkingIsLoading = false; + this.bookmarkPromise = null; }); - - - // setTimeout(() => { - // this.isBookmarked = !this.isBookmarked; - // this.bookmarkingIsLoading = false; - // }, 2000); - return false; } From 93847df4d8962b56624ae11998fa45b65863e35c Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Fri, 12 Mar 2021 19:05:10 -0500 Subject: [PATCH 4/5] fix undoing action not updating global state --- .../stream/status/action-bar/action-bar.component.ts | 6 +++--- 1 file changed, 3 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 a22c5bb9..274c302a 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 @@ -102,13 +102,13 @@ export class ActionBarComponent implements OnInit, OnDestroy { this.statusStateSub = this.statusStateService.stateNotification.subscribe((state: StatusState) => { if (state && state.statusId === this.displayedStatus.url) { - if (state.isFavorited) { + if (state.isFavorited !== null) { this.favoriteStatePerAccountId[state.accountId] = state.isFavorited; } - if (state.isRebloged) { + if (state.isRebloged !== null) { this.bootedStatePerAccountId[state.accountId] = state.isRebloged; } - if (state.isBookmarked) { + if (state.isBookmarked !== null) { this.bookmarkStatePerAccountId[state.accountId] = state.isBookmarked; } From 9bba8a335221fc87833de63bc0c1e44fe95e5fef Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Fri, 12 Mar 2021 19:25:27 -0500 Subject: [PATCH 5/5] road to 1.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1e68012f..51bf83de 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sengi", - "version": "1.1.0", + "version": "1.1.1", "license": "AGPL-3.0-or-later", "main": "main-electron.js", "description": "A multi-account desktop client for Mastodon and Pleroma",