Class: Decidim::Messaging::Message
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Messaging::Message
- Includes:
- FriendlyDates
- Defined in:
- decidim-core/app/models/decidim/messaging/message.rb
Overview
Holds a single message in a conversation. A message has a body, and sender and a set of receipts, which correspond to each user that will receive the message, namely, the interlocutors of the sender in the conversation.
Instance Method Summary collapse
-
#body_with_links ⇒ Object
Public: Returns the comment body with links.
-
#envelope_for(recipients:, from: nil) ⇒ Object
Associates receipts for this message for each of the given users, including also a receipt for the remittant (sender) of the message.
Methods included from FriendlyDates
Instance Method Details
#body_with_links ⇒ Object
Public: Returns the comment body with links
58 59 60 |
# File 'decidim-core/app/models/decidim/messaging/message.rb', line 58 def body_with_links Decidim::ContentRenderers::LinkRenderer.new(body).render end |
#envelope_for(recipients:, from: nil) ⇒ Object
Associates receipts for this message for each of the given users, including also a receipt for the remittant (sender) of the message. Receipts are unread by default, except for the sender’s receipt.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'decidim-core/app/models/decidim/messaging/message.rb', line 43 def envelope_for(recipients:, from: nil) @from = sender.is_a?(User) ? sender : from @already_notified = [@from] receipts.build(recipient: @from, read_at: Time.current) if @from.is_a?(User) recipients.each do |recipient| next if @already_notified.include?(recipient) receipts.build(recipient:) @already_notified.push(recipient) end end |