Fix double polls (#18)
This commit is contained in:
parent
5e35a23574
commit
236dc028aa
|
@ -38,6 +38,7 @@ class WakuVoting {
|
||||||
|
|
||||||
private timedPollInitMessages: PollInitMsg[] = []
|
private timedPollInitMessages: PollInitMsg[] = []
|
||||||
private timedPollVotesMessages: TimedPollVoteMsg[] = []
|
private timedPollVotesMessages: TimedPollVoteMsg[] = []
|
||||||
|
private asyncUpdating = false
|
||||||
|
|
||||||
private static async createWaku() {
|
private static async createWaku() {
|
||||||
const waku = await Waku.create()
|
const waku = await Waku.create()
|
||||||
|
@ -135,17 +136,23 @@ class WakuVoting {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getDetailedTimedPolls() {
|
public async getDetailedTimedPolls() {
|
||||||
const { polls, updatedPolls } = await this.getTimedPolls()
|
let updated = false
|
||||||
const { votes, updatedVotes } = await this.getTimedPollsVotes()
|
if (!this.asyncUpdating) {
|
||||||
|
this.asyncUpdating = true
|
||||||
|
const { polls, updatedPolls } = await this.getTimedPolls()
|
||||||
|
const { votes, updatedVotes } = await this.getTimedPollsVotes()
|
||||||
|
updated = updatedPolls || updatedVotes
|
||||||
|
this.asyncUpdating = false
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
DetailedTimedPolls: polls.map(
|
DetailedTimedPolls: this.timedPollInitMessages.map(
|
||||||
(poll) =>
|
(poll) =>
|
||||||
new DetailedTimedPoll(
|
new DetailedTimedPoll(
|
||||||
poll,
|
poll,
|
||||||
votes.filter((vote) => vote.id === poll.id)
|
this.timedPollVotesMessages.filter((vote) => vote.id === poll.id)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
updated: updatedPolls || updatedVotes,
|
updated,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue