summaryrefslogtreecommitdiff
path: root/app/services/groups/participants_service.rb
blob: 1de2b3c5a2eabeca06a2d77a3ec18aa868953b9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

module Groups
  class ParticipantsService < Groups::BaseService
    include Users::ParticipableService

    def execute(noteable)
      @noteable = noteable

      participants =
        noteable_owner +
        participants_in_noteable +
        all_members +
        groups +
        group_members

      render_participants_as_hash(participants.uniq)
    end

    def all_members
      count = group_members.count
      [{ username: "all", name: "All Group Members", count: count }]
    end

    def group_members
      return [] unless group

      @group_members ||= sorted(group.direct_and_indirect_users)
    end
  end
end