discourse/app/models/user_status.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
955 B
Ruby
Raw Normal View History

2022-05-27 05:15:14 -04:00
# frozen_string_literal: true
class UserStatus < ActiveRecord::Base
MAX_DESCRIPTION_LENGTH = 100
2022-05-27 05:15:14 -04:00
belongs_to :user
validate :emoji_exists
validates :description, length: { maximum: MAX_DESCRIPTION_LENGTH }
2022-05-27 05:15:14 -04:00
validate :ends_at_greater_than_set_at,
if: Proc.new { |t| t.will_save_change_to_set_at? || t.will_save_change_to_ends_at? }
def expired?
ends_at && ends_at < Time.zone.now
end
def emoji_exists
errors.add(:emoji, :invalid) if emoji && !Emoji.exists?(emoji)
end
2022-05-27 05:15:14 -04:00
def ends_at_greater_than_set_at
if ends_at && set_at > ends_at
errors.add(:ends_at, I18n.t("user_status.errors.ends_at_should_be_greater_than_set_at"))
end
end
end
# == Schema Information
#
# Table name: user_statuses
#
# user_id :integer not null, primary key
2022-06-22 10:15:33 -04:00
# emoji :string not null
2022-05-27 05:15:14 -04:00
# description :string not null
# set_at :datetime not null
# ends_at :datetime
#