2018-07-13 06:22:02 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-28 09:17:42 -04:00
|
|
|
class UserStatus < ApplicationRecord
|
2018-07-13 06:22:02 -04:00
|
|
|
include CacheMarkdownField
|
|
|
|
|
2018-07-16 12:18:52 -04:00
|
|
|
self.primary_key = :user_id
|
|
|
|
|
2019-08-31 15:57:00 -04:00
|
|
|
DEFAULT_EMOJI = 'speech_balloon'
|
2018-07-16 12:18:52 -04:00
|
|
|
|
2021-02-12 13:08:59 -05:00
|
|
|
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-07-13 06:22:02 -04:00
|
|
|
belongs_to :user
|
|
|
|
|
2020-10-29 14:09:11 -04:00
|
|
|
enum availability: { not_set: 0, busy: 1 }
|
|
|
|
|
2018-07-13 06:22:02 -04:00
|
|
|
validates :user, presence: true
|
2021-10-19 17:12:08 -04:00
|
|
|
validates :emoji, 'gitlab/emoji_name': true
|
2018-07-13 06:22:02 -04:00
|
|
|
validates :message, length: { maximum: 100 }, allow_blank: true
|
|
|
|
|
2021-02-12 13:08:59 -05:00
|
|
|
scope :scheduled_for_cleanup, -> { where(arel_table[:clear_status_at].lteq(Time.current)) }
|
|
|
|
|
2018-07-13 11:52:31 -04:00
|
|
|
cache_markdown_field :message, pipeline: :emoji
|
2021-02-12 13:08:59 -05:00
|
|
|
|
|
|
|
def clear_status_after=(value)
|
|
|
|
self.clear_status_at = CLEAR_STATUS_QUICK_OPTIONS[value]&.from_now
|
|
|
|
end
|
2018-07-13 06:22:02 -04:00
|
|
|
end
|
2021-11-16 01:12:13 -05:00
|
|
|
|
|
|
|
UserStatus.prepend_mod_with('UserStatus')
|