summaryrefslogtreecommitdiff
path: root/app/services/chat_names/find_user_service.rb
blob: 4f5c5567b4271e60237d6242420e0cd9cedb5bf3 (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
module ChatNames
  class FindUserService
    def initialize(service, params)
      @service = service
      @params = params
    end

    def execute
      chat_name = find_chat_name
      return unless chat_name

      chat_name.touch(:last_used_at)
      chat_name.user
    end

    private

    def find_chat_name
      ChatName.find_by(
        service: @service,
        team_id: @params[:team_id],
        chat_id: @params[:user_id]
      )
    end
  end
end