diff --git a/Gemfile b/Gemfile index a81cd7c31a2..a3cd76fc4f2 100644 --- a/Gemfile +++ b/Gemfile @@ -114,7 +114,7 @@ group :production, :test do end group :test do - gem 'capybara', '~> 3.36' + gem 'capybara', '~> 3.37' gem 'climate_control', '~> 0.2' gem 'faker', '~> 2.20' gem 'microformats', '~> 4.2' diff --git a/Gemfile.lock b/Gemfile.lock index ad5fd705565..472f4e19cca 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -144,7 +144,7 @@ GEM sshkit (~> 1.3) capistrano-yarn (2.0.2) capistrano (~> 3.0) - capybara (3.36.0) + capybara (3.37.1) addressable matrix mini_mime (>= 0.1.3) @@ -308,7 +308,7 @@ GEM rainbow (>= 2.0.0) i18n (1.10.0) concurrent-ruby (~> 1.0) - i18n-tasks (1.0.9) + i18n-tasks (1.0.10) activesupport (>= 4.0.2) ast (>= 2.1.0) better_html (~> 1.0) @@ -469,7 +469,7 @@ GEM pry (~> 0.13.0) pry-rails (0.3.9) pry (>= 0.10.4) - public_suffix (4.0.6) + public_suffix (4.0.7) puma (5.6.4) nio4r (~> 2.0) pundit (2.2.0) @@ -536,7 +536,7 @@ GEM redis (4.5.1) redis-namespace (1.8.2) redis (>= 3.0.4) - regexp_parser (2.3.1) + regexp_parser (2.4.0) request_store (1.5.1) rack (>= 1.4) responders (3.0.1) @@ -614,7 +614,7 @@ GEM rufus-scheduler (~> 3.2) sidekiq (>= 4) tilt (>= 1.4.0) - sidekiq-unique-jobs (7.1.21) + sidekiq-unique-jobs (7.1.22) brpoplpush-redis_script (> 0.1.1, <= 2.0.0) concurrent-ruby (~> 1.0, >= 1.0.5) sidekiq (>= 5.0, < 8.0) @@ -745,7 +745,7 @@ DEPENDENCIES capistrano-rails (~> 1.6) capistrano-rbenv (~> 2.2) capistrano-yarn (~> 2.0) - capybara (~> 3.36) + capybara (~> 3.37) charlock_holmes (~> 0.7.7) chewy (~> 7.2) climate_control (~> 0.2) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 03c07c50b06..9949206cb3e 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -45,7 +45,6 @@ class AccountsController < ApplicationController limit = params[:limit].present? ? [params[:limit].to_i, PAGE_SIZE_MAX].min : PAGE_SIZE @statuses = filtered_statuses.without_reblogs.limit(limit) @statuses = cache_collection(@statuses, Status) - render xml: RSS::AccountSerializer.render(@account, @statuses, params[:tag]) end format.json do diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 64736e77fca..46821a200c7 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -27,7 +27,6 @@ class TagsController < ApplicationController format.rss do expires_in 0, public: true - render xml: RSS::TagSerializer.render(@tag, @statuses) end format.json do diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1c670fde0b1..b26e68c4dad 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -244,7 +244,7 @@ module ApplicationHelper end.values end - def prerender_custom_emojis(html, custom_emojis) - EmojiFormatter.new(html, custom_emojis, animate: prefers_autoplay?).to_s + def prerender_custom_emojis(html, custom_emojis, other_options = {}) + EmojiFormatter.new(html, custom_emojis, other_options.merge(animate: prefers_autoplay?)).to_s end end diff --git a/app/helpers/formatting_helper.rb b/app/helpers/formatting_helper.rb index 53e100dd277..526efd766f7 100644 --- a/app/helpers/formatting_helper.rb +++ b/app/helpers/formatting_helper.rb @@ -18,6 +18,32 @@ module FormattingHelper html_aware_format(status.text, status.local?, preloaded_accounts: [status.account] + (status.respond_to?(:active_mentions) ? status.active_mentions.map(&:account) : []), content_type: status.content_type) end + def rss_status_content_format(status) + html = status_content_format(status) + + before_html = begin + if status.spoiler_text? + "
#{I18n.t('rss.content_warning', locale: valid_locale_or_nil(status.language))} #{h(status.spoiler_text)}
#{status.preloadable_poll.options.map { |o| " #{h(o)}" }.join('
')}
#{poll_options_html}
" - end - - "#{html}#{after_html}" - end - end -end diff --git a/app/lib/rss_builder.rb b/app/lib/rss_builder.rb deleted file mode 100644 index 63ddba2e8ed..00000000000 --- a/app/lib/rss_builder.rb +++ /dev/null @@ -1,130 +0,0 @@ -# frozen_string_literal: true - -class RSSBuilder - class ItemBuilder - def initialize - @item = Ox::Element.new('item') - end - - def title(str) - @item << (Ox::Element.new('title') << str) - - self - end - - def link(str) - @item << Ox::Element.new('guid').tap do |guid| - guid['isPermalink'] = 'true' - guid << str - end - - @item << (Ox::Element.new('link') << str) - - self - end - - def pub_date(date) - @item << (Ox::Element.new('pubDate') << date.to_formatted_s(:rfc822)) - - self - end - - def description(str) - @item << (Ox::Element.new('description') << str) - - self - end - - def enclosure(url, type, size) - @item << Ox::Element.new('enclosure').tap do |enclosure| - enclosure['url'] = url - enclosure['length'] = size - enclosure['type'] = type - end - - self - end - - def to_element - @item - end - end - - def initialize - @document = Ox::Document.new(version: '1.0') - @channel = Ox::Element.new('channel') - - @document << (rss << @channel) - end - - def title(str) - @channel << (Ox::Element.new('title') << str) - - self - end - - def link(str) - @channel << (Ox::Element.new('link') << str) - - self - end - - def image(str) - @channel << Ox::Element.new('image').tap do |image| - image << (Ox::Element.new('url') << str) - image << (Ox::Element.new('title') << '') - image << (Ox::Element.new('link') << '') - end - - @channel << (Ox::Element.new('webfeeds:icon') << str) - - self - end - - def cover(str) - @channel << Ox::Element.new('webfeeds:cover').tap do |cover| - cover['image'] = str - end - - self - end - - def logo(str) - @channel << (Ox::Element.new('webfeeds:logo') << str) - - self - end - - def accent_color(str) - @channel << (Ox::Element.new('webfeeds:accentColor') << str) - - self - end - - def description(str) - @channel << (Ox::Element.new('description') << str) - - self - end - - def item - @channel << ItemBuilder.new.tap do |item| - yield item - end.to_element - - self - end - - def to_xml - ('' + Ox.dump(@document, effort: :tolerant)).force_encoding('UTF-8') - end - - private - - def rss - Ox::Element.new('rss').tap do |rss| - rss['version'] = '2.0' - rss['xmlns:webfeeds'] = 'http://webfeeds.org/rss/1.0' - end - end -end diff --git a/app/serializers/rest/account_serializer.rb b/app/serializers/rest/account_serializer.rb index 113e0cca706..e644a3f9173 100644 --- a/app/serializers/rest/account_serializer.rb +++ b/app/serializers/rest/account_serializer.rb @@ -13,6 +13,7 @@ class REST::AccountSerializer < ActiveModel::Serializer has_many :emojis, serializer: REST::CustomEmojiSerializer attribute :suspended, if: :suspended? + attribute :silenced, key: :limited, if: :silenced? class FieldSerializer < ActiveModel::Serializer include FormattingHelper @@ -102,7 +103,11 @@ class REST::AccountSerializer < ActiveModel::Serializer object.suspended? end - delegate :suspended?, to: :object + def silenced + object.silenced? + end + + delegate :suspended?, :silenced?, to: :object def moved_and_not_nested? object.moved? && object.moved_to_account.moved_to_account_id.nil? diff --git a/app/serializers/rss/account_serializer.rb b/app/serializers/rss/account_serializer.rb deleted file mode 100644 index 81e24af0d0c..00000000000 --- a/app/serializers/rss/account_serializer.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -class RSS::AccountSerializer < RSS::Serializer - include ActionView::Helpers::NumberHelper - include AccountsHelper - include RoutingHelper - - def render(account, statuses, tag) - builder = RSSBuilder.new - - builder.title("#{display_name(account)} (@#{account.local_username_and_domain})") - .description(account_description(account)) - .link(tag.present? ? short_account_tag_url(account, tag) : short_account_url(account)) - .logo(full_pack_url('media/images/logo.svg')) - .accent_color('2b90d9') - - builder.image(full_asset_url(account.avatar.url(:original))) if account.avatar? - builder.cover(full_asset_url(account.header.url(:original))) if account.header? - - render_statuses(builder, statuses) - - builder.to_xml - end - - def self.render(account, statuses, tag) - new.render(account, statuses, tag) - end -end diff --git a/app/serializers/rss/tag_serializer.rb b/app/serializers/rss/tag_serializer.rb deleted file mode 100644 index e549ac3675e..00000000000 --- a/app/serializers/rss/tag_serializer.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -class RSS::TagSerializer < RSS::Serializer - include ActionView::Helpers::NumberHelper - include ActionView::Helpers::SanitizeHelper - include RoutingHelper - - def render(tag, statuses) - builder = RSSBuilder.new - - builder.title("##{tag.name}") - .description(strip_tags(I18n.t('about.about_hashtag_html', hashtag: tag.name))) - .link(tag_url(tag)) - .logo(full_pack_url('media/images/logo.svg')) - .accent_color('2b90d9') - - render_statuses(builder, statuses) - - builder.to_xml - end - - def self.render(tag, statuses) - new.render(tag, statuses) - end -end diff --git a/app/views/accounts/show.rss.ruby b/app/views/accounts/show.rss.ruby new file mode 100644 index 00000000000..73c1c51e079 --- /dev/null +++ b/app/views/accounts/show.rss.ruby @@ -0,0 +1,37 @@ +RSS::Builder.build do |doc| + doc.title(display_name(@account)) + doc.description(I18n.t('rss.descriptions.account', acct: @account.local_username_and_domain)) + doc.link(params[:tag].present? ? short_account_tag_url(@account, params[:tag]) : short_account_url(@account)) + doc.image(full_asset_url(@account.avatar.url(:original)), display_name(@account), params[:tag].present? ? short_account_tag_url(@account, params[:tag]) : short_account_url(@account)) + doc.last_build_date(@statuses.first.created_at) if @statuses.any? + doc.icon(full_asset_url(@account.avatar.url(:original))) + doc.logo(full_pack_url('media/images/logo_transparent_white.svg')) + doc.generator("Mastodon v#{Mastodon::Version.to_s}") + + @statuses.each do |status| + doc.item do |item| + item.title(l(status.created_at)) + item.link(ActivityPub::TagManager.instance.url_for(status)) + item.pub_date(status.created_at) + item.description(rss_status_content_format(status)) + + if status.ordered_media_attachments.first&.audio? + media = status.ordered_media_attachments.first + item.enclosure(full_asset_url(media.file.url(:original, false)), media.file.content_type, media.file.size) + end + + status.ordered_media_attachments.each do |media| + item.media_content(full_asset_url(media.file.url(:original, false)), media.file.content_type, media.file.size) do |media_content| + media_content.medium(media.gifv? ? 'image' : media.type.to_s) + media_content.rating(status.sensitive? ? 'adult' : 'nonadult') + media_content.description(media.description) if media.description.present? + media_content.thumbnail(media.thumbnail.url(:original, false)) if media.thumbnail? + end + end + + status.tags.each do |tag| + item.category(tag.name) + end + end + end +end diff --git a/app/views/tags/show.rss.ruby b/app/views/tags/show.rss.ruby new file mode 100644 index 00000000000..4152ecd24ba --- /dev/null +++ b/app/views/tags/show.rss.ruby @@ -0,0 +1,36 @@ +RSS::Builder.build do |doc| + doc.title("##{@tag.name}") + doc.description(I18n.t('rss.descriptions.tag', hashtag: @tag.name)) + doc.link(tag_url(@tag)) + doc.last_build_date(@statuses.first.created_at) if @statuses.any? + doc.icon(full_asset_url(@account.avatar.url(:original))) + doc.logo(full_pack_url('media/images/logo_transparent_white.svg')) + doc.generator("Mastodon v#{Mastodon::Version.to_s}") + + @statuses.each do |status| + doc.item do |item| + item.title(l(status.created_at)) + item.link(ActivityPub::TagManager.instance.url_for(status)) + item.pub_date(status.created_at) + item.description(rss_status_content_format(status)) + + if status.ordered_media_attachments.first&.audio? + media = status.ordered_media_attachments.first + item.enclosure(full_asset_url(media.file.url(:original, false)), media.file.content_type, media.file.size) + end + + status.ordered_media_attachments.each do |media| + item.media_content(full_asset_url(media.file.url(:original, false)), media.file.content_type, media.file.size) do |media_content| + media_content.medium(media.gifv? ? 'image' : media.type.to_s) + media_content.rating(status.sensitive? ? 'adult' : 'nonadult') + media_content.description(media.description) if media.description.present? + media_content.thumbnail(media.thumbnail.url(:original, false)) if media.thumbnail? + end + end + + status.tags.each do |tag| + item.category(tag.name) + end + end + end +end diff --git a/config/locales/en.yml b/config/locales/en.yml index 2c8455d0aed..50e762db722 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1357,6 +1357,11 @@ en: reports: errors: invalid_rules: does not reference valid rules + rss: + content_warning: 'Content warning:' + descriptions: + account: Public posts from @%{acct} + tag: 'Public posts tagged #%{hashtag}' scheduled_statuses: over_daily_limit: You have exceeded the limit of %{limit} scheduled posts for today over_total_limit: You have exceeded the limit of %{limit} scheduled posts diff --git a/lib/tasks/mastodon.rake b/lib/tasks/mastodon.rake index a89af677807..d652468b37f 100644 --- a/lib/tasks/mastodon.rake +++ b/lib/tasks/mastodon.rake @@ -8,6 +8,14 @@ namespace :mastodon do prompt = TTY::Prompt.new env = {} + # When the application code gets loaded, it runs `lib/mastodon/redis_configuration.rb`. + # This happens before application environment configuration and sets REDIS_URL etc. + # These variables are then used even when REDIS_HOST etc. are changed, so clear them + # out so they don't interfer with our new configuration. + ENV.delete('REDIS_URL') + ENV.delete('CACHE_REDIS_URL') + ENV.delete('SIDEKIQ_REDIS_URL') + begin prompt.say('Your instance is identified by its domain name. Changing it afterward will break things.') env['LOCAL_DOMAIN'] = prompt.ask('Domain name:') do |q| diff --git a/package.json b/package.json index 69283b69841..68b7f12f0a4 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@gamestdio/websocket": "^0.3.2", "@github/webauthn-json": "^0.5.7", "@rails/ujs": "^6.1.5", - "array-includes": "^3.1.4", + "array-includes": "^3.1.5", "atrament": "0.2.4", "arrow-key-navigation": "^1.2.0", "autoprefixer": "^9.8.8", @@ -110,7 +110,7 @@ "react-redux-loading-bar": "^4.0.8", "react-router-dom": "^4.1.1", "react-router-scroll-4": "^1.0.0-beta.1", - "react-select": "^5.3.1", + "react-select": "^5.3.2", "react-sparklines": "^1.7.0", "react-swipeable-views": "^0.14.0", "react-textarea-autosize": "^8.3.3", @@ -147,14 +147,14 @@ "@testing-library/jest-dom": "^5.16.4", "@testing-library/react": "^12.1.5", "babel-eslint": "^10.1.0", - "babel-jest": "^28.0.3", + "babel-jest": "^28.1.0", "eslint": "^7.32.0", "eslint-plugin-import": "~2.26.0", "eslint-plugin-jsx-a11y": "~6.5.1", "eslint-plugin-promise": "~6.0.0", "eslint-plugin-react": "~7.29.4", - "jest": "^28.0.3", - "jest-environment-jsdom": "^28.0.2", + "jest": "^28.1.0", + "jest-environment-jsdom": "^28.1.0", "prettier": "^2.6.2", "raf": "^3.4.1", "react-intl-translations-manager": "^5.0.3", diff --git a/spec/controllers/settings/two_factor_authentication/confirmations_controller_spec.rb b/spec/controllers/settings/two_factor_authentication/confirmations_controller_spec.rb index 7b86513bef6..569c8322bd7 100644 --- a/spec/controllers/settings/two_factor_authentication/confirmations_controller_spec.rb +++ b/spec/controllers/settings/two_factor_authentication/confirmations_controller_spec.rb @@ -22,7 +22,7 @@ describe Settings::TwoFactorAuthentication::ConfirmationsController do let(:user) { Fabricate(:user, email: 'local-part@domain', otp_secret: with_otp_secret ? 'oldotpsecret' : nil) } describe 'GET #new' do - context 'when signed in and a new otp secret has been setted in the session' do + context 'when signed in and a new otp secret has been set in the session' do subject do sign_in user, scope: :user get :new, session: { challenge_passed_at: Time.now.utc, new_otp_secret: 'thisisasecretforthespecofnewview' } @@ -36,7 +36,7 @@ describe Settings::TwoFactorAuthentication::ConfirmationsController do expect(response).to redirect_to('/auth/sign_in') end - it 'redirects if a new otp_secret has not been setted in the session' do + it 'redirects if a new otp_secret has not been set in the session' do sign_in user, scope: :user get :new, session: { challenge_passed_at: Time.now.utc } expect(response).to redirect_to('/settings/otp_authentication') diff --git a/spec/lib/emoji_formatter_spec.rb b/spec/lib/emoji_formatter_spec.rb index 129445aa597..e1747bdd9db 100644 --- a/spec/lib/emoji_formatter_spec.rb +++ b/spec/lib/emoji_formatter_spec.rb @@ -24,7 +24,7 @@ RSpec.describe EmojiFormatter do let(:text) { preformat_text(':coolcat: Beep boop') } it 'converts the shortcode to an image tag' do - is_expected.to match(/