Fix ruby lint
This commit is contained in:
parent
df6de7daf5
commit
f157a509d6
6 changed files with 52 additions and 65 deletions
|
@ -10,35 +10,34 @@
|
||||||
# name :string default(""), not null
|
# name :string default(""), not null
|
||||||
# custom_emoji_id :bigint(8)
|
# custom_emoji_id :bigint(8)
|
||||||
# uri :string
|
# uri :string
|
||||||
# created_at :datetime
|
# created_at :datetime not null
|
||||||
# updated_at :datetime
|
# updated_at :datetime not null
|
||||||
#
|
#
|
||||||
|
|
||||||
class EmojiReaction < ApplicationRecord
|
class EmojiReaction < ApplicationRecord
|
||||||
include Paginable
|
include Paginable
|
||||||
|
|
||||||
update_index('statuses', :status)
|
update_index('statuses', :status)
|
||||||
|
|
||||||
belongs_to :account, inverse_of: :emoji_reactions
|
belongs_to :account, inverse_of: :emoji_reactions
|
||||||
belongs_to :status, inverse_of: :emoji_reactions
|
belongs_to :status, inverse_of: :emoji_reactions
|
||||||
belongs_to :custom_emojis, optional: true
|
belongs_to :custom_emojis, optional: true
|
||||||
|
|
||||||
has_one :notification, as: :activity, dependent: :destroy
|
has_one :notification, as: :activity, dependent: :destroy
|
||||||
|
|
||||||
validates :status_id, uniqueness: { scope: :account_id }
|
after_create :refresh_cache
|
||||||
|
after_destroy :refresh_cache
|
||||||
before_validation do
|
after_destroy :invalidate_cleanup_info
|
||||||
self.status = status.reblog if status&.reblog?
|
|
||||||
end
|
private
|
||||||
|
|
||||||
after_destroy :invalidate_cleanup_info
|
def refresh_cache
|
||||||
|
status&.refresh_emoji_reactions_grouped_by_name!
|
||||||
private
|
|
||||||
|
|
||||||
def invalidate_cleanup_info
|
|
||||||
return unless status&.account_id == account_id && account.local?
|
|
||||||
|
|
||||||
account.statuses_cleanup_policy&.invalidate_last_inspected(status, :unfav)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def invalidate_cleanup_info
|
||||||
|
return unless status&.account_id == account_id && account.local?
|
||||||
|
|
||||||
|
account.statuses_cleanup_policy&.invalidate_last_inspected(status, :unfav)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -9,9 +9,9 @@
|
||||||
# replies_count :bigint(8) default(0), not null
|
# replies_count :bigint(8) default(0), not null
|
||||||
# reblogs_count :bigint(8) default(0), not null
|
# reblogs_count :bigint(8) default(0), not null
|
||||||
# favourites_count :bigint(8) default(0), not null
|
# favourites_count :bigint(8) default(0), not null
|
||||||
# emoji_reactions :string
|
|
||||||
# created_at :datetime not null
|
# created_at :datetime not null
|
||||||
# updated_at :datetime not null
|
# updated_at :datetime not null
|
||||||
|
# emoji_reactions :string
|
||||||
#
|
#
|
||||||
|
|
||||||
class StatusStat < ApplicationRecord
|
class StatusStat < ApplicationRecord
|
||||||
|
|
|
@ -1,31 +1,23 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# name: string,
|
|
||||||
#count: number,
|
|
||||||
#account_ids: Array<string>,
|
|
||||||
#me: boolean,
|
|
||||||
#url: string,
|
|
||||||
#domain: string
|
|
||||||
|
|
||||||
class REST::EmojiReactionsGroupedByNameSerializer < ActiveModel::Serializer
|
class REST::EmojiReactionsGroupedByNameSerializer < ActiveModel::Serializer
|
||||||
attributes :name, :count
|
attributes :name, :count
|
||||||
|
|
||||||
attribute :me, if: :current_user?
|
|
||||||
attribute :url, if: :custom_emoji?
|
|
||||||
attribute :static_url, if: :custom_emoji?
|
|
||||||
attribute :domain, if: :custom_emoji?
|
|
||||||
attribute :account_ids, if: :has_account_ids?
|
|
||||||
|
|
||||||
def current_user?
|
attribute :me, if: :current_user?
|
||||||
!current_user.nil?
|
attribute :url, if: :custom_emoji?
|
||||||
end
|
attribute :static_url, if: :custom_emoji?
|
||||||
|
attribute :domain, if: :custom_emoji?
|
||||||
|
attribute :account_ids, if: :account_ids?
|
||||||
|
|
||||||
def custom_emoji?
|
def current_user?
|
||||||
object.respond_to?(:custom_emoji)
|
!current_user.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_account_ids?
|
def custom_emoji?
|
||||||
object.respond_to?(:account_ids)
|
object.respond_to?(:custom_emoji)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def account_ids?
|
||||||
|
object.respond_to?(:account_ids)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
class CreateEmojiReactions < ActiveRecord::Migration[6.1]
|
class CreateEmojiReactions < ActiveRecord::Migration[6.1]
|
||||||
def change
|
def change
|
||||||
create_table :emoji_reactions do |t|
|
create_table :emoji_reactions do |t|
|
||||||
|
t.belongs_to :account, null: false, foreign_key: { on_delete: :cascade }
|
||||||
t.belongs_to :account, null: false, foreign_key: { on_delete: :cascade }, index: false
|
|
||||||
t.belongs_to :status, null: false, foreign_key: { on_delete: :cascade }
|
t.belongs_to :status, null: false, foreign_key: { on_delete: :cascade }
|
||||||
t.string :name, null: false, default: ''
|
t.string :name, null: false, default: ''
|
||||||
t.belongs_to :custom_emoji, foreign_key: { on_delete: :cascade }, index: false
|
t.belongs_to :custom_emoji, foreign_key: { on_delete: :cascade }
|
||||||
t.string :uri
|
t.string :uri
|
||||||
|
t.datetime :created_at, null: false
|
||||||
|
t.datetime :updated_at, null: false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
class AddCreateAtToEmojiReactions < ActiveRecord::Migration[6.1]
|
|
||||||
def change
|
|
||||||
add_column :emoji_reactions, :created_at, :timestamp
|
|
||||||
add_column :emoji_reactions, :updated_at, :timestamp
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -417,8 +417,10 @@ ActiveRecord::Schema.define(version: 2023_02_23_102416) do
|
||||||
t.string "name", default: "", null: false
|
t.string "name", default: "", null: false
|
||||||
t.bigint "custom_emoji_id"
|
t.bigint "custom_emoji_id"
|
||||||
t.string "uri"
|
t.string "uri"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at", null: false
|
||||||
|
t.index ["account_id"], name: "index_emoji_reactions_on_account_id"
|
||||||
|
t.index ["custom_emoji_id"], name: "index_emoji_reactions_on_custom_emoji_id"
|
||||||
t.index ["status_id"], name: "index_emoji_reactions_on_status_id"
|
t.index ["status_id"], name: "index_emoji_reactions_on_status_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue