0
0
Fork 0

Immediately display poll results to poll author (#10187)

* Immediately display poll results to poll author

* Refactor Poll#loaded_options and add Poll#voted? to improve DRYness
This commit is contained in:
Eugen Rochko 2019-03-07 22:53:47 +01:00 committed by GitHub
parent 75cb93676b
commit 054bbb3da2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 24 deletions

View file

@ -41,17 +41,17 @@ class Poll < ApplicationRecord
after_commit :reset_parent_cache, on: :update
def loaded_options
options.map.with_index { |title, key| Option.new(self, key.to_s, title, cached_tallies[key]) }
end
def unloaded_options
options.map.with_index { |title, key| Option.new(self, key.to_s, title, nil) }
options.map.with_index { |title, key| Option.new(self, key.to_s, title, show_totals_now? ? cached_tallies[key] : nil) }
end
def possibly_stale?
remote? && last_fetched_before_expiration? && time_passed_since_last_fetch?
end
def voted?(account)
account.id == account_id || votes.where(account: account).exists?
end
delegate :local?, to: :account
def remote?
@ -95,4 +95,8 @@ class Poll < ApplicationRecord
def time_passed_since_last_fetch?
last_fetched_at.nil? || last_fetched_at < 1.minute.ago
end
def show_totals_now?
expired? || !hide_totals?
end
end