fedibird-fe/app/models/emoji_reaction.rb

57 lines
1.3 KiB
Ruby
Raw Normal View History

2021-05-19 05:58:27 +00:00
# frozen_string_literal: true
# == Schema Information
#
# Table name: emoji_reactions
#
# id :bigint(8) not null, primary key
# account_id :bigint(8) not null
# status_id :bigint(8) not null
# name :string default(""), not null
# custom_emoji_id :bigint(8)
# created_at :datetime not null
# updated_at :datetime not null
# uri :string
#
class EmojiReaction < ApplicationRecord
include Paginable
after_commit :queue_publish
2021-06-28 22:15:41 +00:00
after_commit :refresh_status
2021-05-19 05:58:27 +00:00
belongs_to :account
2021-07-16 06:38:50 +00:00
belongs_to :status, -> { unscope(where: :expired_at) }, inverse_of: :emoji_reactions
2021-05-19 05:58:27 +00:00
belongs_to :custom_emoji, optional: true
has_one :notification, as: :activity, dependent: :destroy
2022-04-13 01:33:23 +00:00
scope :local, -> { where(uri: nil) }
scope :remote, -> { where.not(uri: nil) }
2021-05-19 05:58:27 +00:00
validates :name, presence: true
validates_with EmojiReactionValidator
before_validation do
self.status = status.reblog if status&.reblog?
end
def sign?
true
end
2022-04-13 01:33:23 +00:00
def object_type
:emoji_reaction
end
2021-05-19 05:58:27 +00:00
private
def queue_publish
PublishEmojiReactionWorker.perform_async(status_id, account_id, name) unless status.destroyed? || account.silenced?
2021-05-19 05:58:27 +00:00
end
2021-06-28 22:15:41 +00:00
def refresh_status
status.refresh_grouped_emoji_reactions! unless status.destroyed?
end
2021-05-19 05:58:27 +00:00
end