Merge branch 'fix-federation' into 'develop'

Fix federated threads

See merge request gab/social/gab-social!44
This commit is contained in:
Alex Gleason
2020-02-26 20:01:41 +00:00
13 changed files with 55 additions and 200 deletions

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
class AccountsController < ApplicationController
class AccountsController < ReactController
PAGE_SIZE = 20
include AccountControllerConcern
@@ -11,24 +11,7 @@ class AccountsController < ApplicationController
respond_to do |format|
format.html do
mark_cacheable! unless user_signed_in?
@body_classes = 'with-modals'
@pinned_statuses = []
@endorsed_accounts = @account.endorsed_accounts.to_a.sample(4)
if current_account && @account.blocking?(current_account)
@statuses = []
return
end
@pinned_statuses = cache_collection(@account.pinned_statuses, Status) if show_pinned_statuses?
@statuses = filtered_status_page(params)
@statuses = cache_collection(@statuses, Status)
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
return process(:react)
end
format.atom do

View File

@@ -11,12 +11,7 @@ class Api::V1::AccountByUsernameController < Api::BaseController
end
def set_account
username, domain = params[:username].split("@")
if domain
@account = Account.find_remote!(username, domain)
else
@account = Account.find_local!(username)
end
@account = Account.find_acct!(params[:username])
end
def check_account_suspension

View File

@@ -6,8 +6,6 @@ module AccountControllerConcern
FOLLOW_PER_PAGE = 12
included do
layout 'public'
before_action :set_account
before_action :check_account_approval
before_action :check_account_suspension
@@ -18,7 +16,7 @@ module AccountControllerConcern
private
def set_account
@account = Account.find_local!(username_param)
@account = Account.find_acct!(username_param)
end
def set_instance_presenter
@@ -26,6 +24,8 @@ module AccountControllerConcern
end
def set_link_headers
return if !@account.local? # TODO: Handle remote users
response.headers['Link'] = LinkHeader.new(
[
webfinger_account_link,

View File

@@ -1,12 +1,12 @@
# frozen_string_literal: true
class HomeController < ApplicationController
before_action :authenticate_user!
before_action :set_referrer_policy_header
before_action :set_initial_state_json
before_action :set_data_for_meta
class ReactController < ApplicationController
before_action :authenticate_user!, only: :react
before_action :set_referrer_policy_header, only: :react
before_action :set_initial_state_json, only: :react
before_action :set_data_for_meta, only: :react
def index
def react
@body_classes = 'app-body'
end
@@ -15,18 +15,6 @@ class HomeController < ApplicationController
def set_data_for_meta
return if find_route_matches
if params[:username].present?
@account = Account.find_local(params[:username])
elsif params[:account_username].present?
@account = Account.find_local(params[:account_username])
if params[:id].present? && !@account.nil?
@status = @account.statuses.find(params[:id])
@stream_entry = @status.stream_entry
@type = @stream_entry.activity_type.downcase
end
end
if request.path.starts_with?('/tags') && params[:tag].present?
@tag = Tag.find_normalized(params[:tag])
end

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
class StatusesController < ApplicationController
class StatusesController < ReactController
include SignatureAuthentication
include Authorization
@@ -8,8 +8,6 @@ class StatusesController < ApplicationController
DESCENDANTS_LIMIT = 60
DESCENDANTS_DEPTH_LIMIT = 20
layout 'public'
before_action :set_account
before_action :set_status
before_action :set_instance_presenter
@@ -32,12 +30,7 @@ class StatusesController < ApplicationController
expires_in 10.seconds, public: true
end
@body_classes = 'with-modals'
set_ancestors
set_descendants
render 'stream_entries/show'
return process(:react)
end
format.json do
@@ -111,7 +104,7 @@ class StatusesController < ApplicationController
end
def set_account
@account = Account.find_local!(params[:account_username])
@account = Account.find_acct!(params[:account_username])
end
def set_ancestors
@@ -174,6 +167,8 @@ class StatusesController < ApplicationController
end
def set_link_headers
return if !@account.local? # TODO: Handle remote accounts
response.headers['Link'] = LinkHeader.new(
[
[account_stream_entry_url(@account, @status.stream_entry, format: 'atom'), [%w(rel alternate), %w(type application/atom+xml)]],
@@ -185,7 +180,7 @@ class StatusesController < ApplicationController
def set_status
@status = @account.statuses.find(params[:id])
@stream_entry = @status.stream_entry
@type = @stream_entry.activity_type.downcase
@type = @stream_entry&.activity_type&.downcase
authorize @status, :show?
rescue GabSocial::NotPermittedError

View File

@@ -15,7 +15,7 @@ class StatusFinder
case recognized_params[:controller]
when 'stream_entries'
StreamEntry.find(recognized_params[:id]).status
when 'home'
when 'statuses'
Status.find(recognized_params[:id])
else
raise ActiveRecord::RecordNotFound
@@ -29,7 +29,7 @@ class StatusFinder
end
def verify_action!
unless recognized_params[:action] == 'show' || recognized_params[:action] == 'index'
unless recognized_params[:action] == 'show'
raise ActiveRecord::RecordNotFound
end
end

View File

@@ -12,6 +12,10 @@ module AccountFinderConcern
find_remote(username, domain) || raise(ActiveRecord::RecordNotFound)
end
def find_acct!(acct)
find_acct(acct) || raise(ActiveRecord::RecordNotFound)
end
def representative
find_local(Setting.site_contact_username.strip.gsub(/\A@/, '')) || Account.local.without_suspended.first
end
@@ -23,6 +27,11 @@ module AccountFinderConcern
def find_remote(username, domain)
AccountFinder.new(username, domain).account
end
def find_acct(acct)
username, domain = acct.split("@")
find_remote(username, domain)
end
end
class AccountFinder

View File

@@ -22,7 +22,7 @@
= render 'tags/meta', tag: @tag, initial_state_json: @initial_state_json
- elsif @stream_entry && @account
= render 'stream_entries/meta', stream_entry: @stream_entry, account: @account
- elsif @account
- elsif @account && @account.local?
= render 'accounts/meta', account: @account, older_url: nil, newer_url: nil
%title= content_for?(:page_title) ? safe_join([yield(:page_title).chomp.html_safe, title], ' - ') : title