(url, forceShowPoll)
| 2325 | } |
| 2326 | |
| 2327 | loadPoll (url, forceShowPoll) { |
| 2328 | if (url == null) { url = `/db/poll/${this.userPollsRecord.id}/next` } |
| 2329 | let tempLoadingPoll = new Poll().setURL(url) |
| 2330 | const onPollSync = () => { |
| 2331 | if (this.destroyed) { return } |
| 2332 | tempLoadingPoll.url = () => '/db/poll/' + tempLoadingPoll.id |
| 2333 | this.poll = tempLoadingPoll |
| 2334 | const delay = forceShowPoll ? 1000 : 5000 // Wait a little bit before showing the poll |
| 2335 | setTimeout(() => this.activatePoll?.(forceShowPoll), delay) |
| 2336 | } |
| 2337 | const onPollError = (poll, response, request) => { |
| 2338 | if (response.status === 404) { |
| 2339 | console.log('There are no more polls left.') |
| 2340 | } else { |
| 2341 | console.error("Couldn't load poll:", response.status, response.statusText) |
| 2342 | } |
| 2343 | if (this.poll) { |
| 2344 | delete this.poll |
| 2345 | } |
| 2346 | } |
| 2347 | this.listenToOnce(tempLoadingPoll, 'sync', onPollSync) |
| 2348 | this.listenToOnce(tempLoadingPoll, 'error', onPollError) |
| 2349 | tempLoadingPoll = this.supermodel.loadModel(tempLoadingPoll, null, 0).model |
| 2350 | if (tempLoadingPoll.loaded) { |
| 2351 | onPollSync() |
| 2352 | } |
| 2353 | } |
| 2354 | |
| 2355 | activatePoll (forceShowPoll) { |
| 2356 | if (this.shouldShow('promotion')) { return } |
no test coverage detected