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
@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) =>
return if data.session_id isnt @session.session_id
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'
if @session
if @session && @session.preferences && @session.preferences.url
@addNoticeMessage(@session.preferences.url)
if @session.messages
for message in @session.messages
if message.created_by_id
@ -660,6 +668,15 @@ class ChatWindow extends App.Controller
@scrollToBottom()
addNoticeMessage: (message, args) ->
@maybeAddTimestamp()
@body.append App.view('customer_chat/chat_notice_message')
message: message
args: args
@scrollToBottom()
scrollToBottom: ->
@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>
<% if @session: %>
<li><%- @T('Created at') %>: <%- @Ttimestamp(@session.created_at) %>

View file

@ -32,6 +32,7 @@ class Sessions::Event::ChatSessionInit < Sessions::Event::ChatBase
name: '',
state: 'waiting',
preferences: {
url: @payload['data']['url'],
participants: [@client_id],
remote_ip: @remote_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
chat_session = Chat::Session.find_by(session_id: session_id)
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
{
event: 'chat_status_customer',
data: current_chat.customer_state(session_id),

View file

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

View file

@ -464,7 +464,8 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
this.idleTimeout.start();
this.sessionId = sessionStorage.getItem('sessionId');
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) {
return function() {
if (_this.isOpen) {
if (_this.sessionId) {
_this.send('chat_session_notice', {
session_id: _this.sessionId,
message: window.location.href
});
}
return;
}
return _this.idleTimeout.start();
@ -743,7 +750,9 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
this.el.animate({
bottom: 0
}, 500, this.onOpenAnimationEnd);
return this.send('chat_session_init');
return this.send('chat_session_init', {
url: window.location.href
});
} else {
this.el.css('bottom', 0);
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
def test_basic
chat_url = "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}"
agent = browser_instance
login(
browser: agent,
@ -41,7 +42,7 @@ class ChatTest < TestCase
customer = browser_instance
location(
browser: customer,
url: "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}",
url: chat_url,
)
sleep 4
exists_not(
@ -170,6 +171,7 @@ class ChatTest < TestCase
end
def test_basic_usecase1
chat_url = "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}"
agent = browser_instance
login(
browser: agent,
@ -190,7 +192,7 @@ class ChatTest < TestCase
customer = browser_instance
location(
browser: customer,
url: "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}",
url: chat_url,
)
watch_for(
browser: customer,
@ -220,6 +222,11 @@ class ChatTest < TestCase
browser: agent,
css: '.active .chat-window .chat-status.is-modified',
)
match(
browser: agent,
css: '.active .chat-window .js-body',
value: chat_url,
)
set(
browser: agent,
css: '.active .chat-window .js-customerChatInput',
@ -277,6 +284,7 @@ class ChatTest < TestCase
end
def test_basic_usecase2
chat_url = "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}"
agent = browser_instance
login(
browser: agent,
@ -297,7 +305,7 @@ class ChatTest < TestCase
customer = browser_instance
location(
browser: customer,
url: "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}",
url: chat_url,
)
watch_for(
browser: customer,
@ -431,6 +439,7 @@ class ChatTest < TestCase
end
def test_basic_usecase3
chat_url = "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}"
agent = browser_instance
login(
browser: agent,
@ -466,7 +475,7 @@ class ChatTest < TestCase
customer = browser_instance
location(
browser: customer,
url: "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}",
url: chat_url,
)
watch_for(
browser: customer,
@ -500,6 +509,11 @@ class ChatTest < TestCase
css: '.zammad-chat .zammad-chat-agent-status',
value: 'online',
)
match(
browser: agent,
css: '.active .chat-window .js-body',
value: chat_url,
)
set(
browser: agent,
css: '.active .chat-window .js-customerChatInput',
@ -554,6 +568,16 @@ class ChatTest < TestCase
css: '.zammad-chat',
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(
browser: customer,
css: '.js-chat-toggle',
@ -566,6 +590,7 @@ class ChatTest < TestCase
end
def test_timeouts
chat_url = "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}"
agent = browser_instance
login(
browser: agent,
@ -592,7 +617,7 @@ class ChatTest < TestCase
customer = browser_instance
location(
browser: customer,
url: "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}",
url: chat_url,
)
watch_for(
browser: customer,