Class: Decidim::Messaging::Message

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

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:



36
37
38
39
40
# File 'app/models/decidim/messaging/message.rb', line 36

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

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