user.rb 1.01 KB
Newer Older
1 2
# frozen_string_literal: true

Eugen Rochko's avatar
Eugen Rochko committed
3
class User < ApplicationRecord
Eugen Rochko's avatar
Eugen Rochko committed
4
  devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable
5

Eugen Rochko's avatar
Eugen Rochko committed
6
  belongs_to :account, inverse_of: :user
7
  accepts_nested_attributes_for :account
8

Eugen Rochko's avatar
Eugen Rochko committed
9
  validates :account, presence: true
Eugen Rochko's avatar
Eugen Rochko committed
10
  validates :locale, inclusion: I18n.available_locales.map(&:to_s), unless: 'locale.nil?'
11

12
  scope :prolific, -> { joins('inner join statuses on statuses.account_id = users.account_id').select('users.*, count(statuses.id) as statuses_count').group('users.id').order('statuses_count desc') }
Eugen Rochko's avatar
Eugen Rochko committed
13
  scope :recent,   -> { order('id desc') }
14
  scope :admins,   -> { where(admin: true) }
15 16

  has_settings do |s|
17
    s.key :notification_emails, defaults: { follow: false, reblog: false, favourite: false, mention: false }
18
    s.key :interactions, defaults: { must_be_follower: false, must_be_following: false }
19
  end
20 21 22 23

  def send_devise_notification(notification, *args)
    devise_mailer.send(notification, self, *args).deliver_later
  end
Eugen Rochko's avatar
Eugen Rochko committed
24
end