From d0ba77047e539b7ae102296d096fcfd668a2ec92 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 1 Nov 2022 13:01:39 +0100 Subject: Change max. thumbnail dimensions to 640x360px (360p) (#19619) --- app/models/media_attachment.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index a24fb857b..4a1948380 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -72,7 +72,7 @@ class MediaAttachment < ApplicationRecord }.freeze, small: { - pixels: 160_000, # 400x400px + pixels: 230_400, # 640x360px file_geometry_parser: FastGeometryParser, blurhash: BLURHASH_OPTIONS, }.freeze, -- cgit From 15bae3e0e467a19582a25e0482cd26c1c82fd7f9 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 1 Nov 2022 15:27:58 +0100 Subject: Change post-processing to be deferred only for large media types (#19617) --- app/controllers/api/v2/media_controller.rb | 2 +- app/models/media_attachment.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'app/models') diff --git a/app/controllers/api/v2/media_controller.rb b/app/controllers/api/v2/media_controller.rb index 0c1baf01d..288f847f1 100644 --- a/app/controllers/api/v2/media_controller.rb +++ b/app/controllers/api/v2/media_controller.rb @@ -3,7 +3,7 @@ class Api::V2::MediaController < Api::V1::MediaController def create @media_attachment = current_account.media_attachments.create!({ delay_processing: true }.merge(media_attachment_params)) - render json: @media_attachment, serializer: REST::MediaAttachmentSerializer, status: 202 + render json: @media_attachment, serializer: REST::MediaAttachmentSerializer, status: @media_attachment.not_processed? ? 202 : 200 rescue Paperclip::Errors::NotIdentifiedByImageMagickError render json: file_type_error, status: 422 rescue Paperclip::Error diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index 4a1948380..81e8ef2dc 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -248,11 +248,11 @@ class MediaAttachment < ApplicationRecord attr_writer :delay_processing def delay_processing? - @delay_processing + @delay_processing && larger_media_format? end def delay_processing_for_attachment?(attachment_name) - @delay_processing && attachment_name == :file + delay_processing? && attachment_name == :file end after_commit :enqueue_processing, on: :create -- cgit From ae07cfb8688e862203f682feaed866ce0ac1774e Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 1 Nov 2022 16:26:25 +0100 Subject: Add support for HEIC uploads (#19618) --- app/models/media_attachment.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index 81e8ef2dc..c71b54eb8 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -44,7 +44,7 @@ class MediaAttachment < ApplicationRecord MAX_VIDEO_MATRIX_LIMIT = 2_304_000 # 1920x1200px MAX_VIDEO_FRAME_RATE = 60 - IMAGE_FILE_EXTENSIONS = %w(.jpg .jpeg .png .gif .webp).freeze + IMAGE_FILE_EXTENSIONS = %w(.jpg .jpeg .png .gif .webp .heic .heif).freeze VIDEO_FILE_EXTENSIONS = %w(.webm .mp4 .m4v .mov).freeze AUDIO_FILE_EXTENSIONS = %w(.ogg .oga .mp3 .wav .flac .opus .aac .m4a .3gp .wma).freeze @@ -55,7 +55,8 @@ class MediaAttachment < ApplicationRecord small ).freeze - IMAGE_MIME_TYPES = %w(image/jpeg image/png image/gif image/webp).freeze + IMAGE_MIME_TYPES = %w(image/jpeg image/png image/gif image/heic image/heif image/webp).freeze + IMAGE_CONVERTIBLE_MIME_TYPES = %w(image/heic image/heif).freeze VIDEO_MIME_TYPES = %w(video/webm video/mp4 video/quicktime video/ogg).freeze VIDEO_CONVERTIBLE_MIME_TYPES = %w(video/webm video/quicktime).freeze AUDIO_MIME_TYPES = %w(audio/wave audio/wav audio/x-wav audio/x-pn-wave audio/vnd.wave audio/ogg audio/vorbis audio/mpeg audio/mp3 audio/webm audio/flac audio/aac audio/m4a audio/x-m4a audio/mp4 audio/3gpp video/x-ms-asf).freeze @@ -78,6 +79,16 @@ class MediaAttachment < ApplicationRecord }.freeze, }.freeze + IMAGE_CONVERTED_STYLES = { + original: { + format: 'jpeg', + }.merge(IMAGE_STYLES[:original]).freeze, + + small: { + format: 'jpeg', + }.merge(IMAGE_STYLES[:small]).freeze, + }.freeze + VIDEO_FORMAT = { format: 'mp4', content_type: 'video/mp4', @@ -277,6 +288,8 @@ class MediaAttachment < ApplicationRecord def file_styles(attachment) if attachment.instance.file_content_type == 'image/gif' || VIDEO_CONVERTIBLE_MIME_TYPES.include?(attachment.instance.file_content_type) VIDEO_CONVERTED_STYLES + elsif IMAGE_CONVERTIBLE_MIME_TYPES.include?(attachment.instance.file_content_type) + IMAGE_CONVERTED_STYLES elsif IMAGE_MIME_TYPES.include?(attachment.instance.file_content_type) IMAGE_STYLES elsif VIDEO_MIME_TYPES.include?(attachment.instance.file_content_type) -- cgit From 0f5e6dd02b9434f66c2f19715b0f1318c5d721ed Mon Sep 17 00:00:00 2001 From: txt-file <44214237+txt-file@users.noreply.github.com> Date: Tue, 1 Nov 2022 22:08:41 +0100 Subject: Add support for AVIF uploads (#19647) --- app/models/media_attachment.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index c71b54eb8..a6e090f4c 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -44,7 +44,7 @@ class MediaAttachment < ApplicationRecord MAX_VIDEO_MATRIX_LIMIT = 2_304_000 # 1920x1200px MAX_VIDEO_FRAME_RATE = 60 - IMAGE_FILE_EXTENSIONS = %w(.jpg .jpeg .png .gif .webp .heic .heif).freeze + IMAGE_FILE_EXTENSIONS = %w(.jpg .jpeg .png .gif .webp .heic .heif .avif).freeze VIDEO_FILE_EXTENSIONS = %w(.webm .mp4 .m4v .mov).freeze AUDIO_FILE_EXTENSIONS = %w(.ogg .oga .mp3 .wav .flac .opus .aac .m4a .3gp .wma).freeze @@ -55,7 +55,7 @@ class MediaAttachment < ApplicationRecord small ).freeze - IMAGE_MIME_TYPES = %w(image/jpeg image/png image/gif image/heic image/heif image/webp).freeze + IMAGE_MIME_TYPES = %w(image/jpeg image/png image/gif image/heic image/heif image/webp image/avif).freeze IMAGE_CONVERTIBLE_MIME_TYPES = %w(image/heic image/heif).freeze VIDEO_MIME_TYPES = %w(video/webm video/mp4 video/quicktime video/ogg).freeze VIDEO_CONVERTIBLE_MIME_TYPES = %w(video/webm video/quicktime).freeze -- cgit From 125322718bfe983e94937f5d127003d47a138313 Mon Sep 17 00:00:00 2001 From: Claire Date: Wed, 2 Nov 2022 18:50:21 +0100 Subject: Fix inaccurate admin log entry for re-sending confirmation e-mails (#19674) Fixes #19593 --- app/controllers/admin/confirmations_controller.rb | 2 +- app/models/admin/action_log_filter.rb | 1 + config/locales/en.yml | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/controllers/admin/confirmations_controller.rb b/app/controllers/admin/confirmations_controller.rb index efe7dcbd4..6f4e42679 100644 --- a/app/controllers/admin/confirmations_controller.rb +++ b/app/controllers/admin/confirmations_controller.rb @@ -17,7 +17,7 @@ module Admin @user.resend_confirmation_instructions - log_action :confirm, @user + log_action :resend, @user flash[:notice] = I18n.t('admin.accounts.resend_confirmation.success') redirect_to admin_accounts_path diff --git a/app/models/admin/action_log_filter.rb b/app/models/admin/action_log_filter.rb index c7a7e1a4c..edb391e2e 100644 --- a/app/models/admin/action_log_filter.rb +++ b/app/models/admin/action_log_filter.rb @@ -47,6 +47,7 @@ class Admin::ActionLogFilter promote_user: { target_type: 'User', action: 'promote' }.freeze, remove_avatar_user: { target_type: 'User', action: 'remove_avatar' }.freeze, reopen_report: { target_type: 'Report', action: 'reopen' }.freeze, + resend_user: { target_type: 'User', action: 'resend' }.freeze, reset_password_user: { target_type: 'User', action: 'reset_password' }.freeze, resolve_report: { target_type: 'Report', action: 'resolve' }.freeze, sensitive_account: { target_type: 'Account', action: 'sensitive' }.freeze, diff --git a/config/locales/en.yml b/config/locales/en.yml index 547b19f07..ce8dea65b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -207,6 +207,7 @@ en: reject_user: Reject User remove_avatar_user: Remove Avatar reopen_report: Reopen Report + resend_user: Resend Confirmation Mail reset_password_user: Reset Password resolve_report: Resolve Report sensitive_account: Force-Sensitive Account @@ -265,6 +266,7 @@ en: reject_user_html: "%{name} rejected sign-up from %{target}" remove_avatar_user_html: "%{name} removed %{target}'s avatar" reopen_report_html: "%{name} reopened report %{target}" + resend_user_html: "%{name} resent confirmation e-mail for %{target}" reset_password_user_html: "%{name} reset password of user %{target}" resolve_report_html: "%{name} resolved report %{target}" sensitive_account_html: "%{name} marked %{target}'s media as sensitive" -- cgit From b1a219552e935d0c988e1f20b9fdceeb042d2c2d Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 4 Nov 2022 16:08:29 +0100 Subject: Fix featured tags not saving preferred casing (#19732) --- app/models/featured_tag.rb | 25 +++++++++------------- config/locales/simple_form.en.yml | 2 +- .../20221104133904_add_name_to_featured_tags.rb | 5 +++++ db/schema.rb | 3 ++- 4 files changed, 18 insertions(+), 17 deletions(-) create mode 100644 db/migrate/20221104133904_add_name_to_featured_tags.rb (limited to 'app/models') diff --git a/app/models/featured_tag.rb b/app/models/featured_tag.rb index d4ed74302..78185b2a9 100644 --- a/app/models/featured_tag.rb +++ b/app/models/featured_tag.rb @@ -10,13 +10,16 @@ # last_status_at :datetime # created_at :datetime not null # updated_at :datetime not null +# name :string # class FeaturedTag < ApplicationRecord belongs_to :account, inverse_of: :featured_tags belongs_to :tag, inverse_of: :featured_tags, optional: true # Set after validation - validate :validate_tag_name, on: :create + validates :name, presence: true, format: { with: /\A(#{Tag::HASHTAG_NAME_RE})\z/i }, on: :create + + validate :validate_tag_uniqueness, on: :create validate :validate_featured_tags_limit, on: :create before_validation :strip_name @@ -26,18 +29,14 @@ class FeaturedTag < ApplicationRecord scope :by_name, ->(name) { joins(:tag).where(tag: { name: HashtagNormalizer.new.normalize(name) }) } - delegate :display_name, to: :tag - - attr_writer :name - LIMIT = 10 def sign? true end - def name - tag_id.present? ? tag.name : @name + def display_name + attributes['name'] || tag.display_name end def increment(timestamp) @@ -51,13 +50,11 @@ class FeaturedTag < ApplicationRecord private def strip_name - return unless defined?(@name) - - @name = @name&.strip&.gsub(/\A#/, '') + self.name = name&.strip&.gsub(/\A#/, '') end def set_tag - self.tag = Tag.find_or_create_by_names(@name)&.first + self.tag = Tag.find_or_create_by_names(name)&.first end def reset_data @@ -69,9 +66,7 @@ class FeaturedTag < ApplicationRecord errors.add(:base, I18n.t('featured_tags.errors.limit')) if account.featured_tags.count >= LIMIT end - def validate_tag_name - errors.add(:name, :blank) if @name.blank? - errors.add(:name, :invalid) unless @name.match?(/\A(#{Tag::HASHTAG_NAME_RE})\z/i) - errors.add(:name, :taken) if FeaturedTag.by_name(@name).where(account_id: account_id).exists? + def validate_tag_uniqueness + errors.add(:name, :taken) if FeaturedTag.by_name(name).where(account_id: account_id).exists? end end diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index 64281d7b7..6edf7b4e9 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -67,7 +67,7 @@ en: domain: This can be the domain name that shows up in the e-mail address or the MX record it uses. They will be checked upon sign-up. with_dns_records: An attempt to resolve the given domain's DNS records will be made and the results will also be blocked featured_tag: - name: 'You might want to use one of these:' + name: 'Here are some of the hashtags you used the most recently:' filters: action: Chose which action to perform when a post matches the filter actions: diff --git a/db/migrate/20221104133904_add_name_to_featured_tags.rb b/db/migrate/20221104133904_add_name_to_featured_tags.rb new file mode 100644 index 000000000..7c8c8ebfb --- /dev/null +++ b/db/migrate/20221104133904_add_name_to_featured_tags.rb @@ -0,0 +1,5 @@ +class AddNameToFeaturedTags < ActiveRecord::Migration[6.1] + def change + add_column :featured_tags, :name, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 12ec37c11..09d07fcca 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_11_01_190723) do +ActiveRecord::Schema.define(version: 2022_11_04_133904) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -442,6 +442,7 @@ ActiveRecord::Schema.define(version: 2022_11_01_190723) do t.datetime "last_status_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "name" t.index ["account_id", "tag_id"], name: "index_featured_tags_on_account_id_and_tag_id", unique: true t.index ["tag_id"], name: "index_featured_tags_on_tag_id" end -- cgit From c2170991c7889b8f6c6434f416cb0a8450db25a1 Mon Sep 17 00:00:00 2001 From: Claire Date: Fri, 4 Nov 2022 16:31:44 +0100 Subject: Fix reblogs being discarded after the reblogged status (#19731) --- app/controllers/api/v1/statuses_controller.rb | 2 +- app/lib/status_reach_finder.rb | 2 +- app/models/admin/status_batch_action.rb | 2 +- app/models/status.rb | 6 ++++++ app/services/account_statuses_cleanup_service.rb | 2 +- app/services/remove_status_service.rb | 4 ++-- 6 files changed, 12 insertions(+), 6 deletions(-) (limited to 'app/models') diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb index 2e239d48b..676ec2a79 100644 --- a/app/controllers/api/v1/statuses_controller.rb +++ b/app/controllers/api/v1/statuses_controller.rb @@ -77,7 +77,7 @@ class Api::V1::StatusesController < Api::BaseController @status = Status.where(account: current_account).find(params[:id]) authorize @status, :destroy? - @status.discard + @status.discard_with_reblogs StatusPin.find_by(status: @status)&.destroy @status.account.statuses_count = @status.account.statuses_count - 1 json = render_to_body json: @status, serializer: REST::StatusSerializer, source_requested: true diff --git a/app/lib/status_reach_finder.rb b/app/lib/status_reach_finder.rb index 98e502bb6..ccf1e9e3a 100644 --- a/app/lib/status_reach_finder.rb +++ b/app/lib/status_reach_finder.rb @@ -55,7 +55,7 @@ class StatusReachFinder # Beware: Reblogs can be created without the author having had access to the status def reblogs_account_ids - @status.reblogs.pluck(:account_id) if distributable? || unsafe? + @status.reblogs.rewhere(deleted_at: [nil, @status.deleted_at]).pluck(:account_id) if distributable? || unsafe? end # Beware: Favourites can be created without the author having had access to the status diff --git a/app/models/admin/status_batch_action.rb b/app/models/admin/status_batch_action.rb index 0ec4fef82..0f019b854 100644 --- a/app/models/admin/status_batch_action.rb +++ b/app/models/admin/status_batch_action.rb @@ -44,7 +44,7 @@ class Admin::StatusBatchAction ApplicationRecord.transaction do statuses.each do |status| - status.discard + status.discard_with_reblogs log_action(:destroy, status) end diff --git a/app/models/status.rb b/app/models/status.rb index 4805abfea..8bdb5e8db 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -440,6 +440,12 @@ class Status < ApplicationRecord im end + def discard_with_reblogs + discard_time = Time.current + Status.unscoped.where(reblog_of_id: id, deleted_at: [nil, deleted_at]).in_batches.update_all(deleted_at: discard_time) unless reblog? + update_attribute(:deleted_at, discard_time) + end + private def update_status_stat!(attrs) diff --git a/app/services/account_statuses_cleanup_service.rb b/app/services/account_statuses_cleanup_service.rb index 3918b5ba4..96bc3db7d 100644 --- a/app/services/account_statuses_cleanup_service.rb +++ b/app/services/account_statuses_cleanup_service.rb @@ -14,7 +14,7 @@ class AccountStatusesCleanupService < BaseService last_deleted = nil account_policy.statuses_to_delete(budget, cutoff_id, account_policy.last_inspected).reorder(nil).find_each(order: :asc) do |status| - status.discard + status.discard_with_reblogs RemovalWorker.perform_async(status.id, { 'redraft' => false }) num_deleted += 1 last_deleted = status.id diff --git a/app/services/remove_status_service.rb b/app/services/remove_status_service.rb index f9fdea2cb..37d2dabae 100644 --- a/app/services/remove_status_service.rb +++ b/app/services/remove_status_service.rb @@ -19,7 +19,7 @@ class RemoveStatusService < BaseService @options = options with_lock("distribute:#{@status.id}") do - @status.discard + @status.discard_with_reblogs StatusPin.find_by(status: @status)&.destroy @@ -102,7 +102,7 @@ class RemoveStatusService < BaseService # because once original status is gone, reblogs will disappear # without us being able to do all the fancy stuff - @status.reblogs.includes(:account).reorder(nil).find_each do |reblog| + @status.reblogs.rewhere(deleted_at: [nil, @status.deleted_at]).includes(:account).reorder(nil).find_each do |reblog| RemoveStatusService.new.call(reblog, original_removed: true) end end -- cgit From 3151b260e27c1d3143b36a68b700bf3884ae9808 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 6 Nov 2022 06:16:34 +0100 Subject: Fix not using GIN index for account search queries (#19830) --- app/models/account.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/account.rb b/app/models/account.rb index da0ee2336..3647b8225 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -445,7 +445,7 @@ class Account < ApplicationRecord class << self DISALLOWED_TSQUERY_CHARACTERS = /['?\\:‘’]/.freeze - TEXTSEARCH = "(setweight(to_tsvector('simple', accounts.display_name), 'A') || setweight(to_tsvector('simple', accounts.username), 'A') || setweight(to_tsvector('simple', coalesce(accounts.domain, '')), 'C'))" + TEXTSEARCH = "(setweight(to_tsvector('simple', accounts.display_name), 'A') || setweight(to_tsvector('simple', accounts.username), 'B') || setweight(to_tsvector('simple', coalesce(accounts.domain, '')), 'C'))" REPUTATION_SCORE_FUNCTION = '(greatest(0, coalesce(s.followers_count, 0)) / (greatest(0, coalesce(s.following_count, 0)) + 1.0))' FOLLOWERS_SCORE_FUNCTION = 'log(greatest(0, coalesce(s.followers_count, 0)) + 2)' -- cgit