Class: Api::V1::ChatsController
- Inherits:
-
ApiController
- Object
- ApiController
- Api::V1::ChatsController
- Defined in:
- lib/templates/chat/chats_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
17 18 19 20 21 |
# File 'lib/templates/chat/chats_controller.rb', line 17 def create chat = Chat.new(name: chat_name) chat.users << params[:users].each { |user| User.find(user) } chat.save! end |
#index ⇒ Object
4 5 6 |
# File 'lib/templates/chat/chats_controller.rb', line 4 def index @chats = Chat.joins(:participants).where('participants.user' => current_user) end |
#show ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/templates/chat/chats_controller.rb', line 8 def show chat = Chat.find(params[:id]) if !chat || chat..empty? return render json: { messages: {} }, status: :ok end chat.mark_user_seen(current_user) (chat, params[:page]) end |
#visit ⇒ Object
23 24 25 26 27 |
# File 'lib/templates/chat/chats_controller.rb', line 23 def visit chat = Chat.find(params[:chat_id]) participant = Participant.find_by(user: current_user, chat: chat) participant.touch(:last_connection) end |