Class: Decidim::Messaging::Message
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Messaging::Message
- Includes:
- FriendlyDates
- Defined in:
- 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 remitent (sender) of the message.
Methods included from FriendlyDates
Instance Method Details
#body_with_links ⇒ Object
Public: Returns the comment body with links
62 63 64 |
# File 'app/models/decidim/messaging/message.rb', line 62 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 remitent (sender) of the message. Receipts are unread by default, except for the sender’s receipt.
If the sender is a UserGroup then receipts will be created for its managers a “from” user can be specified to avoid create a receipt for the real user sending the message
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/models/decidim/messaging/message.rb', line 47 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) all_recipients(recipients).each do |recipient| next if @already_notified.include?(recipient) receipts.build(recipient: recipient) @already_notified.push(recipient) end end |