Merge remote-tracking branch 'tootsuite/master' into glitchsoc/master

This commit is contained in:
Jenkins
2018-02-19 15:17:14 +00:00
25 changed files with 193 additions and 60 deletions

View File

@@ -16,12 +16,16 @@ class AccountDomainBlock < ApplicationRecord
belongs_to :account
validates :domain, presence: true, uniqueness: { scope: :account_id }
after_create :remove_blocking_cache
after_destroy :remove_blocking_cache
after_commit :remove_blocking_cache
after_commit :remove_relationship_cache
private
def remove_blocking_cache
Rails.cache.delete("exclude_domains_for:#{account_id}")
end
def remove_relationship_cache
Rails.cache.delete_matched("relationship:#{account_id}:*")
end
end

View File

@@ -12,14 +12,14 @@
class Block < ApplicationRecord
include Paginable
include RelationshipCacheable
belongs_to :account
belongs_to :target_account, class_name: 'Account'
validates :account_id, uniqueness: { scope: :target_account_id }
after_create :remove_blocking_cache
after_destroy :remove_blocking_cache
after_commit :remove_blocking_cache
private

View File

@@ -7,9 +7,15 @@ module AccountAvatar
class_methods do
def avatar_styles(file)
styles = { original: '120x120#' }
styles[:static] = { format: 'png', convert_options: '-coalesce' } if file.content_type == 'image/gif'
styles = {}
geometry = Paperclip::Geometry.from_file(file)
styles[:original] = '120x120#' if geometry.width != geometry.height || geometry.width > 120 || geometry.height > 120
styles[:static] = { format: 'png', convert_options: '-coalesce' } if file.content_type == 'image/gif'
styles
rescue Paperclip::Errors::NotIdentifiedByImageMagickError
{}
end
private :avatar_styles
@@ -17,7 +23,7 @@ module AccountAvatar
included do
# Avatar upload
has_attached_file :avatar, styles: ->(f) { avatar_styles(f) }, convert_options: { all: '-quality 80 -strip' }
has_attached_file :avatar, styles: ->(f) { avatar_styles(f) }, convert_options: { all: '-strip' }
validates_attachment_content_type :avatar, content_type: IMAGE_MIME_TYPES
validates_attachment_size :avatar, less_than: 2.megabytes
end

View File

@@ -7,9 +7,15 @@ module AccountHeader
class_methods do
def header_styles(file)
styles = { original: '700x335#' }
styles[:static] = { format: 'png', convert_options: '-coalesce' } if file.content_type == 'image/gif'
styles = {}
geometry = Paperclip::Geometry.from_file(file)
styles[:original] = '700x335#' unless geometry.width == 700 && geometry.height == 335
styles[:static] = { format: 'png', convert_options: '-coalesce' } if file.content_type == 'image/gif'
styles
rescue Paperclip::Errors::NotIdentifiedByImageMagickError
{}
end
private :header_styles
@@ -17,7 +23,7 @@ module AccountHeader
included do
# Header upload
has_attached_file :header, styles: ->(f) { header_styles(f) }, convert_options: { all: '-quality 80 -strip' }
has_attached_file :header, styles: ->(f) { header_styles(f) }, convert_options: { all: '-strip' }
validates_attachment_content_type :header, content_type: IMAGE_MIME_TYPES
validates_attachment_size :header, less_than: 2.megabytes
end

View File

@@ -0,0 +1,16 @@
# frozen_string_literal: true
module RelationshipCacheable
extend ActiveSupport::Concern
included do
after_commit :remove_relationship_cache
end
private
def remove_relationship_cache
Rails.cache.delete("relationship:#{account_id}:#{target_account_id}")
Rails.cache.delete("relationship:#{target_account_id}:#{account_id}")
end
end

View File

@@ -13,6 +13,7 @@
class Follow < ApplicationRecord
include Paginable
include RelationshipCacheable
belongs_to :account, counter_cache: :following_count

View File

@@ -13,6 +13,7 @@
class FollowRequest < ApplicationRecord
include Paginable
include RelationshipCacheable
belongs_to :account
belongs_to :target_account, class_name: 'Account'

View File

@@ -13,14 +13,14 @@
class Mute < ApplicationRecord
include Paginable
include RelationshipCacheable
belongs_to :account
belongs_to :target_account, class_name: 'Account'
validates :account_id, uniqueness: { scope: :target_account_id }
after_create :remove_blocking_cache
after_destroy :remove_blocking_cache
after_commit :remove_blocking_cache
private

View File

@@ -83,6 +83,8 @@ class Status < ApplicationRecord
delegate :domain, to: :account, prefix: true
REAL_TIME_WINDOW = 6.hours
def searchable_by(preloaded = nil)
ids = [account_id]
@@ -111,6 +113,10 @@ class Status < ApplicationRecord
!reblog_of_id.nil?
end
def within_realtime_window?
created_at >= REAL_TIME_WINDOW.ago
end
def verb
if destroyed?
:delete