Class: Renalware::Messaging::UnreadMessagesComponent

Inherits:
ApplicationComponent show all
Defined in:
app/components/renalware/messaging/unread_messages_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationComponent

#policy, #renalware

Constructor Details

#initialize(current_user:) ⇒ UnreadMessagesComponent

Returns a new instance of UnreadMessagesComponent.



8
9
10
# File 'app/components/renalware/messaging/unread_messages_component.rb', line 8

def initialize(current_user:)
  @current_user = Messaging::Internal.cast_recipient(current_user)
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user.



6
7
8
# File 'app/components/renalware/messaging/unread_messages_component.rb', line 6

def current_user
  @current_user
end

Instance Method Details

#unread_message_receiptsObject



12
13
14
15
16
17
18
19
20
21
# File 'app/components/renalware/messaging/unread_messages_component.rb', line 12

def unread_message_receipts
  @unread_message_receipts ||= begin
    receipts = current_user
      .receipts
      .includes(message: [:author, :patient])
      .order("messaging_messages.sent_at asc")
      .unread
    CollectionPresenter.new(receipts, Messaging::Internal::ReceiptPresenter)
  end
end