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

View file

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

View file

@ -448,6 +448,28 @@ class IntegrationCtiControllerTest < ActionDispatch::IntegrationTest
assert_nil(log.duration_waiting_time) assert_nil(log.duration_waiting_time)
assert_nil(log.duration_talking_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 caller list
get '/api/v1/cti/log' get '/api/v1/cti/log'
assert_response(401) assert_response(401)
@ -461,24 +483,25 @@ class IntegrationCtiControllerTest < ActionDispatch::IntegrationTest
assert_response(200) assert_response(200)
result = JSON.parse(@response.body) result = JSON.parse(@response.body)
assert_equal(result['list'].class, Array) assert_equal(result['list'].class, Array)
assert_equal(6, result['list'].count) assert_equal(7, result['list'].count)
assert(result['assets']) assert(result['assets'])
assert(result['assets']['User']) assert(result['assets']['User'])
assert(result['assets']['User'][customer2.id.to_s]) assert(result['assets']['User'][customer2.id.to_s])
assert(result['assets']['User'][customer3.id.to_s]) assert(result['assets']['User'][customer3.id.to_s])
assert_equal('1234567890-6', result['list'][0]['call_id']) assert_equal('1234567890-7', result['list'][0]['call_id'])
assert_equal('1234567890-5', result['list'][1]['call_id']) assert_equal('1234567890-6', result['list'][1]['call_id'])
assert_equal('1234567890-4', result['list'][2]['call_id']) assert_equal('1234567890-5', result['list'][2]['call_id'])
assert_equal('1234567890-3', result['list'][3]['call_id']) assert_equal('1234567890-4', result['list'][3]['call_id'])
assert_equal('1234567890-2', result['list'][4]['call_id']) assert_equal('1234567890-3', result['list'][4]['call_id'])
assert_equal('hangup', result['list'][4]['state']) assert_equal('1234567890-2', result['list'][5]['call_id'])
assert_equal('4930777000000', result['list'][4]['from']) assert_equal('hangup', result['list'][5]['state'])
assert_equal('user 1', result['list'][4]['from_comment']) assert_equal('4930777000000', result['list'][5]['from'])
assert_equal('4912347114711', result['list'][4]['to']) assert_equal('user 1', result['list'][5]['from_comment'])
assert_equal('CallerId Customer1', result['list'][4]['to_comment']) assert_equal('4912347114711', result['list'][5]['to'])
assert_equal('normalClearing', result['list'][4]['comment']) assert_equal('CallerId Customer1', result['list'][5]['to_comment'])
assert_equal('hangup', result['list'][4]['state']) assert_equal('normalClearing', result['list'][5]['comment'])
assert_equal('1234567890-1', result['list'][5]['call_id']) assert_equal('hangup', result['list'][5]['state'])
assert_equal('1234567890-1', result['list'][6]['call_id'])
end end

View file

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