module PrivateExtension::PrivateMessages::PrivateMessageExtensions::ClassMethods
Public Instance Methods
read_message(id, reader)
click to toggle source
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.
# 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