summaryrefslogtreecommitdiff
path: root/app/services/award_emojis/collect_user_emoji_service.rb
blob: 6cab23f3edf487c8fc1900146f68669cf0bae218 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# frozen_string_literal: true

# Class for retrieving information about emoji awarded _by_ a particular user.
module AwardEmojis
  class CollectUserEmojiService
    attr_reader :current_user

    # current_user - The User to generate the data for.
    def initialize(current_user = nil)
      @current_user = current_user
    end

    def execute
      return [] unless current_user

      # We want the resulting data set to be an Array containing the emoji names
      # in descending order, based on how often they were awarded.
      AwardEmoji
        .award_counts_for_user(current_user)
        .map { |name, _| { name: name } }
    end
  end
end