2021-11-25 12:07:38 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Trends
|
|
|
|
def self.table_name_prefix
|
|
|
|
'trends_'
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.links
|
|
|
|
@links ||= Trends::Links.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.tags
|
|
|
|
@tags ||= Trends::Tags.new
|
|
|
|
end
|
|
|
|
|
2022-02-24 23:34:14 +00:00
|
|
|
def self.statuses
|
|
|
|
@statuses ||= Trends::Statuses.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.register!(status)
|
|
|
|
[links, tags, statuses].each { |trend_type| trend_type.register(status) }
|
|
|
|
end
|
|
|
|
|
2021-11-25 12:07:38 +00:00
|
|
|
def self.refresh!
|
2022-02-24 23:34:14 +00:00
|
|
|
[links, tags, statuses].each(&:refresh)
|
2021-11-25 12:07:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.request_review!
|
2022-10-08 14:45:40 +00:00
|
|
|
return if skip_review? || !enabled?
|
2022-02-24 23:34:14 +00:00
|
|
|
|
|
|
|
links_requiring_review = links.request_review
|
|
|
|
tags_requiring_review = tags.request_review
|
|
|
|
statuses_requiring_review = statuses.request_review
|
|
|
|
|
2022-07-05 00:41:40 +00:00
|
|
|
User.those_who_can(:manage_taxonomies).includes(:account).find_each do |user|
|
2022-05-13 20:57:47 +00:00
|
|
|
links = user.allows_trending_links_review_emails? ? links_requiring_review : []
|
|
|
|
tags = user.allows_trending_tags_review_emails? ? tags_requiring_review : []
|
2022-02-26 09:30:45 +00:00
|
|
|
statuses = user.allows_trending_statuses_review_emails? ? statuses_requiring_review : []
|
|
|
|
next if links.empty? && tags.empty? && statuses.empty?
|
|
|
|
|
2023-07-12 13:38:35 +00:00
|
|
|
AdminMailer.with(recipient: user.account).new_trends(links, tags, statuses).deliver_later! if user.allows_trends_review_emails?
|
2022-02-24 23:34:14 +00:00
|
|
|
end
|
2021-11-25 12:07:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.enabled?
|
|
|
|
Setting.trends
|
|
|
|
end
|
2022-02-24 23:34:14 +00:00
|
|
|
|
2022-10-10 06:03:19 +00:00
|
|
|
def self.skip_review?
|
2022-10-08 14:45:40 +00:00
|
|
|
Setting.trendable_by_default
|
|
|
|
end
|
|
|
|
|
2022-02-24 23:34:14 +00:00
|
|
|
def self.available_locales
|
|
|
|
@available_locales ||= I18n.available_locales.map { |locale| locale.to_s.split(/[_-]/).first }.uniq
|
|
|
|
end
|
2021-11-25 12:07:38 +00:00
|
|
|
end
|