From 3fd2aadb2323728e15fe2d49928b4af09447cf0f Mon Sep 17 00:00:00 2001 From: Claire Date: Wed, 25 May 2022 12:27:11 +0200 Subject: [PATCH] Various code cleanup (#1782) * Remove duplicate in_chosen_languages definition * Use `DEFAULT_FIELDS_SIZE` instead of `MAX_FIELDS` to reduce code differences with upstream * Remove duplicate annotation * Fix incorrect cross-flavor imports * Remove deprecated `hide_network` setting (replaced by account column) * Remove unused KeywordMutesHelper * Remove trailing spaces * Remove commit_hash from InstancePresenter, as it has been unused since mid-2017 --- app/helpers/settings/keyword_mutes_helper.rb | 2 -- .../flavours/glitch/components/dropdown_menu.js | 2 +- .../flavours/glitch/features/report/thanks.js | 2 +- app/lib/user_settings_decorator.rb | 5 ----- app/models/account.rb | 8 ++++---- app/models/mute.rb | 1 - app/models/status.rb | 4 ---- app/policies/status_policy.rb | 2 +- app/presenters/instance_presenter.rb | 9 --------- app/validators/status_pin_validator.rb | 2 +- .../helpers/settings/keyword_mutes_helper_spec.rb | 15 --------------- 11 files changed, 8 insertions(+), 44 deletions(-) delete mode 100644 app/helpers/settings/keyword_mutes_helper.rb delete mode 100644 spec/helpers/settings/keyword_mutes_helper_spec.rb diff --git a/app/helpers/settings/keyword_mutes_helper.rb b/app/helpers/settings/keyword_mutes_helper.rb deleted file mode 100644 index 7b98cd59e0..0000000000 --- a/app/helpers/settings/keyword_mutes_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module Settings::KeywordMutesHelper -end diff --git a/app/javascript/flavours/glitch/components/dropdown_menu.js b/app/javascript/flavours/glitch/components/dropdown_menu.js index bd6bc4ffda..e04af8074b 100644 --- a/app/javascript/flavours/glitch/components/dropdown_menu.js +++ b/app/javascript/flavours/glitch/components/dropdown_menu.js @@ -7,7 +7,7 @@ import Motion from 'flavours/glitch/util/optional_motion'; import spring from 'react-motion/lib/spring'; import { supportsPassiveEvents } from 'detect-passive-events'; import classNames from 'classnames'; -import { CircularProgress } from 'mastodon/components/loading_indicator'; +import { CircularProgress } from 'flavours/glitch/components/loading_indicator'; const listenerOptions = supportsPassiveEvents ? { passive: true } : false; let id = 0; diff --git a/app/javascript/flavours/glitch/features/report/thanks.js b/app/javascript/flavours/glitch/features/report/thanks.js index 9c41baa7fd..454979f9fa 100644 --- a/app/javascript/flavours/glitch/features/report/thanks.js +++ b/app/javascript/flavours/glitch/features/report/thanks.js @@ -8,7 +8,7 @@ import { unfollowAccount, muteAccount, blockAccount, -} from 'mastodon/actions/accounts'; +} from 'flavours/glitch/actions/accounts'; const mapStateToProps = () => ({}); diff --git a/app/lib/user_settings_decorator.rb b/app/lib/user_settings_decorator.rb index d339e078ca..1d70ed36ab 100644 --- a/app/lib/user_settings_decorator.rb +++ b/app/lib/user_settings_decorator.rb @@ -34,7 +34,6 @@ class UserSettingsDecorator user.settings['noindex'] = noindex_preference if change?('setting_noindex') user.settings['flavour'] = flavour_preference if change?('setting_flavour') user.settings['skin'] = skin_preference if change?('setting_skin') - user.settings['hide_network'] = hide_network_preference if change?('setting_hide_network') user.settings['aggregate_reblogs'] = aggregate_reblogs_preference if change?('setting_aggregate_reblogs') user.settings['show_application'] = show_application_preference if change?('setting_show_application') user.settings['advanced_layout'] = advanced_layout_preference if change?('setting_advanced_layout') @@ -118,10 +117,6 @@ class UserSettingsDecorator settings['setting_skin'] end - def hide_network_preference - boolean_cast_setting 'setting_hide_network' - end - def show_application_preference boolean_cast_setting 'setting_show_application' end diff --git a/app/models/account.rb b/app/models/account.rb index 068ee7ae9c..f4fc321535 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -79,7 +79,7 @@ class Account < ApplicationRecord MAX_DISPLAY_NAME_LENGTH = (ENV['MAX_DISPLAY_NAME_CHARS'] || 30).to_i MAX_NOTE_LENGTH = (ENV['MAX_BIO_CHARS'] || 500).to_i - MAX_FIELDS = (ENV['MAX_PROFILE_FIELDS'] || 4).to_i + DEFAULT_FIELDS_SIZE = (ENV['MAX_PROFILE_FIELDS'] || 4).to_i enum protocol: [:ostatus, :activitypub] enum suspension_origin: [:local, :remote], _prefix: true @@ -95,7 +95,7 @@ class Account < ApplicationRecord validates_with UnreservedUsernameValidator, if: -> { local? && will_save_change_to_username? } validates :display_name, length: { maximum: MAX_DISPLAY_NAME_LENGTH }, if: -> { local? && will_save_change_to_display_name? } validates :note, note_length: { maximum: MAX_NOTE_LENGTH }, if: -> { local? && will_save_change_to_note? } - validates :fields, length: { maximum: MAX_FIELDS }, if: -> { local? && will_save_change_to_fields? } + validates :fields, length: { maximum: DEFAULT_FIELDS_SIZE }, if: -> { local? && will_save_change_to_fields? } scope :remote, -> { where.not(domain: nil) } scope :local, -> { where(domain: nil) } @@ -329,12 +329,12 @@ class Account < ApplicationRecord end def build_fields - return if fields.size >= MAX_FIELDS + return if fields.size >= DEFAULT_FIELDS_SIZE tmp = self[:fields] || [] tmp = [] if tmp.is_a?(Hash) - (MAX_FIELDS - tmp.size).times do + (DEFAULT_FIELDS_SIZE - tmp.size).times do tmp << { name: '', value: '' } end diff --git a/app/models/mute.rb b/app/models/mute.rb index fe8b6f42c8..578345ef64 100644 --- a/app/models/mute.rb +++ b/app/models/mute.rb @@ -6,7 +6,6 @@ # id :bigint(8) not null, primary key # created_at :datetime not null # updated_at :datetime not null -# hide_notifications :boolean default(TRUE), not null # account_id :bigint(8) not null # target_account_id :bigint(8) not null # hide_notifications :boolean default(TRUE), not null diff --git a/app/models/status.rb b/app/models/status.rb index 75b464a708..21a574a71e 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -322,10 +322,6 @@ class Status < ApplicationRecord visibilities.keys - %w(direct limited) end - def in_chosen_languages(account) - where(language: nil).or where(language: account.chosen_languages) - end - def as_direct_timeline(account, limit = 20, max_id = nil, since_id = nil, cache_ids = false) # direct timeline is mix of direct message from_me and to_me. # 2 queries are executed with pagination. diff --git a/app/policies/status_policy.rb b/app/policies/status_policy.rb index d3a3b36c0d..75d95a90b3 100644 --- a/app/policies/status_policy.rb +++ b/app/policies/status_policy.rb @@ -97,7 +97,7 @@ class StatusPolicy < ApplicationPolicy def author record.account end - + def local_only? record.local_only? end diff --git a/app/presenters/instance_presenter.rb b/app/presenters/instance_presenter.rb index a0f1ebd0ab..3e85faa924 100644 --- a/app/presenters/instance_presenter.rb +++ b/app/presenters/instance_presenter.rb @@ -44,15 +44,6 @@ class InstancePresenter Mastodon::Version end - def commit_hash - current_release_file = Pathname.new('CURRENT_RELEASE').expand_path - if current_release_file.file? - IO.read(current_release_file).strip! - else - '' - end - end - def source_url Mastodon::Version.source_url end diff --git a/app/validators/status_pin_validator.rb b/app/validators/status_pin_validator.rb index 35a101f1d7..9466a81fef 100644 --- a/app/validators/status_pin_validator.rb +++ b/app/validators/status_pin_validator.rb @@ -2,7 +2,7 @@ class StatusPinValidator < ActiveModel::Validator MAX_PINNED = (ENV['MAX_PINNED_TOOTS'] || 5).to_i - + def validate(pin) pin.errors.add(:base, I18n.t('statuses.pin_errors.reblog')) if pin.status.reblog? pin.errors.add(:base, I18n.t('statuses.pin_errors.ownership')) if pin.account_id != pin.status.account_id diff --git a/spec/helpers/settings/keyword_mutes_helper_spec.rb b/spec/helpers/settings/keyword_mutes_helper_spec.rb deleted file mode 100644 index a19d518ddd..0000000000 --- a/spec/helpers/settings/keyword_mutes_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'rails_helper' - -# Specs in this file have access to a helper object that includes -# the Settings::KeywordMutesHelper. For example: -# -# describe Settings::KeywordMutesHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# expect(helper.concat_strings("this","that")).to eq("this that") -# end -# end -# end -RSpec.describe Settings::KeywordMutesHelper, type: :helper do - pending "add some examples to (or delete) #{__FILE__}" -end