Class: Collavre::Inbox::BadgeComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/collavre/inbox/badge_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user: nil, creative: nil, count: nil, badge_id: "desktop-inbox-badge", show_zero: false) ⇒ BadgeComponent

Returns a new instance of BadgeComponent.



6
7
8
9
10
11
12
# File 'app/components/collavre/inbox/badge_component.rb', line 6

def initialize(user: nil, creative: nil, count: nil, badge_id: "desktop-inbox-badge", show_zero: false)
  @user = user
  @creative = creative
  @count = count
  @badge_id = badge_id
  @show_zero = show_zero
end

Instance Attribute Details

#badge_idObject (readonly)

Returns the value of attribute badge_id.



4
5
6
# File 'app/components/collavre/inbox/badge_component.rb', line 4

def badge_id
  @badge_id
end

#show_zeroObject (readonly)

Returns the value of attribute show_zero.



4
5
6
# File 'app/components/collavre/inbox/badge_component.rb', line 4

def show_zero
  @show_zero
end

Instance Method Details

#countObject



14
15
16
17
18
19
20
21
22
23
24
# File 'app/components/collavre/inbox/badge_component.rb', line 14

def count
  return @count if @count

  if @creative && @user
    # Use CommentReadPointer-based unread count for inbox creative
    unread_count_for_creative
  else
    # Legacy fallback: InboxItem count
    InboxItem.where(owner: @user, state: "new").count
  end
end