Welcome to mirror list, hosted at ThFree Co, Russian Federation.

find_user_service.rb « chat_names « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a7dc6a47a6b4312c2a61d5fc73c8980203c46758 (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
32
33
34
35
36
# frozen_string_literal: true

module ChatNames
  class FindUserService
    def initialize(team_id, user_id)
      @team_id = team_id
      @user_id = user_id
    end

    def execute
      chat_name = find_chat_name
      return unless chat_name

      record_chat_activity(chat_name)
      chat_name
    end

    private

    attr_reader :team_id, :user_id

    # rubocop: disable CodeReuse/ActiveRecord
    def find_chat_name
      ChatName.find_by(
        team_id: team_id,
        chat_id: user_id
      )
    end
    # rubocop: enable CodeReuse/ActiveRecord

    def record_chat_activity(chat_name)
      chat_name.update_last_used_at
      Users::ActivityService.new(author: chat_name.user).execute
    end
  end
end