Class: AwardEmoji
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- AwardEmoji
- Includes:
- GhostUser, Importable, Participable
- Defined in:
- app/models/award_emoji.rb
Constant Summary collapse
- DOWNVOTE_NAME =
"thumbsdown"
- UPVOTE_NAME =
"thumbsup"
Constants inherited from ApplicationRecord
Instance Attribute Summary
Attributes included from Importable
Class Method Summary collapse
-
.award_counts_for_user(user, limit = 100) ⇒ Object
Returns the top 100 emoji awarded by the given user.
- .votes_for_collection(ids, type) ⇒ Object
Instance Method Summary collapse
Methods included from GhostUser
Methods included from Participable
#participant?, #participants, #visible_participants
Methods inherited from ApplicationRecord
cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
Methods included from SensitiveSerializableHash
Class Method Details
.award_counts_for_user(user, limit = 100) ⇒ Object
Returns the top 100 emoji awarded by the given user.
The returned value is a Hash mapping emoji names to the number of times they were awarded:
{ 'thumbsup' => 2, 'thumbsdown' => 1 }
user - The User to get the awards for. limt - The maximum number of emoji to return.
48 49 50 51 52 53 54 |
# File 'app/models/award_emoji.rb', line 48 def award_counts_for_user(user, limit = 100) limit(limit) .where(user: user) .group(:name) .order('count_all DESC, name ASC') .count end |
.votes_for_collection(ids, type) ⇒ Object
33 34 35 36 37 |
# File 'app/models/award_emoji.rb', line 33 def votes_for_collection(ids, type) select('name', 'awardable_id', 'COUNT(*) as count') .where('name IN (?) AND awardable_type = ? AND awardable_id IN (?)', [DOWNVOTE_NAME, UPVOTE_NAME], type, ids) .group('name', 'awardable_id') end |
Instance Method Details
#downvote? ⇒ Boolean
57 58 59 |
# File 'app/models/award_emoji.rb', line 57 def downvote? self.name == DOWNVOTE_NAME end |
#expire_cache ⇒ Object
71 72 73 74 75 |
# File 'app/models/award_emoji.rb', line 71 def expire_cache awardable.try(:bump_updated_at) awardable.try(:expire_etag_cache) awardable.try(:update_upvotes_count) if upvote? end |
#upvote? ⇒ Boolean
61 62 63 |
# File 'app/models/award_emoji.rb', line 61 def upvote? self.name == UPVOTE_NAME end |
#url ⇒ Object
65 66 67 68 69 |
# File 'app/models/award_emoji.rb', line 65 def url return if TanukiEmoji.find_by_alpha_code(name) CustomEmoji.for_resource(resource_parent).by_name(name).select(:url).first&.url end |