Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change public accounts pages to mount the web UI #19319

Merged
merged 10 commits into from
Oct 20, 2022
8 changes: 8 additions & 0 deletions app/controllers/about_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ class AboutController < ApplicationController

skip_before_action :require_functional!

before_action :set_instance_presenter

def show
expires_in 0, public: true unless user_signed_in?
end

private

def set_instance_presenter
@instance_presenter = InstancePresenter.new
end
Comment on lines +8 to +18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this related?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a crash because this presenter is used by the OpenGraph partial

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, but I'm not sure how adding the OpenGraph partial to this controller is related to begin with

end
12 changes: 0 additions & 12 deletions app/controllers/account_follow_controller.rb

This file was deleted.

12 changes: 0 additions & 12 deletions app/controllers/account_unfollow_controller.rb

This file was deleted.

58 changes: 0 additions & 58 deletions app/controllers/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class AccountsController < ApplicationController

before_action :require_account_signature!, if: -> { request.format == :json && authorized_fetch_mode? }
before_action :set_cache_headers
before_action :set_body_classes

skip_around_action :set_locale, if: -> { [:json, :rss].include?(request.format&.to_sym) }
skip_before_action :require_functional!, unless: :whitelist_mode?
Expand All @@ -18,24 +17,6 @@ def show
respond_to do |format|
format.html do
expires_in 0, public: true unless user_signed_in?

@pinned_statuses = []
@endorsed_accounts = @account.endorsed_accounts.to_a.sample(4)
@featured_hashtags = @account.featured_tags.order(statuses_count: :desc)

if current_account && @account.blocking?(current_account)
@statuses = []
return
end

@pinned_statuses = cached_filtered_status_pins if show_pinned_statuses?
@statuses = cached_filtered_status_page
@rss_url = rss_url

unless @statuses.empty?
@older_url = older_url if @statuses.last.id > filtered_statuses.last.id
@newer_url = newer_url if @statuses.first.id < filtered_statuses.first.id
end
end

format.rss do
Expand All @@ -55,18 +36,6 @@ def show

private

def set_body_classes
@body_classes = 'with-modals'
end

def show_pinned_statuses?
[replies_requested?, media_requested?, tag_requested?, params[:max_id].present?, params[:min_id].present?].none?
end

def filtered_pinned_statuses
@account.pinned_statuses.where(visibility: [:public, :unlisted])
end

def filtered_statuses
default_statuses.tap do |statuses|
statuses.merge!(hashtag_scope) if tag_requested?
Expand Down Expand Up @@ -113,26 +82,6 @@ def rss_url
end
end

def older_url
pagination_url(max_id: @statuses.last.id)
end

def newer_url
pagination_url(min_id: @statuses.first.id)
end

def pagination_url(max_id: nil, min_id: nil)
if tag_requested?
short_account_tag_url(@account, params[:tag], max_id: max_id, min_id: min_id)
elsif media_requested?
short_account_media_url(@account, max_id: max_id, min_id: min_id)
elsif replies_requested?
short_account_with_replies_url(@account, max_id: max_id, min_id: min_id)
else
short_account_url(@account, max_id: max_id, min_id: min_id)
end
end

def media_requested?
request.path.split('.').first.end_with?('/media') && !tag_requested?
end
Expand All @@ -145,13 +94,6 @@ def tag_requested?
request.path.split('.').first.end_with?(Addressable::URI.parse("/tagged/#{params[:tag]}").normalize)
end

def cached_filtered_status_pins
cache_collection(
filtered_pinned_statuses,
Status
)
end

def cached_filtered_status_page
cache_collection_paginated_by_id(
filtered_statuses,
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/concerns/account_controller_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
module AccountControllerConcern
extend ActiveSupport::Concern

include WebAppControllerConcern
include AccountOwnedConcern

FOLLOW_PER_PAGE = 12

included do
layout 'public'

before_action :set_instance_presenter
before_action :set_link_headers, if: -> { request.format.nil? || request.format == :html }
end
Expand Down
13 changes: 11 additions & 2 deletions app/controllers/concerns/web_app_controller_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,24 @@ module WebAppControllerConcern
extend ActiveSupport::Concern

included do
before_action :set_body_classes
before_action :redirect_unauthenticated_to_permalinks!
before_action :set_app_body_class
before_action :set_referrer_policy_header
end

def set_body_classes
def set_app_body_class
@body_classes = 'app-body'
end

def set_referrer_policy_header
response.headers['Referrer-Policy'] = 'origin'
end

def redirect_unauthenticated_to_permalinks!
return if user_signed_in?

redirect_path = PermalinkRedirector.new(request.path).redirect_path

redirect_to(redirect_path) if redirect_path.present?
end
end
5 changes: 1 addition & 4 deletions app/controllers/follower_accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class FollowerAccountsController < ApplicationController
include AccountControllerConcern
include SignatureVerification
include WebAppControllerConcern

before_action :require_account_signature!, if: -> { request.format == :json && authorized_fetch_mode? }
before_action :set_cache_headers
Expand All @@ -14,10 +15,6 @@ def index
respond_to do |format|
format.html do
expires_in 0, public: true unless user_signed_in?

next if @account.hide_collections?

follows
end

format.json do
Expand Down
5 changes: 1 addition & 4 deletions app/controllers/following_accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class FollowingAccountsController < ApplicationController
include AccountControllerConcern
include SignatureVerification
include WebAppControllerConcern

before_action :require_account_signature!, if: -> { request.format == :json && authorized_fetch_mode? }
before_action :set_cache_headers
Expand All @@ -14,10 +15,6 @@ def index
respond_to do |format|
format.html do
expires_in 0, public: true unless user_signed_in?

next if @account.hide_collections?

follows
end

format.json do
Expand Down
13 changes: 3 additions & 10 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,14 @@
class HomeController < ApplicationController
include WebAppControllerConcern

before_action :redirect_unauthenticated_to_permalinks!
before_action :set_instance_presenter

def index; end
def index
expires_in 0, public: true unless user_signed_in?
end

private

def redirect_unauthenticated_to_permalinks!
return if user_signed_in?

redirect_path = PermalinkRedirector.new(request.path).redirect_path

redirect_to(redirect_path) if redirect_path.present?
end

def set_instance_presenter
@instance_presenter = InstancePresenter.new
end
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/privacy_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ class PrivacyController < ApplicationController

skip_before_action :require_functional!

before_action :set_instance_presenter

def show
expires_in 0, public: true if current_account.nil?
end

private

def set_instance_presenter
@instance_presenter = InstancePresenter.new
end
end
41 changes: 0 additions & 41 deletions app/controllers/remote_follow_controller.rb

This file was deleted.

55 changes: 0 additions & 55 deletions app/controllers/remote_interaction_controller.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/controllers/statuses_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

class StatusesController < ApplicationController
include WebAppControllerConcern
include StatusControllerConcern
include SignatureAuthentication
include Authorization
include AccountOwnedConcern
include WebAppControllerConcern

before_action :require_account_signature!, only: [:show, :activity], if: -> { request.format == :json && authorized_fetch_mode? }
before_action :set_status
Expand Down