## Description Adds the account-level `unread_count_for_filters` feature flag as the dark-launch gate for filtered sidebar unread counts. This reuses the deprecated `quoted_email_reply` flag slot, resets the reused bit for existing accounts, and removes stale defaults so new accounts do not reference the old flag. This also adds the feature where we are now calculating the unread counts for built in filters like mentions, participating and unattended along with unread count for saved filters/folders. Closes [CW-7262](https://linear.app/chatwoot/issue/CW-7262/unread-counts-for-filters-folders) ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality not to work as expected) - [ ] This change requires a documentation update
45 lines
1.3 KiB
Ruby
45 lines
1.3 KiB
Ruby
# == Schema Information
|
|
#
|
|
# Table name: inbox_members
|
|
#
|
|
# id :integer not null, primary key
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
# inbox_id :integer not null
|
|
# user_id :integer not null
|
|
#
|
|
# Indexes
|
|
#
|
|
# index_inbox_members_on_inbox_id (inbox_id)
|
|
# index_inbox_members_on_inbox_id_and_user_id (inbox_id,user_id) UNIQUE
|
|
#
|
|
|
|
class InboxMember < ApplicationRecord
|
|
validates :inbox_id, presence: true
|
|
validates :user_id, presence: true
|
|
validates :user_id, uniqueness: { scope: :inbox_id }
|
|
|
|
belongs_to :user
|
|
belongs_to :inbox
|
|
|
|
after_create :add_agent_to_round_robin
|
|
after_destroy :remove_agent_from_round_robin
|
|
after_commit :invalidate_filtered_unread_count_visibility, on: [:create, :destroy]
|
|
|
|
private
|
|
|
|
def add_agent_to_round_robin
|
|
::AutoAssignment::InboxRoundRobinService.new(inbox: inbox).add_agent_to_queue(user_id)
|
|
end
|
|
|
|
def remove_agent_from_round_robin
|
|
::AutoAssignment::InboxRoundRobinService.new(inbox: inbox).remove_agent_from_queue(user_id) if inbox.present?
|
|
end
|
|
|
|
def invalidate_filtered_unread_count_visibility
|
|
::Conversations::UnreadCounts::FilteredCountInvalidator.new(inbox&.account).user_visibility_changed!(user_id: user_id)
|
|
end
|
|
end
|
|
|
|
InboxMember.include_mod_with('Audit::InboxMember')
|