Added agent info on reconnect.

This commit is contained in:
Martin Edenhofer 2015-11-12 16:16:01 +01:00
parent fc433fd649
commit dfd3bb4adf
4 changed files with 38 additions and 16 deletions

View file

@ -8,12 +8,29 @@ class Chat < ApplicationModel
return { state: 'chat_disabled' } if !Setting.get('chat')
if session_id
chat_session = Chat::Session.find_by(session_id: session_id)
user = nil
if chat_session && chat_session.user_id
chat_user = User.find(chat_session.user_id)
url = nil
if chat_user.image && chat_user.image != 'none'
url = "/api/v1/users/image/#{chat_user.image}"
end
user = {
name: chat_user.fullname,
avatar: url,
}
end
session = Chat.session_state(session_id)
if session
return {
state: 'reconnect',
session: session,
agent: user,
}
end
end
if Chat::Agent.where(active: true).where('updated_at > ?', Time.zone.now - 2.minutes).count > 0
if active_chat_count >= max_queue
@ -31,8 +48,9 @@ class Chat < ApplicationModel
def self.session_state(session_id)
session_attributes = []
chat_session_id = Chat::Session.find_by(session_id: session_id)
Chat::Message.where(chat_session_id: chat_session_id.id).each { |message|
chat_session = Chat::Session.find_by(session_id: session_id)
return if !chat_session
Chat::Message.where(chat_session_id: chat_session.id).each { |message|
session_attributes.push message.attributes
}
session_attributes

View file

@ -16,7 +16,7 @@ class Sessions::Event::ChatSessionMessage < Sessions::Event::ChatBase
return {
event: 'chat_session_message',
data: {
state: "No such session id #{data['data']['session_id']}",
state: "No such session id #{@data['data']['session_id']}",
},
}
end

View file

@ -16,7 +16,7 @@ class Sessions::Event::ChatSessionTyping < Sessions::Event::ChatBase
return {
event: 'chat_session_typing',
data: {
state: "No such session id #{data['data']['session_id']}",
state: "No such session id #{@data['data']['session_id']}",
},
}
end

View file

@ -108,7 +108,7 @@ do($ = window.jQuery, window) ->
when 'chat_session_start'
@onConnectionEstablished pipe.data
when 'chat_session_queue'
@onQueue pipe.data
@onQueueScreen pipe.data
when 'chat_session_closed'
@onSessionClosed pipe.data
when 'chat_session_left'
@ -126,17 +126,19 @@ do($ = window.jQuery, window) ->
@log 'debug', 'Zammad Chat: Too many clients in queue. Clients in queue: ', pipe.data.queue
when 'reconnect'
@log 'debug', 'old messages', pipe.data.session
@openSession pipe.data.session
@reopenSession pipe.data
onReady: =>
if @options.show
@show()
openSession: (session) =>
reopenSession: (data) =>
unfinishedMessage = sessionStorage.getItem 'unfinished_message'
for message in session
console.log "message in session", message
@onConnectionEstablished(data)
for message in data.session
@log 'debug', "message in session", message
@renderMessage
message: message.content
id: message.id
@ -434,7 +436,9 @@ do($ = window.jQuery, window) ->
clearTimeout @onInitialQueueDelayId
@inQueue = false
if data.agent
@agent = data.agent
if data.session_id
@setSessionId data.session_id
@el.find('.zammad-chat-agent').html @view('agent')