From d34aae41f1a7ae4fc9958d9c095e412614e49963 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Tue, 6 Dec 2016 15:27:07 +0100 Subject: [PATCH] Follow up: Pull request #495 - refactoring broke level based lookup. --- app/models/cti/caller_id.rb | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/app/models/cti/caller_id.rb b/app/models/cti/caller_id.rb index dc09c98a1..32ab7688e 100644 --- a/app/models/cti/caller_id.rb +++ b/app/models/cti/caller_id.rb @@ -25,6 +25,9 @@ module Cti o_id: data[:o_id], user_id: data[:user_id], ) + # p "------------------" + # p record + return record if !record.new_record? record.comment = data[:comment] record.save! @@ -41,11 +44,23 @@ returns =end def self.lookup(caller_id) - where(caller_id: caller_id) - .group(:user_id, :id) \ - # first known, then maybe, last others - .order("level != 'known', level != 'maybe', id DESC") - .limit(20) + + result = [] + ['known', 'maybe', nil].each { |level| + + search_params = { + caller_id: caller_id, + } + + if level + search_params[:level] = level + end + + result = Cti::CallerId.where(search_params).group(:user_id, :id).order(id: 'DESC').limit(20) + + break if result.present? + } + result end =begin