From db25b7d944392c78fb3effc2304460f245ebab2d Mon Sep 17 00:00:00 2001 From: Tanmay Sharma Date: Tue, 22 Jul 2025 16:08:08 +0400 Subject: [PATCH] keep the is_verified changes only --- .../api/v1/accounts/contacts_controller.rb | 19 +++++++++---------- app/models/contact.rb | 2 +- .../v1/accounts/contacts/active.json.jbuilder | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/controllers/api/v1/accounts/contacts_controller.rb b/app/controllers/api/v1/accounts/contacts_controller.rb index ba2d92186..02f8d0e5f 100644 --- a/app/controllers/api/v1/accounts/contacts_controller.rb +++ b/app/controllers/api/v1/accounts/contacts_controller.rb @@ -17,8 +17,8 @@ class Api::V1::Accounts::ContactsController < Api::V1::Accounts::BaseController before_action :set_include_contact_inboxes, only: [:index, :active, :search, :filter, :show, :update] def index + @contacts_count = resolved_contacts.count @contacts = fetch_contacts(resolved_contacts) - @contacts_count = @contacts.total_count end def search @@ -29,8 +29,8 @@ class Api::V1::Accounts::ContactsController < Api::V1::Accounts::BaseController OR contacts.additional_attributes->>\'company_name\' ILIKE :search', search: "%#{params[:q].strip}%" ) + @contacts_count = contacts.count @contacts = fetch_contacts(contacts) - @contacts_count = @contacts.total_count end def import @@ -55,8 +55,8 @@ class Api::V1::Accounts::ContactsController < Api::V1::Accounts::BaseController def active contacts = Current.account.contacts.where(id: ::OnlineStatusTracker .get_available_contact_ids(Current.account.id)) + @contacts_count = contacts.count @contacts = fetch_contacts(contacts) - @contacts_count = @contacts.total_count end def show; end @@ -134,14 +134,13 @@ class Api::V1::Accounts::ContactsController < Api::V1::Accounts::BaseController end def fetch_contacts(contacts) - # Build includes hash to avoid separate query when contact_inboxes are needed - includes_hash = { avatar_attachment: [:blob] } - includes_hash[:contact_inboxes] = { inbox: :channel } if @include_contact_inboxes + contacts_with_avatar = filtrate(contacts) + .includes([{ avatar_attachment: [:blob] }]) + .page(@current_page).per(RESULTS_PER_PAGE) - filtrate(contacts) - .includes(includes_hash) - .page(@current_page) - .per(RESULTS_PER_PAGE) + return contacts_with_avatar.includes([{ contact_inboxes: [:inbox] }]) if @include_contact_inboxes + + contacts_with_avatar end def build_contact_inbox diff --git a/app/models/contact.rb b/app/models/contact.rb index 5e69f26f1..a349c948d 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -179,7 +179,7 @@ class Contact < ApplicationRecord end def self.resolved_contacts - where(is_verified: true) + where("contacts.email <> '' OR contacts.phone_number <> '' OR contacts.identifier <> ''") end def discard_invalid_attrs diff --git a/app/views/api/v1/accounts/contacts/active.json.jbuilder b/app/views/api/v1/accounts/contacts/active.json.jbuilder index 577dff4be..cde9e5445 100644 --- a/app/views/api/v1/accounts/contacts/active.json.jbuilder +++ b/app/views/api/v1/accounts/contacts/active.json.jbuilder @@ -5,6 +5,6 @@ end json.payload do json.array! @contacts do |contact| - json.partial! 'api/v1/models/contact', formats: [:json], resource: contact, with_contact_inboxes: @include_contact_inboxes + json.partial! 'api/v1/models/contact', formats: [:json], resource: contact, with_contact_inboxes: true end end