2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2015-12-09 13:09:37 +00:00
|
|
|
class Sessions::Event::ChatBase < Sessions::Event::Base
|
2018-11-02 17:42:57 +00:00
|
|
|
database_connection_required
|
2015-12-09 13:09:37 +00:00
|
|
|
|
|
|
|
def run
|
2015-11-11 13:10:26 +00:00
|
|
|
|
|
|
|
# check if feature is enabled
|
2015-11-12 13:19:41 +00:00
|
|
|
return if Setting.get('chat')
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2015-11-12 13:19:41 +00:00
|
|
|
{
|
|
|
|
event: 'chat_error',
|
2018-12-19 17:31:51 +00:00
|
|
|
data: {
|
2015-11-12 13:19:41 +00:00
|
|
|
state: 'chat_disabled',
|
|
|
|
},
|
|
|
|
}
|
2015-11-11 13:10:26 +00:00
|
|
|
end
|
|
|
|
|
2015-11-25 09:33:39 +00:00
|
|
|
def current_chat_session
|
2015-12-09 13:09:37 +00:00
|
|
|
Chat::Session.find_by(session_id: @payload['data']['session_id'])
|
2015-11-25 09:33:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def check_chat_session_exists
|
2015-12-09 13:09:37 +00:00
|
|
|
if !@payload['data'] || !@payload['data']['session_id']
|
2015-11-25 09:33:39 +00:00
|
|
|
error = {
|
|
|
|
event: 'chat_error',
|
2018-12-19 17:31:51 +00:00
|
|
|
data: {
|
2021-11-15 15:58:19 +00:00
|
|
|
state: __('Need session_id.'),
|
2015-11-25 09:33:39 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
Sessions.send(@client_id, error)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
return true if current_chat_session
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2015-11-25 09:33:39 +00:00
|
|
|
error = {
|
|
|
|
event: 'chat_error',
|
2018-12-19 17:31:51 +00:00
|
|
|
data: {
|
2015-12-09 13:09:37 +00:00
|
|
|
state: "No such session id #{@payload['data']['session_id']}",
|
2015-11-25 09:33:39 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
Sessions.send(@client_id, error)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def current_chat
|
2015-12-09 13:09:37 +00:00
|
|
|
Chat.find_by(id: @payload['data']['chat_id'])
|
2015-11-25 09:33:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def check_chat_exists
|
|
|
|
chat = current_chat
|
|
|
|
return true if chat
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2015-11-25 09:33:39 +00:00
|
|
|
error = {
|
|
|
|
event: 'chat_error',
|
2018-12-19 17:31:51 +00:00
|
|
|
data: {
|
2015-11-25 09:33:39 +00:00
|
|
|
state: 'no_such_chat',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
Sessions.send(@client_id, error)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2015-11-11 13:10:26 +00:00
|
|
|
end
|