Class: Decidim::Messaging::Message

Inherits:
ApplicationRecord show all
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

Methods included from FriendlyDates

#friendly_created_at

Instance Method Details

#envelope_for(recipients) ⇒ 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.

Parameters:



41
42
43
44
45
# File 'app/models/decidim/messaging/message.rb', line 41

def envelope_for(recipients)
  receipts.build(recipient: sender, read_at: Time.current)

  recipients.each { |recipient| receipts.build(recipient: recipient) }
end