32 lines
952 B
Ruby
Executable File
32 lines
952 B
Ruby
Executable File
class Conversations::TypingStatusManager
|
|
include Events::Types
|
|
|
|
attr_reader :conversation, :user, :params
|
|
|
|
def initialize(conversation, user, params)
|
|
@conversation = conversation
|
|
@user = user
|
|
@params = params
|
|
end
|
|
|
|
def trigger_typing_event(event, is_private)
|
|
user = @user.presence || @resource
|
|
Rails.configuration.dispatcher.dispatch(event, Time.zone.now, conversation: @conversation, user: user, is_private: is_private)
|
|
end
|
|
|
|
def toggle_typing_status
|
|
case params[:typing_status]
|
|
when 'on'
|
|
trigger_typing_event(CONVERSATION_TYPING_ON, params[:is_private])
|
|
when 'off'
|
|
trigger_typing_event(CONVERSATION_TYPING_OFF, params[:is_private])
|
|
end
|
|
channel = conversation.inbox.channel
|
|
return unless channel.respond_to?(:toggle_typing_status)
|
|
|
|
channel.toggle_typing_status(params[:typing_status], conversation: conversation)
|
|
|
|
# Return the head :ok response from the controller
|
|
end
|
|
end
|