Class: DeliveryMethods::TurboStreamNotification
- Inherits:
-
Noticed::DeliveryMethod
- Object
- Noticed::DeliveryMethod
- DeliveryMethods::TurboStreamNotification
- Defined in:
- app/notifiers/delivery_methods/turbo_stream_notification.rb
Overview
Broadcasts a Turbo Stream to the recipient's personal notification stream
so that sidebar conversation items update in real time when they are on
any page that subscribes to turbo_stream_from "notifications:#party_id".
Renders the conversation_sidebar_item partial (not active, marked unread)
and replaces the existing DOM element identified by the conversation's dom_id.
If the user is not on the chat page the broadcast simply has no effect.
Instance Method Summary collapse
Instance Method Details
#deliver ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/notifiers/delivery_methods/turbo_stream_notification.rb', line 11 def deliver return unless recipient.is_a?(Party) conversation = params[:conversation] return unless conversation renderer = build_renderer html = renderer.render( partial: 'crm/assistant_chat/conversation_sidebar_item', locals: { conv: conversation, is_active: false, is_unread: true } ) Turbo::StreamsChannel.broadcast_replace_to( "notifications:#{recipient.id}", target: ActionView::RecordIdentifier.dom_id(conversation), html: html ) end |