Added agent info on reconnect.
This commit is contained in:
parent
fc433fd649
commit
dfd3bb4adf
4 changed files with 38 additions and 16 deletions
|
@ -8,12 +8,29 @@ class Chat < ApplicationModel
|
||||||
return { state: 'chat_disabled' } if !Setting.get('chat')
|
return { state: 'chat_disabled' } if !Setting.get('chat')
|
||||||
|
|
||||||
if session_id
|
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)
|
session = Chat.session_state(session_id)
|
||||||
|
if session
|
||||||
return {
|
return {
|
||||||
state: 'reconnect',
|
state: 'reconnect',
|
||||||
session: session,
|
session: session,
|
||||||
|
agent: user,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if Chat::Agent.where(active: true).where('updated_at > ?', Time.zone.now - 2.minutes).count > 0
|
if Chat::Agent.where(active: true).where('updated_at > ?', Time.zone.now - 2.minutes).count > 0
|
||||||
if active_chat_count >= max_queue
|
if active_chat_count >= max_queue
|
||||||
|
@ -31,8 +48,9 @@ class Chat < ApplicationModel
|
||||||
|
|
||||||
def self.session_state(session_id)
|
def self.session_state(session_id)
|
||||||
session_attributes = []
|
session_attributes = []
|
||||||
chat_session_id = Chat::Session.find_by(session_id: session_id)
|
chat_session = Chat::Session.find_by(session_id: session_id)
|
||||||
Chat::Message.where(chat_session_id: chat_session_id.id).each { |message|
|
return if !chat_session
|
||||||
|
Chat::Message.where(chat_session_id: chat_session.id).each { |message|
|
||||||
session_attributes.push message.attributes
|
session_attributes.push message.attributes
|
||||||
}
|
}
|
||||||
session_attributes
|
session_attributes
|
||||||
|
|
|
@ -16,7 +16,7 @@ class Sessions::Event::ChatSessionMessage < Sessions::Event::ChatBase
|
||||||
return {
|
return {
|
||||||
event: 'chat_session_message',
|
event: 'chat_session_message',
|
||||||
data: {
|
data: {
|
||||||
state: "No such session id #{data['data']['session_id']}",
|
state: "No such session id #{@data['data']['session_id']}",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,7 +16,7 @@ class Sessions::Event::ChatSessionTyping < Sessions::Event::ChatBase
|
||||||
return {
|
return {
|
||||||
event: 'chat_session_typing',
|
event: 'chat_session_typing',
|
||||||
data: {
|
data: {
|
||||||
state: "No such session id #{data['data']['session_id']}",
|
state: "No such session id #{@data['data']['session_id']}",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -108,7 +108,7 @@ do($ = window.jQuery, window) ->
|
||||||
when 'chat_session_start'
|
when 'chat_session_start'
|
||||||
@onConnectionEstablished pipe.data
|
@onConnectionEstablished pipe.data
|
||||||
when 'chat_session_queue'
|
when 'chat_session_queue'
|
||||||
@onQueue pipe.data
|
@onQueueScreen pipe.data
|
||||||
when 'chat_session_closed'
|
when 'chat_session_closed'
|
||||||
@onSessionClosed pipe.data
|
@onSessionClosed pipe.data
|
||||||
when 'chat_session_left'
|
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
|
@log 'debug', 'Zammad Chat: Too many clients in queue. Clients in queue: ', pipe.data.queue
|
||||||
when 'reconnect'
|
when 'reconnect'
|
||||||
@log 'debug', 'old messages', pipe.data.session
|
@log 'debug', 'old messages', pipe.data.session
|
||||||
@openSession pipe.data.session
|
@reopenSession pipe.data
|
||||||
|
|
||||||
onReady: =>
|
onReady: =>
|
||||||
if @options.show
|
if @options.show
|
||||||
@show()
|
@show()
|
||||||
|
|
||||||
openSession: (session) =>
|
reopenSession: (data) =>
|
||||||
unfinishedMessage = sessionStorage.getItem 'unfinished_message'
|
unfinishedMessage = sessionStorage.getItem 'unfinished_message'
|
||||||
|
|
||||||
for message in session
|
@onConnectionEstablished(data)
|
||||||
console.log "message in session", message
|
|
||||||
|
for message in data.session
|
||||||
|
@log 'debug', "message in session", message
|
||||||
@renderMessage
|
@renderMessage
|
||||||
message: message.content
|
message: message.content
|
||||||
id: message.id
|
id: message.id
|
||||||
|
@ -434,7 +436,9 @@ do($ = window.jQuery, window) ->
|
||||||
clearTimeout @onInitialQueueDelayId
|
clearTimeout @onInitialQueueDelayId
|
||||||
|
|
||||||
@inQueue = false
|
@inQueue = false
|
||||||
|
if data.agent
|
||||||
@agent = data.agent
|
@agent = data.agent
|
||||||
|
if data.session_id
|
||||||
@setSessionId data.session_id
|
@setSessionId data.session_id
|
||||||
|
|
||||||
@el.find('.zammad-chat-agent').html @view('agent')
|
@el.find('.zammad-chat-agent').html @view('agent')
|
||||||
|
|
Loading…
Reference in a new issue