fix: Disable typing indicator for user when agent is typing a private note (#3303)

This commit is contained in:
Hugo Sarti 2021-11-01 05:20:07 -03:00 committed by GitHub
parent 000c7603d6
commit 68fa694268
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 38 additions and 16 deletions

View file

@ -64,9 +64,9 @@ class Api::V1::Accounts::ConversationsController < Api::V1::Accounts::BaseContro
def toggle_typing_status def toggle_typing_status
case params[:typing_status] case params[:typing_status]
when 'on' when 'on'
trigger_typing_event(CONVERSATION_TYPING_ON) trigger_typing_event(CONVERSATION_TYPING_ON, params[:is_private])
when 'off' when 'off'
trigger_typing_event(CONVERSATION_TYPING_OFF) trigger_typing_event(CONVERSATION_TYPING_OFF, params[:is_private])
end end
head :ok head :ok
end 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] @conversation.snoozed_until = parse_date_time(params[:snoozed_until].to_s) if params[:snoozed_until]
end end
def trigger_typing_event(event) def trigger_typing_event(event, is_private)
user = current_user.presence || @resource 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 end
def conversation def conversation

View file

@ -51,9 +51,10 @@ class ConversationApi extends ApiClient {
return axios.post(`${this.url}/${id}/update_last_seen`); 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`, { return axios.post(`${this.url}/${conversationId}/toggle_typing_status`, {
typing_status: status, typing_status: status,
is_private: isPrivate
}); });
} }

View file

@ -415,9 +415,11 @@ export default {
}, },
toggleTyping(status) { toggleTyping(status) {
const conversationId = this.currentChat.id; const conversationId = this.currentChat.id;
const isPrivate = this.isPrivate;
this.$store.dispatch('conversationTypingStatus/toggleTyping', { this.$store.dispatch('conversationTypingStatus/toggleTyping', {
status, status,
conversationId, conversationId,
isPrivate,
}); });
}, },
onFileUpload(file) { onFileUpload(file) {

View file

@ -12,9 +12,9 @@ export const getters = {
}; };
export const actions = { export const actions = {
toggleTyping: async (_, { status, conversationId }) => { toggleTyping: async (_, { status, conversationId, isPrivate }) => {
try { try {
await ConversationAPI.toggleTyping({ status, conversationId }); await ConversationAPI.toggleTyping({ status, conversationId, isPrivate });
} catch (error) { } catch (error) {
// Handle error // Handle error
} }

View file

@ -55,7 +55,10 @@ class ActionCableConnector extends BaseActionCableConnector {
ActionCableConnector.refreshConnector(pubsubToken); ActionCableConnector.refreshConnector(pubsubToken);
}; };
onTypingOn = () => { onTypingOn = data => {
if (data.is_private) {
return
}
this.clearTimer(); this.clearTimer();
this.app.$store.dispatch('conversation/toggleAgentTyping', { this.app.$store.dispatch('conversation/toggleAgentTyping', {
status: 'on', status: 'on',

View file

@ -50,7 +50,8 @@ class ActionCableListener < BaseListener
tokens, tokens,
CONVERSATION_TYPING_ON, CONVERSATION_TYPING_ON,
conversation: conversation.push_event_data, conversation: conversation.push_event_data,
user: user.push_event_data user: user.push_event_data,
is_private: event.data[:is_private] || false
) )
end end
@ -65,7 +66,8 @@ class ActionCableListener < BaseListener
tokens, tokens,
CONVERSATION_TYPING_OFF, CONVERSATION_TYPING_OFF,
conversation: conversation.push_event_data, conversation: conversation.push_event_data,
user: user.push_event_data user: user.push_event_data,
is_private: event.data[:is_private] || false
) )
end end

View file

@ -405,12 +405,24 @@ RSpec.describe 'Conversations API', type: :request do
allow(Rails.configuration.dispatcher).to receive(:dispatch) allow(Rails.configuration.dispatcher).to receive(:dispatch)
post "/api/v1/accounts/#{account.id}/conversations/#{conversation.display_id}/toggle_typing_status", post "/api/v1/accounts/#{account.id}/conversations/#{conversation.display_id}/toggle_typing_status",
headers: agent.create_new_auth_token, headers: agent.create_new_auth_token,
params: { typing_status: 'on' }, params: { typing_status: 'on', is_private: false },
as: :json as: :json
expect(response).to have_http_status(:success) expect(response).to have_http_status(:success)
expect(Rails.configuration.dispatcher).to have_received(:dispatch) 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 end
end end

View file

@ -34,7 +34,7 @@ describe ActionCableListener do
describe '#typing_on' do describe '#typing_on' do
let(:event_name) { :'conversation.typing_on' } 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 it 'sends message to account admins, inbox agents and the contact' do
# HACK: to reload conversation inbox members # HACK: to reload conversation inbox members
@ -43,7 +43,8 @@ describe ActionCableListener do
[admin.pubsub_token, conversation.contact.pubsub_token], [admin.pubsub_token, conversation.contact.pubsub_token],
'conversation.typing_on', conversation: conversation.push_event_data, 'conversation.typing_on', conversation: conversation.push_event_data,
user: agent.push_event_data, user: agent.push_event_data,
account_id: account.id account_id: account.id,
is_private: false
) )
listener.conversation_typing_on(event) listener.conversation_typing_on(event)
end end
@ -51,7 +52,7 @@ describe ActionCableListener do
describe '#typing_off' do describe '#typing_off' do
let(:event_name) { :'conversation.typing_off' } 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 it 'sends message to account admins, inbox agents and the contact' do
# HACK: to reload conversation inbox members # HACK: to reload conversation inbox members
@ -60,7 +61,8 @@ describe ActionCableListener do
[admin.pubsub_token, conversation.contact.pubsub_token], [admin.pubsub_token, conversation.contact.pubsub_token],
'conversation.typing_off', conversation: conversation.push_event_data, 'conversation.typing_off', conversation: conversation.push_event_data,
user: agent.push_event_data, user: agent.push_event_data,
account_id: account.id account_id: account.id,
is_private: false
) )
listener.conversation_typing_off(event) listener.conversation_typing_off(event)
end end