27 lines
763 B
Ruby
27 lines
763 B
Ruby
|
|
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
|
||
|
|
# Return the head :ok response from the controller
|
||
|
|
end
|
||
|
|
end
|