# frozen_string_literal: true # == Schema Information # # Table name: messages # # id :integer not null, primary key # body :string not null # created_at :datetime not null # updated_at :datetime not null # conversation_id :integer not null # from_id :integer not null # # Indexes # # index_messages_on_conversation_id_and_created_at (conversation_id,created_at) # index_messages_on_from_id (from_id) # # Foreign Keys # # fk_rails_... (from_id => users.id) ON DELETE => restrict ON UPDATE => cascade # class Message < ApplicationRecord belongs_to :from, class_name: 'User', optional: true belongs_to :conversation, optional: true validates :body, presence: true, length: { maximum: 600_000 } validates :from, presence: true after_create do conversation.from_read = false conversation.to_read = false conversation.last_message_at = Time.zone.now conversation.save end def for_route self end # TODO: create a base class for comments/posts/messages alias user from def author(_reveal_anon=false) from.name end def user_visible? true end end