debian-mirror-gitlab/app/models/user_status.rb

36 lines
904 B
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2019-07-07 11:18:12 +05:30
class UserStatus < ApplicationRecord
2018-11-18 11:00:15 +05:30
include CacheMarkdownField
self.primary_key = :user_id
2019-12-04 20:38:33 +05:30
DEFAULT_EMOJI = 'speech_balloon'
2018-11-18 11:00:15 +05:30
2021-03-11 19:13:27 +05:30
CLEAR_STATUS_QUICK_OPTIONS = {
'30_minutes' => 30.minutes,
'3_hours' => 3.hours,
'8_hours' => 8.hours,
'1_day' => 1.day,
'3_days' => 3.days,
'7_days' => 7.days,
'30_days' => 30.days
}.freeze
2018-11-18 11:00:15 +05:30
belongs_to :user
2021-01-29 00:20:46 +05:30
enum availability: { not_set: 0, busy: 1 }
2018-11-18 11:00:15 +05:30
validates :user, presence: true
validates :emoji, inclusion: { in: Gitlab::Emoji.emojis_names }
validates :message, length: { maximum: 100 }, allow_blank: true
2021-03-11 19:13:27 +05:30
scope :scheduled_for_cleanup, -> { where(arel_table[:clear_status_at].lteq(Time.current)) }
2018-11-18 11:00:15 +05:30
cache_markdown_field :message, pipeline: :emoji
2021-03-11 19:13:27 +05:30
def clear_status_after=(value)
self.clear_status_at = CLEAR_STATUS_QUICK_OPTIONS[value]&.from_now
end
2018-11-18 11:00:15 +05:30
end