<commit_before>class Message < ApplicationRecord
  include Rails.application.routes.url_helpers

  mount_uploader :image, PictureUploader
  before_create :set_conversation_start_message

  has_many :replies, class_name: 'Message', foreign_key: :in_reply_to_message_id
  has_many :conversation, class_name: 'Message', foreign_key: :conversation_start_message_id

  validates_presence_of :subject
  validates_presence_of :message

  belongs_to :subject_object, polymorphic: true
  belongs_to :from_user, class_name: 'User'
  belongs_to :to_user, class_name: 'User'
  belongs_to :in_reply_to_message, class_name: 'Message'
  belongs_to :conversation_start_message, class_name: 'Message'
  belongs_to :reminder

  scope :order_by_creation_date, -> {order(:created_at)}
  scope :order_by_reverse_creation_date, -> {order(created_at: :desc)}
  scope :conversation_starters, -> {where("messages.conversation_start_message_id IS NULL or messages.conversation_start_message_id = messages.id")}
  scope :thread_can_be_accessed_by_user, ->(user) { where("messages.from_user_id = ? OR messages.to_user_id = ? OR (SELECT COUNT(messages_a.id) FROM messages AS messages_a WHERE messages_a.id = messages.conversation_start_message_id AND (messages_a.from_user_id = ? OR messages_a.to_user_id = ?)) = 1", user.id,user.id,user.id,user.id)}
  scope :not_qkunst_private, -> {where(qkunst_private: [nil, false])}
  scope :for, ->(subject_object) { where(subject_object: subject_object )}
  scope :sent_at_date, ->(date) {where("messages.created_at > ? AND messages.created_at < ?", date.to_time.beginning_of_day, date.to_time.end_of_day)}

  after_create :send_notification

  def from_user_name
    from_user ? from_user.name.to_s : ""
  end

  def from_user?(user)
    from_user == user
  end

  def read(user=nil)
    !actioned_upon_by_qkunst_admin_at.nil? or (user and from_user?(user)) or (user and !user.qkunst? and from_user and from_user.qkunst?)
  end
<commit_msg>+00:00 wasn't working (travis' timezone)<commit_after>class Message < ApplicationRecord
  include Rails.application.routes.url_helpers

  mount_uploader :image, PictureUploader
  before_create :set_conversation_start_message

  has_many :replies, class_name: 'Message', foreign_key: :in_reply_to_message_id
  has_many :conversation, class_name: 'Message', foreign_key: :conversation_start_message_id

  validates_presence_of :subject
  validates_presence_of :message

  belongs_to :subject_object, polymorphic: true
  belongs_to :from_user, class_name: 'User'
  belongs_to :to_user, class_name: 'User'
  belongs_to :in_reply_to_message, class_name: 'Message'
  belongs_to :conversation_start_message, class_name: 'Message'
  belongs_to :reminder

  scope :order_by_creation_date, -> {order(:created_at)}
  scope :order_by_reverse_creation_date, -> {order(created_at: :desc)}
  scope :conversation_starters, -> {where("messages.conversation_start_message_id IS NULL or messages.conversation_start_message_id = messages.id")}
  scope :thread_can_be_accessed_by_user, ->(user) { where("messages.from_user_id = ? OR messages.to_user_id = ? OR (SELECT COUNT(messages_a.id) FROM messages AS messages_a WHERE messages_a.id = messages.conversation_start_message_id AND (messages_a.from_user_id = ? OR messages_a.to_user_id = ?)) = 1", user.id,user.id,user.id,user.id)}
  scope :not_qkunst_private, -> {where(qkunst_private: [nil, false])}
  scope :for, ->(subject_object) { where(subject_object: subject_object )}
  scope :sent_at_date, ->(date) {where("messages.created_at >= ? AND messages.created_at <= ?", date.to_time.beginning_of_day, date.to_time.end_of_day)}

  after_create :send_notification

  def from_user_name
    from_user ? from_user.name.to_s : ""
  end

  def from_user?(user)
    from_user == user
  end

  def read(user=nil)
    !actioned_upon_by_qkunst_admin_at.nil? or (user and from_user?(user)) or (user and !user.qkunst? and from_user and from_user.qkunst?)
  end

{'fraction_non_alphanumeric': 0.10628019323671498, 'fraction_numerical': 0.0015255530129672007, 'mean_word_length': 6.271719038817006, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2185773', 'n_tokens_mistral': 1395, 'n_tokens_neox': 1389, 'n_words': 266}