diff --git a/app/controllers/api/v1/accounts/conversations_controller.rb b/app/controllers/api/v1/accounts/conversations_controller.rb index db9f65b41..601f63604 100644 --- a/app/controllers/api/v1/accounts/conversations_controller.rb +++ b/app/controllers/api/v1/accounts/conversations_controller.rb @@ -64,9 +64,9 @@ class Api::V1::Accounts::ConversationsController < Api::V1::Accounts::BaseContro def toggle_typing_status case params[:typing_status] when 'on' - trigger_typing_event(CONVERSATION_TYPING_ON) + trigger_typing_event(CONVERSATION_TYPING_ON, params[:is_private]) when 'off' - trigger_typing_event(CONVERSATION_TYPING_OFF) + trigger_typing_event(CONVERSATION_TYPING_OFF, params[:is_private]) end head :ok end @@ -90,9 +90,9 @@ class Api::V1::Accounts::ConversationsController < Api::V1::Accounts::BaseContro @conversation.snoozed_until = parse_date_time(params[:snoozed_until].to_s) if params[:snoozed_until] end - def trigger_typing_event(event) + def trigger_typing_event(event, is_private) user = current_user.presence || @resource - Rails.configuration.dispatcher.dispatch(event, Time.zone.now, conversation: @conversation, user: user) + Rails.configuration.dispatcher.dispatch(event, Time.zone.now, conversation: @conversation, user: user, is_private: is_private) end def conversation diff --git a/app/javascript/dashboard/api/inbox/conversation.js b/app/javascript/dashboard/api/inbox/conversation.js index e407aecb0..0c90f3fd4 100644 --- a/app/javascript/dashboard/api/inbox/conversation.js +++ b/app/javascript/dashboard/api/inbox/conversation.js @@ -51,9 +51,10 @@ class ConversationApi extends ApiClient { return axios.post(`${this.url}/${id}/update_last_seen`); } - toggleTyping({ conversationId, status }) { + toggleTyping({ conversationId, status, isPrivate }) { return axios.post(`${this.url}/${conversationId}/toggle_typing_status`, { typing_status: status, + is_private: isPrivate }); } diff --git a/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue b/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue index 661515adf..a15577b9b 100644 --- a/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue +++ b/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue @@ -415,9 +415,11 @@ export default { }, toggleTyping(status) { const conversationId = this.currentChat.id; + const isPrivate = this.isPrivate; this.$store.dispatch('conversationTypingStatus/toggleTyping', { status, conversationId, + isPrivate, }); }, onFileUpload(file) { diff --git a/app/javascript/dashboard/store/modules/conversationTypingStatus.js b/app/javascript/dashboard/store/modules/conversationTypingStatus.js index 27badb668..93690da4e 100644 --- a/app/javascript/dashboard/store/modules/conversationTypingStatus.js +++ b/app/javascript/dashboard/store/modules/conversationTypingStatus.js @@ -12,9 +12,9 @@ export const getters = { }; export const actions = { - toggleTyping: async (_, { status, conversationId }) => { + toggleTyping: async (_, { status, conversationId, isPrivate }) => { try { - await ConversationAPI.toggleTyping({ status, conversationId }); + await ConversationAPI.toggleTyping({ status, conversationId, isPrivate }); } catch (error) { // Handle error } diff --git a/app/javascript/widget/helpers/actionCable.js b/app/javascript/widget/helpers/actionCable.js index 1bdbba850..a8c3f5d40 100644 --- a/app/javascript/widget/helpers/actionCable.js +++ b/app/javascript/widget/helpers/actionCable.js @@ -55,7 +55,10 @@ class ActionCableConnector extends BaseActionCableConnector { ActionCableConnector.refreshConnector(pubsubToken); }; - onTypingOn = () => { + onTypingOn = data => { + if (data.is_private) { + return + } this.clearTimer(); this.app.$store.dispatch('conversation/toggleAgentTyping', { status: 'on', diff --git a/app/listeners/action_cable_listener.rb b/app/listeners/action_cable_listener.rb index a2388774f..8970f0487 100644 --- a/app/listeners/action_cable_listener.rb +++ b/app/listeners/action_cable_listener.rb @@ -50,7 +50,8 @@ class ActionCableListener < BaseListener tokens, CONVERSATION_TYPING_ON, conversation: conversation.push_event_data, - user: user.push_event_data + user: user.push_event_data, + is_private: event.data[:is_private] || false ) end @@ -65,7 +66,8 @@ class ActionCableListener < BaseListener tokens, CONVERSATION_TYPING_OFF, conversation: conversation.push_event_data, - user: user.push_event_data + user: user.push_event_data, + is_private: event.data[:is_private] || false ) end diff --git a/spec/controllers/api/v1/accounts/conversations_controller_spec.rb b/spec/controllers/api/v1/accounts/conversations_controller_spec.rb index dafec9ea7..2663d0a23 100644 --- a/spec/controllers/api/v1/accounts/conversations_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/conversations_controller_spec.rb @@ -405,12 +405,24 @@ RSpec.describe 'Conversations API', type: :request do allow(Rails.configuration.dispatcher).to receive(:dispatch) post "/api/v1/accounts/#{account.id}/conversations/#{conversation.display_id}/toggle_typing_status", headers: agent.create_new_auth_token, - params: { typing_status: 'on' }, + params: { typing_status: 'on', is_private: false }, as: :json expect(response).to have_http_status(:success) expect(Rails.configuration.dispatcher).to have_received(:dispatch) - .with(Conversation::CONVERSATION_TYPING_ON, kind_of(Time), { conversation: conversation, user: agent }) + .with(Conversation::CONVERSATION_TYPING_ON, kind_of(Time), { conversation: conversation, user: agent, is_private: false }) + end + + it 'toggles the conversation status for private notes' do + allow(Rails.configuration.dispatcher).to receive(:dispatch) + post "/api/v1/accounts/#{account.id}/conversations/#{conversation.display_id}/toggle_typing_status", + headers: agent.create_new_auth_token, + params: { typing_status: 'on', is_private: true }, + as: :json + + expect(response).to have_http_status(:success) + expect(Rails.configuration.dispatcher).to have_received(:dispatch) + .with(Conversation::CONVERSATION_TYPING_ON, kind_of(Time), { conversation: conversation, user: agent, is_private: true }) end end end diff --git a/spec/listeners/action_cable_listener_spec.rb b/spec/listeners/action_cable_listener_spec.rb index 8e7aed2a1..ea7327e5b 100644 --- a/spec/listeners/action_cable_listener_spec.rb +++ b/spec/listeners/action_cable_listener_spec.rb @@ -34,7 +34,7 @@ describe ActionCableListener do describe '#typing_on' do let(:event_name) { :'conversation.typing_on' } - let!(:event) { Events::Base.new(event_name, Time.zone.now, conversation: conversation, user: agent) } + let!(:event) { Events::Base.new(event_name, Time.zone.now, conversation: conversation, user: agent, is_private: false) } it 'sends message to account admins, inbox agents and the contact' do # HACK: to reload conversation inbox members @@ -43,7 +43,8 @@ describe ActionCableListener do [admin.pubsub_token, conversation.contact.pubsub_token], 'conversation.typing_on', conversation: conversation.push_event_data, user: agent.push_event_data, - account_id: account.id + account_id: account.id, + is_private: false ) listener.conversation_typing_on(event) end @@ -51,7 +52,7 @@ describe ActionCableListener do describe '#typing_off' do let(:event_name) { :'conversation.typing_off' } - let!(:event) { Events::Base.new(event_name, Time.zone.now, conversation: conversation, user: agent) } + let!(:event) { Events::Base.new(event_name, Time.zone.now, conversation: conversation, user: agent, is_private: false) } it 'sends message to account admins, inbox agents and the contact' do # HACK: to reload conversation inbox members @@ -60,7 +61,8 @@ describe ActionCableListener do [admin.pubsub_token, conversation.contact.pubsub_token], 'conversation.typing_off', conversation: conversation.push_event_data, user: agent.push_event_data, - account_id: account.id + account_id: account.id, + is_private: false ) listener.conversation_typing_off(event) end