Sha256: c14dcff4b93e885a4646f1c0cf3f66a483f82e6a506e69019acb0d5d32d1b902

Contents?: true

Size: 1.17 KB

Versions: 10

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true
module Thredded
  class UserDetail < ActiveRecord::Base
    include Thredded::ModerationState

    belongs_to :user, class_name: Thredded.user_class, inverse_of: :thredded_user_detail
    validates :user_id, presence: true, uniqueness: true

    has_many :topics, class_name: 'Thredded::Topic', foreign_key: :user_id, primary_key: :user_id
    has_many :private_topics, class_name: 'Thredded::PrivateTopic', foreign_key: :user_id, primary_key: :user_id
    has_many :posts, class_name: 'Thredded::Post', foreign_key: :user_id, primary_key: :user_id
    has_many :private_posts, class_name: 'Thredded::PrivatePost', foreign_key: :user_id, primary_key: :user_id
    has_many :messageboard_users, class_name: 'Thredded::MessageboardUser', foreign_key: :thredded_user_detail_id,
                                  inverse_of: :user_detail, dependent: :destroy

    scope :recently_active, -> { where(arel_table[:last_seen_at].gt(Thredded.active_user_threshold.ago)) }

    before_save :set_moderation_state_changed_at

    private

    def set_moderation_state_changed_at
      self.moderation_state_changed_at = Time.current if moderation_state_changed?
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
thredded-0.12.1 app/models/thredded/user_detail.rb
thredded-0.12.0 app/models/thredded/user_detail.rb
thredded-0.11.1 app/models/thredded/user_detail.rb
thredded-0.11.0 app/models/thredded/user_detail.rb
thredded-0.10.1 app/models/thredded/user_detail.rb
thredded-0.10.0 app/models/thredded/user_detail.rb
thredded-0.9.4 app/models/thredded/user_detail.rb
thredded-0.9.3 app/models/thredded/user_detail.rb
thredded-0.9.2 app/models/thredded/user_detail.rb
thredded-0.9.1 app/models/thredded/user_detail.rb