Follow up for issue #2193 - re-enabled shown anonymous if no caller is exists. Fixed triggering event of new/changed caller log items.

This commit is contained in:
Martin Edenhofer 2018-08-17 16:12:28 +02:00
parent c60be2140e
commit a8642d3ed0
4 changed files with 104 additions and 40 deletions

View file

@ -30,21 +30,25 @@
<% classes.push('is-inactive') if !user.active %>
<% if caller_id.level isnt 'known': %><%- @T('maybe') %> <% end %>
<span class="<%= classes.join(' ') %>" data-id="<%- user.id %>"><%= user.displayNameLong() %></span><br>
<% else if caller_id.comment: %>
<% else if !_.isEmpty(caller_id.comment): %>
<% shown = true %>
<%- @T('maybe') %> <%= caller_id.comment %><br>
<% end %>
<% end %>
<% end %>
<% if !shown && item.from_comment: %>
<% if !shown && !_.isEmpty(item.from_comment): %>
<% shown = true %>
<% if item.from_comment: %><%= item.from_comment %><% end %>
<%= item.from_comment %>
<br>
<% end %>
<% if shown: %>
<small><%= item.from_pretty %></small>
<% else: %>
<% if !_.isEmpty(item.from_pretty): %>
<span class="js-userNew u-clickable" href="#"><%= item.from_pretty %></span>
<% else: %>
<span><%= item.from %></span>
<% end %>
<% end %>
</td>
<td>
@ -58,21 +62,25 @@
<% classes.push('is-inactive') if !user.active %>
<% if caller_id.level isnt 'known': %><%- @T('maybe') %> <% end %>
<span class="<%= classes.join(' ') %>" data-id="<%- user.id %>"><%= user.displayNameLong() %></span><br>
<% else if caller_id.comment: %>
<% else if !_.isEmpty(caller_id.comment): %>
<% shown = true %>
<%- @T('maybe') %> <%= caller_id.comment %><br>
<% end %>
<% end %>
<% end %>
<% if !shown && item.to_comment: %>
<% if !shown && !_.isEmpty(item.to_comment): %>
<% shown = true %>
<% if item.to_comment: %><%= item.to_comment %><% end %>
<%= item.to_comment %>
<br>
<% end %>
<% if shown: %>
<small><%= item.to_pretty %></small>
<% else: %>
<% if !_.isEmpty(item.to_pretty): %>
<%= item.to_pretty %>
<% else: %>
<%= item.to %>
<% end %>
<% end %>
</td>
<td style="vertical-align: middle">

View file

@ -4,9 +4,7 @@ module Cti
store :preferences
after_create :push_incoming_call, :push_caller_list_update
after_update :push_incoming_call, :push_caller_list_update
after_destroy :push_caller_list_update
after_commit :push_incoming_call, :push_caller_list_update
=begin
@ -366,12 +364,13 @@ Cti::Log.process(
end
def push_incoming_call
return if state != 'newCall'
return if direction != 'in'
users = User.with_permissions('cti.agent')
users.each do |user|
return true if destroyed?
return true if state != 'newCall'
return true if direction != 'in'
# send notify about event
users = User.with_permissions('cti.agent')
users.each do |user|
Sessions.send_to(
user.id,
{
@ -380,24 +379,21 @@ Cti::Log.process(
},
)
end
true
end
def self.push_caller_list_update?(record)
list_ids = Cti::Log.log_records.pluck(:id)
if list_ids.present?
last_caller_log = Cti::Log.find_by(id: list_ids.last)
return false if last_caller_log && last_caller_log.created_at > record.created_at - 1.day
end
true
return true if list_ids.include?(record.id)
false
end
def push_caller_list_update
return false if Cti::Log.push_caller_list_update?(self)
users = User.with_permissions('cti.agent')
users.each do |user|
return false if !Cti::Log.push_caller_list_update?(self)
# send notify on create/update/delete
users = User.with_permissions('cti.agent')
users.each do |user|
Sessions.send_to(
user.id,
{
@ -405,7 +401,6 @@ Cti::Log.process(
},
)
end
true
end

View file

@ -448,6 +448,28 @@ class IntegrationCtiControllerTest < ActionDispatch::IntegrationTest
assert_nil(log.duration_waiting_time)
assert_nil(log.duration_talking_time)
# inbound - IV - new call
params = 'event=newCall&direction=in&to=4930600000000&from=anonymous&call_id=1234567890-7&user%5B%5D=user+1,user+2'
post "/api/v1/cti/#{token}", params: params
assert_response(200)
log = Cti::Log.find_by(call_id: '1234567890-7')
assert(log)
assert_equal('4930600000000', log.to)
assert_equal('anonymous', log.from)
assert_equal('in', log.direction)
assert_equal('user 1,user 2', log.to_comment)
assert_nil(log.from_comment)
assert_not(log.preferences['to'])
assert_not(log.preferences['from'])
assert_nil(log.comment)
assert_equal('newCall', log.state)
assert_equal(false, log.done)
assert(log.initialized_at)
assert_nil(log.start_at)
assert_nil(log.end_at)
assert_nil(log.duration_waiting_time)
assert_nil(log.duration_talking_time)
# get caller list
get '/api/v1/cti/log'
assert_response(401)
@ -461,24 +483,25 @@ class IntegrationCtiControllerTest < ActionDispatch::IntegrationTest
assert_response(200)
result = JSON.parse(@response.body)
assert_equal(result['list'].class, Array)
assert_equal(6, result['list'].count)
assert_equal(7, result['list'].count)
assert(result['assets'])
assert(result['assets']['User'])
assert(result['assets']['User'][customer2.id.to_s])
assert(result['assets']['User'][customer3.id.to_s])
assert_equal('1234567890-6', result['list'][0]['call_id'])
assert_equal('1234567890-5', result['list'][1]['call_id'])
assert_equal('1234567890-4', result['list'][2]['call_id'])
assert_equal('1234567890-3', result['list'][3]['call_id'])
assert_equal('1234567890-2', result['list'][4]['call_id'])
assert_equal('hangup', result['list'][4]['state'])
assert_equal('4930777000000', result['list'][4]['from'])
assert_equal('user 1', result['list'][4]['from_comment'])
assert_equal('4912347114711', result['list'][4]['to'])
assert_equal('CallerId Customer1', result['list'][4]['to_comment'])
assert_equal('normalClearing', result['list'][4]['comment'])
assert_equal('hangup', result['list'][4]['state'])
assert_equal('1234567890-1', result['list'][5]['call_id'])
assert_equal('1234567890-7', result['list'][0]['call_id'])
assert_equal('1234567890-6', result['list'][1]['call_id'])
assert_equal('1234567890-5', result['list'][2]['call_id'])
assert_equal('1234567890-4', result['list'][3]['call_id'])
assert_equal('1234567890-3', result['list'][4]['call_id'])
assert_equal('1234567890-2', result['list'][5]['call_id'])
assert_equal('hangup', result['list'][5]['state'])
assert_equal('4930777000000', result['list'][5]['from'])
assert_equal('user 1', result['list'][5]['from_comment'])
assert_equal('4912347114711', result['list'][5]['to'])
assert_equal('CallerId Customer1', result['list'][5]['to_comment'])
assert_equal('normalClearing', result['list'][5]['comment'])
assert_equal('hangup', result['list'][5]['state'])
assert_equal('1234567890-1', result['list'][6]['call_id'])
end

View file

@ -479,7 +479,18 @@ Mob: +49 333 8362222",
test '5 probe if caller log need to be pushed' do
60.times do |count|
Cti::Log.process(
'cause' => '',
'event' => 'newCall',
'user' => 'user 1',
'from' => '491111222222',
'to' => '4930600000000',
'callId' => 'touch-loop-0',
'direction' => 'in',
)
assert(Cti::Log.push_caller_list_update?(Cti::Log.last))
65.times do |count|
travel 1.hour
Cti::Log.process(
'cause' => '',
@ -487,13 +498,40 @@ Mob: +49 333 8362222",
'user' => 'user 1',
'from' => '491111222222',
'to' => '4930600000000',
'callId' => "touch-loop-#{count}",
'callId' => "touch-loop-1-#{count}",
'direction' => 'in',
)
end
assert(Cti::Log.push_caller_list_update?(Cti::Log.last))
assert_not(Cti::Log.push_caller_list_update?(Cti::Log.first))
65.times do |count|
travel 1.minute
Cti::Log.process(
'cause' => '',
'event' => 'newCall',
'user' => 'user 1',
'from' => '491111222222',
'to' => '4930600000000',
'callId' => "touch-loop-2-#{count}",
'direction' => 'in',
)
end
assert(Cti::Log.push_caller_list_update?(Cti::Log.last))
assert_not(Cti::Log.push_caller_list_update?(Cti::Log.first))
travel 2.seconds
Cti::Log.process(
'cause' => '',
'event' => 'newCall',
'user' => 'user 1',
'from' => '491111222222',
'to' => '4930600000000',
'callId' => 'touch-loop-3-1',
'direction' => 'in',
)
assert(Cti::Log.push_caller_list_update?(Cti::Log.last))
end
end