Add trending links (#16917)
* Add trending links * Add overriding specific links trendability * Add link type to preview cards and only trend articles Change trends review notifications from being sent every 5 minutes to being sent every 2 hours Change threshold from 5 unique accounts to 15 unique accounts * Fix tests
This commit is contained in:
parent
46e62fc4b3
commit
6e50134a42
97 changed files with 2071 additions and 722 deletions
|
@ -24,6 +24,11 @@
|
|||
# embed_url :string default(""), not null
|
||||
# image_storage_schema_version :integer
|
||||
# blurhash :string
|
||||
# language :string
|
||||
# max_score :float
|
||||
# max_score_at :datetime
|
||||
# trendable :boolean
|
||||
# link_type :integer
|
||||
#
|
||||
|
||||
class PreviewCard < ApplicationRecord
|
||||
|
@ -40,6 +45,7 @@ class PreviewCard < ApplicationRecord
|
|||
self.inheritance_column = false
|
||||
|
||||
enum type: [:link, :photo, :video, :rich]
|
||||
enum link_type: [:unknown, :article]
|
||||
|
||||
has_and_belongs_to_many :statuses
|
||||
|
||||
|
@ -54,6 +60,32 @@ class PreviewCard < ApplicationRecord
|
|||
|
||||
before_save :extract_dimensions, if: :link?
|
||||
|
||||
def appropriate_for_trends?
|
||||
link? && article? && title.present? && description.present? && image.present? && provider_name.present?
|
||||
end
|
||||
|
||||
def domain
|
||||
@domain ||= Addressable::URI.parse(url).normalized_host
|
||||
end
|
||||
|
||||
def provider
|
||||
@provider ||= PreviewCardProvider.matching_domain(domain)
|
||||
end
|
||||
|
||||
def trendable?
|
||||
if attributes['trendable'].nil?
|
||||
provider&.trendable?
|
||||
else
|
||||
attributes['trendable']
|
||||
end
|
||||
end
|
||||
|
||||
def requires_review_notification?
|
||||
attributes['trendable'].nil? && (provider.nil? || provider.requires_review_notification?)
|
||||
end
|
||||
|
||||
attr_writer :provider
|
||||
|
||||
def local?
|
||||
false
|
||||
end
|
||||
|
@ -69,11 +101,14 @@ class PreviewCard < ApplicationRecord
|
|||
save!
|
||||
end
|
||||
|
||||
def history
|
||||
@history ||= Trends::History.new('links', id)
|
||||
end
|
||||
|
||||
class << self
|
||||
private
|
||||
|
||||
# rubocop:disable Naming/MethodParameterName
|
||||
def image_styles(f)
|
||||
def image_styles(file)
|
||||
styles = {
|
||||
original: {
|
||||
geometry: '400x400>',
|
||||
|
@ -83,10 +118,9 @@ class PreviewCard < ApplicationRecord
|
|||
},
|
||||
}
|
||||
|
||||
styles[:original][:format] = 'jpg' if f.instance.image_content_type == 'image/gif'
|
||||
styles[:original][:format] = 'jpg' if file.instance.image_content_type == 'image/gif'
|
||||
styles
|
||||
end
|
||||
# rubocop:enable Naming/MethodParameterName
|
||||
end
|
||||
|
||||
private
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue