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
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

View file

@ -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
});
}

View file

@ -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) {

View file

@ -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
}

View file

@ -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',

View file

@ -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

View file

@ -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

View file

@ -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