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

46 lines
1 KiB
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,
2022-08-27 11:52:29 +05:30
'3_hours' => 3.hours,
'8_hours' => 8.hours,
'1_day' => 1.day,
'3_days' => 3.days,
'7_days' => 7.days,
'30_days' => 30.days
2021-03-11 19:13:27 +05:30
}.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
2021-12-11 22:18:48 +05:30
validates :emoji, 'gitlab/emoji_name': true
2018-11-18 11:00:15 +05:30
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
2022-10-11 01:57:18 +05:30
def clear_status_after
clear_status_at
end
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
2022-08-27 11:52:29 +05:30
def customized?
message.present? || emoji != UserStatus::DEFAULT_EMOJI
end
2018-11-18 11:00:15 +05:30
end
2021-12-11 22:18:48 +05:30
UserStatus.prepend_mod_with('UserStatus')