2020-05-04 17:37:56 +00:00
|
|
|
class Api::V1::Widget::ConversationsController < Api::V1::Widget::BaseController
|
|
|
|
include Events::Types
|
|
|
|
|
2020-05-09 16:32:43 +00:00
|
|
|
def index
|
|
|
|
@conversation = conversation
|
|
|
|
end
|
|
|
|
|
2020-07-07 18:34:44 +00:00
|
|
|
def update_last_seen
|
|
|
|
head :ok && return if conversation.nil?
|
|
|
|
|
|
|
|
conversation.user_last_seen_at = DateTime.now.utc
|
|
|
|
conversation.save!
|
|
|
|
head :ok
|
|
|
|
end
|
|
|
|
|
2020-05-04 17:37:56 +00:00
|
|
|
def toggle_typing
|
2020-05-05 18:40:56 +00:00
|
|
|
head :ok && return if conversation.nil?
|
2020-05-04 17:37:56 +00:00
|
|
|
|
|
|
|
if permitted_params[:typing_status] == 'on'
|
|
|
|
trigger_typing_event(CONVERSATION_TYPING_ON)
|
|
|
|
elsif permitted_params[:typing_status] == 'off'
|
|
|
|
trigger_typing_event(CONVERSATION_TYPING_OFF)
|
|
|
|
end
|
|
|
|
|
|
|
|
head :ok
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def trigger_typing_event(event)
|
|
|
|
Rails.configuration.dispatcher.dispatch(event, Time.zone.now, conversation: conversation, user: @contact)
|
|
|
|
end
|
|
|
|
|
|
|
|
def permitted_params
|
|
|
|
params.permit(:id, :typing_status, :website_token)
|
|
|
|
end
|
|
|
|
end
|