Welcome to mirror list, hosted at ThFree Co, Russian Federation.

user_status.rb « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1c8634e47c3ba9d2661171c7d78fe203727fd362 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

class UserStatus < ApplicationRecord
  include CacheMarkdownField

  self.primary_key = :user_id

  DEFAULT_EMOJI = 'speech_balloon'

  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

  belongs_to :user

  enum availability: { not_set: 0, busy: 1 }

  validates :user, presence: true
  validates :emoji, inclusion: { in: Gitlab::Emoji.emojis_names }
  validates :message, length: { maximum: 100 }, allow_blank: true

  scope :scheduled_for_cleanup, -> { where(arel_table[:clear_status_at].lteq(Time.current)) }

  cache_markdown_field :message, pipeline: :emoji

  def clear_status_after=(value)
    self.clear_status_at = CLEAR_STATUS_QUICK_OPTIONS[value]&.from_now
  end
end