Show private messages in foodsofts index pages (fixes #106)

This commit is contained in:
Patrick Gansterer 2018-12-20 16:59:37 +01:00
parent f8148e7d30
commit 722bb474d1
7 changed files with 10 additions and 8 deletions

View file

@ -9,9 +9,11 @@ class Message < ApplicationRecord
attr_accessor :send_method, :recipient_tokens, :order_id
scope :pub, -> { where(:private => false) }
scope :threads, -> { where(:reply_to => nil) }
scope :thread, -> (id) { where("id = ? OR reply_to = ?", id, id) }
scope :readable_for, -> (user) {
joins(:message_recipients).where('private = ? OR message_recipients.user_id = ?', false, user.try(&:id)).distinct
}
validates_presence_of :message_recipients, :subject, :body
validates_length_of :subject, :in => 1..255