2016-11-13 14:35:47 -05:00
|
|
|
module ChatNames
|
|
|
|
class FindUserService
|
2016-11-16 08:56:30 -05:00
|
|
|
def initialize(service, params)
|
|
|
|
@service = service
|
2016-11-13 14:35:47 -05:00
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2016-11-16 08:56:30 -05:00
|
|
|
chat_name = find_chat_name
|
|
|
|
return unless chat_name
|
|
|
|
|
2016-11-17 10:29:16 -05:00
|
|
|
chat_name.touch(:last_used_at)
|
2016-11-16 08:56:30 -05:00
|
|
|
chat_name.user
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def find_chat_name
|
|
|
|
ChatName.find_by(
|
|
|
|
service: @service,
|
2016-11-13 14:35:47 -05:00
|
|
|
team_id: @params[:team_id],
|
|
|
|
chat_id: @params[:user_id]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|