Module: PrivateExtension::PrivateMessages::PrivateMessageExtensions::ClassMethods

Defined in:
lib/private_message_extensions.rb

Instance Method Summary collapse

Instance Method Details

#read_message(id, reader) ⇒ Object

Ensures the passed user is either the sender or the recipient then returns the message. If the reader is the recipient and the message has yet not been read, it marks the read_at timestamp.



38
39
40
41
42
43
44
45
# File 'lib/private_message_extensions.rb', line 38

def read_message(id, reader)
  message = where("sender_id = ? OR recipient_id = ?", reader, reader).first
  if message.read_at.nil? && reader == message.recipient
    message.read_at = Time.now
    message.save!
  end
  message
end