Added current url support of clients for agents.

This commit is contained in:
Martin Edenhofer 2016-03-25 08:45:21 +01:00
parent 81acdbb06a
commit 1030eb1840
10 changed files with 108 additions and 11 deletions

View file

@ -381,6 +381,11 @@ class ChatWindow extends App.Controller
return if data.self_written return if data.self_written
@receiveMessage(data.message.content) @receiveMessage(data.message.content)
) )
@bind('chat_session_notice', (data) =>
return if data.session_id isnt @session.session_id
return if data.self_written
@addNoticeMessage(data.message)
)
@bind('chat_session_left', (data) => @bind('chat_session_left', (data) =>
return if data.session_id isnt @session.session_id return if data.session_id isnt @session.session_id
return if data.self_written return if data.self_written
@ -410,6 +415,9 @@ class ChatWindow extends App.Controller
# @addMessage 'Hello. My name is Roger, how can I help you?', 'agent' # @addMessage 'Hello. My name is Roger, how can I help you?', 'agent'
if @session if @session
if @session && @session.preferences && @session.preferences.url
@addNoticeMessage(@session.preferences.url)
if @session.messages if @session.messages
for message in @session.messages for message in @session.messages
if message.created_by_id if message.created_by_id
@ -660,6 +668,15 @@ class ChatWindow extends App.Controller
@scrollToBottom() @scrollToBottom()
addNoticeMessage: (message, args) ->
@maybeAddTimestamp()
@body.append App.view('customer_chat/chat_notice_message')
message: message
args: args
@scrollToBottom()
scrollToBottom: -> scrollToBottom: ->
@scrollHolder.scrollTop(@scrollHolder.prop('scrollHeight')) @scrollHolder.scrollTop(@scrollHolder.prop('scrollHeight'))

View file

@ -0,0 +1 @@
<div class="chat-notice-message"><%= @message %></div>

View file

@ -1,3 +1,4 @@
<hr>
<ul> <ul>
<% if @session: %> <% if @session: %>
<li><%- @T('Created at') %>: <%- @Ttimestamp(@session.created_at) %> <li><%- @T('Created at') %>: <%- @Ttimestamp(@session.created_at) %>

View file

@ -32,6 +32,7 @@ class Sessions::Event::ChatSessionInit < Sessions::Event::ChatBase
name: '', name: '',
state: 'waiting', state: 'waiting',
preferences: { preferences: {
url: @payload['data']['url'],
participants: [@client_id], participants: [@client_id],
remote_ip: @remote_ip, remote_ip: @remote_ip,
geo_ip: geo_ip, geo_ip: geo_ip,

View file

@ -0,0 +1,22 @@
class Sessions::Event::ChatSessionNotice < Sessions::Event::ChatBase
def run
return super if super
return if !check_chat_session_exists
chat_session = current_chat_session
return if !chat_session
return if !@payload['data']['message']
message = {
event: 'chat_session_notice',
data: {
session_id: chat_session.session_id,
message: @payload['data']['message'],
},
}
chat_session.send_to_recipients(message, @client_id)
nil
end
end

View file

@ -12,7 +12,20 @@ class Sessions::Event::ChatStatusCustomer < Sessions::Event::ChatBase
# update recipients of existing sessions # update recipients of existing sessions
chat_session = Chat::Session.find_by(session_id: session_id) chat_session = Chat::Session.find_by(session_id: session_id)
chat_session.add_recipient(@client_id, true) chat_session.add_recipient(@client_id, true)
# sent url update to agent
if @payload['data']['url']
message = {
event: 'chat_session_notice',
data: {
session_id: chat_session.session_id,
message: @payload['data']['url'],
},
}
chat_session.send_to_recipients(message, @client_id)
end
end end
{ {
event: 'chat_status_customer', event: 'chat_status_customer',
data: current_chat.customer_state(session_id), data: current_chat.customer_state(session_id),

View file

@ -291,6 +291,7 @@ do($ = window.jQuery, window) ->
@sessionId = sessionStorage.getItem('sessionId') @sessionId = sessionStorage.getItem('sessionId')
@send 'chat_status_customer', @send 'chat_status_customer',
session_id: @sessionId session_id: @sessionId
url: window.location.href
renderBase: -> renderBase: ->
@el = $(@view('chat')( @el = $(@view('chat')(
@ -311,7 +312,12 @@ do($ = window.jQuery, window) ->
@onLeaveTemporary() @onLeaveTemporary()
) )
$(window).bind('hashchange', => $(window).bind('hashchange', =>
return if @isOpen if @isOpen
if @sessionId
@send 'chat_session_notice',
session_id: @sessionId
message: window.location.href
return
@idleTimeout.start() @idleTimeout.start()
) )
@ -527,7 +533,9 @@ do($ = window.jQuery, window) ->
if !@sessionId if !@sessionId
@el.animate { bottom: 0 }, 500, @onOpenAnimationEnd @el.animate { bottom: 0 }, 500, @onOpenAnimationEnd
@send('chat_session_init') @send('chat_session_init'
url: window.location.href
)
else else
@el.css 'bottom', 0 @el.css 'bottom', 0
@onOpenAnimationEnd() @onOpenAnimationEnd()

View file

@ -464,7 +464,8 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
this.idleTimeout.start(); this.idleTimeout.start();
this.sessionId = sessionStorage.getItem('sessionId'); this.sessionId = sessionStorage.getItem('sessionId');
return this.send('chat_status_customer', { return this.send('chat_status_customer', {
session_id: this.sessionId session_id: this.sessionId,
url: window.location.href
}); });
}; };
@ -489,6 +490,12 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
$(window).bind('hashchange', (function(_this) { $(window).bind('hashchange', (function(_this) {
return function() { return function() {
if (_this.isOpen) { if (_this.isOpen) {
if (_this.sessionId) {
_this.send('chat_session_notice', {
session_id: _this.sessionId,
message: window.location.href
});
}
return; return;
} }
return _this.idleTimeout.start(); return _this.idleTimeout.start();
@ -743,7 +750,9 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
this.el.animate({ this.el.animate({
bottom: 0 bottom: 0
}, 500, this.onOpenAnimationEnd); }, 500, this.onOpenAnimationEnd);
return this.send('chat_session_init'); return this.send('chat_session_init', {
url: window.location.href
});
} else { } else {
this.el.css('bottom', 0); this.el.css('bottom', 0);
return this.onOpenAnimationEnd(); return this.onOpenAnimationEnd();

File diff suppressed because one or more lines are too long

View file

@ -4,6 +4,7 @@ require 'browser_test_helper'
class ChatTest < TestCase class ChatTest < TestCase
def test_basic def test_basic
chat_url = "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}"
agent = browser_instance agent = browser_instance
login( login(
browser: agent, browser: agent,
@ -41,7 +42,7 @@ class ChatTest < TestCase
customer = browser_instance customer = browser_instance
location( location(
browser: customer, browser: customer,
url: "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}", url: chat_url,
) )
sleep 4 sleep 4
exists_not( exists_not(
@ -170,6 +171,7 @@ class ChatTest < TestCase
end end
def test_basic_usecase1 def test_basic_usecase1
chat_url = "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}"
agent = browser_instance agent = browser_instance
login( login(
browser: agent, browser: agent,
@ -190,7 +192,7 @@ class ChatTest < TestCase
customer = browser_instance customer = browser_instance
location( location(
browser: customer, browser: customer,
url: "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}", url: chat_url,
) )
watch_for( watch_for(
browser: customer, browser: customer,
@ -220,6 +222,11 @@ class ChatTest < TestCase
browser: agent, browser: agent,
css: '.active .chat-window .chat-status.is-modified', css: '.active .chat-window .chat-status.is-modified',
) )
match(
browser: agent,
css: '.active .chat-window .js-body',
value: chat_url,
)
set( set(
browser: agent, browser: agent,
css: '.active .chat-window .js-customerChatInput', css: '.active .chat-window .js-customerChatInput',
@ -277,6 +284,7 @@ class ChatTest < TestCase
end end
def test_basic_usecase2 def test_basic_usecase2
chat_url = "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}"
agent = browser_instance agent = browser_instance
login( login(
browser: agent, browser: agent,
@ -297,7 +305,7 @@ class ChatTest < TestCase
customer = browser_instance customer = browser_instance
location( location(
browser: customer, browser: customer,
url: "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}", url: chat_url,
) )
watch_for( watch_for(
browser: customer, browser: customer,
@ -431,6 +439,7 @@ class ChatTest < TestCase
end end
def test_basic_usecase3 def test_basic_usecase3
chat_url = "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}"
agent = browser_instance agent = browser_instance
login( login(
browser: agent, browser: agent,
@ -466,7 +475,7 @@ class ChatTest < TestCase
customer = browser_instance customer = browser_instance
location( location(
browser: customer, browser: customer,
url: "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}", url: chat_url,
) )
watch_for( watch_for(
browser: customer, browser: customer,
@ -500,6 +509,11 @@ class ChatTest < TestCase
css: '.zammad-chat .zammad-chat-agent-status', css: '.zammad-chat .zammad-chat-agent-status',
value: 'online', value: 'online',
) )
match(
browser: agent,
css: '.active .chat-window .js-body',
value: chat_url,
)
set( set(
browser: agent, browser: agent,
css: '.active .chat-window .js-customerChatInput', css: '.active .chat-window .js-customerChatInput',
@ -554,6 +568,16 @@ class ChatTest < TestCase
css: '.zammad-chat', css: '.zammad-chat',
value: 'my name is customer', value: 'my name is customer',
) )
location(
browser: customer,
url: "#{chat_url}#new_hash",
)
sleep 2
match(
browser: agent,
css: '.active .chat-window .js-body',
value: "#{chat_url}#new_hash",
)
click( click(
browser: customer, browser: customer,
css: '.js-chat-toggle', css: '.js-chat-toggle',
@ -566,6 +590,7 @@ class ChatTest < TestCase
end end
def test_timeouts def test_timeouts
chat_url = "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}"
agent = browser_instance agent = browser_instance
login( login(
browser: agent, browser: agent,
@ -592,7 +617,7 @@ class ChatTest < TestCase
customer = browser_instance customer = browser_instance
location( location(
browser: customer, browser: customer,
url: "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}", url: chat_url,
) )
watch_for( watch_for(
browser: customer, browser: customer,