Add emoji reactions to trends
This commit is contained in:
parent
bc48000dce
commit
e6fcf1543b
8 changed files with 33 additions and 14 deletions
|
@ -28,6 +28,8 @@ class EmojiReaction < ApplicationRecord
|
|||
|
||||
has_one :notification, as: :activity, dependent: :destroy
|
||||
|
||||
validate :status_emoji_reactions_count
|
||||
|
||||
after_create :refresh_cache
|
||||
after_destroy :refresh_cache
|
||||
after_destroy :invalidate_cleanup_info
|
||||
|
@ -50,4 +52,10 @@ class EmojiReaction < ApplicationRecord
|
|||
query = query.where(arel_table[:id].gt(since_id)) if since_id.present?
|
||||
query
|
||||
end
|
||||
|
||||
def status_emoji_reactions_count
|
||||
if status && account && status.emoji_reactions.where(account: account).count >= EMOJI_REACTION_PER_ACCOUNT_LIMIT
|
||||
raise Mastodon::ValidationError, I18n.t('reactions.errors.limit_reached')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -339,8 +339,8 @@ class Status < ApplicationRecord
|
|||
end
|
||||
|
||||
def refresh_emoji_reactions_grouped_by_name!
|
||||
generate_emoji_reactions_grouped_by_name.tap do |emoji_reactions|
|
||||
update_status_stat!(emoji_reactions: emoji_reactions)
|
||||
generate_emoji_reactions_grouped_by_name.tap do |emoji_reactions_json|
|
||||
update_status_stat!(emoji_reactions: emoji_reactions_json, emoji_reactions_count: emoji_reactions.size)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,14 +4,15 @@
|
|||
#
|
||||
# Table name: status_stats
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# status_id :bigint(8) not null
|
||||
# replies_count :bigint(8) default(0), not null
|
||||
# reblogs_count :bigint(8) default(0), not null
|
||||
# favourites_count :bigint(8) default(0), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# emoji_reactions :string
|
||||
# id :bigint(8) not null, primary key
|
||||
# status_id :bigint(8) not null
|
||||
# replies_count :bigint(8) default(0), not null
|
||||
# reblogs_count :bigint(8) default(0), not null
|
||||
# favourites_count :bigint(8) default(0), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# emoji_reactions :string
|
||||
# emoji_reactions_count :integer default(0), not null
|
||||
#
|
||||
|
||||
class StatusStat < ApplicationRecord
|
||||
|
@ -35,6 +36,10 @@ class StatusStat < ApplicationRecord
|
|||
attributes['emoji_reactions'] || ''
|
||||
end
|
||||
|
||||
def emoji_reactions_count
|
||||
[attributes['emoji_reactions_count'], 0].max
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def reset_parent_cache
|
||||
|
|
|
@ -97,7 +97,7 @@ class Trends::Statuses < Trends::Base
|
|||
def calculate_scores(statuses, at_time)
|
||||
items = statuses.map do |status|
|
||||
expected = 1.0
|
||||
observed = (status.reblogs_count + status.favourites_count).to_f
|
||||
observed = (status.reblogs_count + status.favourites_count + status.emoji_reactions_count * 0.3).to_f
|
||||
|
||||
score = if expected > observed || observed < options[:threshold]
|
||||
0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue