2021-11-25 14:07:38 +02: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-25 01:34:14 +02: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 14:07:38 +02:00
|
|
|
def self.refresh!
|
2022-02-25 01:34:14 +02:00
|
|
|
[links, tags, statuses].each(&:refresh)
|
2021-11-25 14:07:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.request_review!
|
2022-02-25 01:34:14 +02:00
|
|
|
return unless enabled?
|
|
|
|
|
|
|
|
links_requiring_review = links.request_review
|
|
|
|
tags_requiring_review = tags.request_review
|
|
|
|
statuses_requiring_review = statuses.request_review
|
|
|
|
|
|
|
|
return if links_requiring_review.empty? && tags_requiring_review.empty? && statuses_requiring_review.empty?
|
|
|
|
|
|
|
|
User.staff.includes(:account).find_each do |user|
|
|
|
|
AdminMailer.new_trends(user.account, links_requiring_review, tags_requiring_review, statuses_requiring_review).deliver_later! if user.allows_trends_review_emails?
|
|
|
|
end
|
2021-11-25 14:07:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.enabled?
|
|
|
|
Setting.trends
|
|
|
|
end
|
2022-02-25 01:34:14 +02:00
|
|
|
|
|
|
|
def self.available_locales
|
|
|
|
@available_locales ||= I18n.available_locales.map { |locale| locale.to_s.split(/[_-]/).first }.uniq
|
|
|
|
end
|
2021-11-25 14:07:38 +02:00
|
|
|
end
|