Merge remote-tracking branch 'upstream/develop' into feature/frontend_refactor
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
# 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
|
||||
|
||||
private
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -5,7 +5,7 @@ import { me } from '../../initial_state';
|
||||
|
||||
const links = [
|
||||
<NavLink key='pr1' className='footer-bar__link' to='/home' data-preview-title-id='column.home'>
|
||||
<i className='tabs-bar__link__icon home'/>
|
||||
<i className='tabs-bar__link__icon home' />
|
||||
<FormattedMessage id='tabs_bar.home' defaultMessage='Home' />
|
||||
</NavLink>,
|
||||
<NavLink key='pr2' className='footer-bar__link' to='/notifications' data-preview-title-id='column.notifications'>
|
||||
@@ -13,14 +13,18 @@ const links = [
|
||||
<NotificationCounter />
|
||||
<FormattedMessage id='tabs_bar.notifications' defaultMessage='Notifications' />
|
||||
</NavLink>,
|
||||
<NavLink key='pr3' className='footer-bar__link' to='/groups' data-preview-title-id='column.groups'>
|
||||
<i className='tabs-bar__link__icon groups'/>
|
||||
<FormattedMessage id='tabs_bar.groups' defaultMessage='Groups' />
|
||||
</NavLink>,
|
||||
<a key='pl5' className='footer-bar__link footer-bar__link--chat' href='https://chat.gab.com' data-preview-title-id='tabs_bar.chat'>
|
||||
<Icon id='comments' className='tabs-bar__link__icon chat' />
|
||||
<FormattedMessage id='tabs_bar.chat' defaultMessage='Chat' />
|
||||
</a>,
|
||||
<a key='pl4' className='footer-bar__link footer-bar__link--trends' href='https://trends.gab.com' data-preview-title-id='tabs_bar.trends'>
|
||||
<i className='tabs-bar__link__icon trends'/>
|
||||
<i className='tabs-bar__link__icon trends' />
|
||||
<FormattedMessage id='tabs_bar.trends' defaultMessage='Trends' />
|
||||
</a>,
|
||||
<NavLink key='pr3' className='footer-bar__link' to='/groups' data-preview-title-id='column.groups'>
|
||||
<i className='tabs-bar__link__icon groups' />
|
||||
<FormattedMessage id='tabs_bar.groups' defaultMessage='Groups' />
|
||||
</NavLink>,
|
||||
]
|
||||
|
||||
export default
|
||||
@@ -32,7 +36,7 @@ class FooterBar extends PureComponent {
|
||||
intl: PropTypes.object.isRequired,
|
||||
}
|
||||
|
||||
render () {
|
||||
render() {
|
||||
const { intl: { formatMessage } } = this.props;
|
||||
|
||||
if (!me) return null;
|
||||
@@ -53,4 +57,4 @@ class FooterBar extends PureComponent {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +82,20 @@ class Header extends ImmutablePureComponent {
|
||||
window.removeEventListener('resize', this.handleResize);
|
||||
}
|
||||
|
||||
onChat = () => {
|
||||
const { account } = this.props;
|
||||
|
||||
axios.post('https://chat.gab.com/private-message', {
|
||||
username: account.get('username'),
|
||||
})
|
||||
.then(function (response) {
|
||||
console.log(response);
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log(error);
|
||||
});
|
||||
}
|
||||
|
||||
handleResize = debounce(() => {
|
||||
this.setState({ isSmallScreen: (window.innerWidth <= 895) });
|
||||
}, 5, {
|
||||
@@ -112,6 +126,8 @@ class Header extends ImmutablePureComponent {
|
||||
menu.push({ text: intl.formatMessage(messages.blocks), to: '/blocks' });
|
||||
menu.push({ text: intl.formatMessage(messages.domain_blocks), to: '/domain_blocks' });
|
||||
} else {
|
||||
menu.push({ text: intl.formatMessage(messages.mention, { name: account.get('acct') }), action: this.props.onMention });
|
||||
|
||||
if (account.getIn(['relationship', 'following'])) {
|
||||
if (account.getIn(['relationship', 'showing_reblogs'])) {
|
||||
menu.push({ text: intl.formatMessage(messages.hideReposts, { name: account.get('username') }), action: this.props.onRepostToggle });
|
||||
|
||||
@@ -167,4 +167,4 @@ noscript {
|
||||
100% {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -3,6 +3,15 @@
|
||||
class ActivityPub::ActorSerializer < ActivityPub::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
# Conditionally serialize Gab image for gab:// URLs
|
||||
def self.serializer_for(object, options)
|
||||
gab_image = object.is_a?(String) and object.start_with?('gab://')
|
||||
if gab_image and options[:serializer] == ActivityPub::ImageSerializer
|
||||
return ActivityPub::GabImageSerializer
|
||||
end
|
||||
super
|
||||
end
|
||||
|
||||
context :security
|
||||
|
||||
context_extensions :manually_approves_followers, :featured, :also_known_as,
|
||||
@@ -83,11 +92,13 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
|
||||
end
|
||||
|
||||
def icon
|
||||
object.avatar
|
||||
return object.avatar if object.avatar?
|
||||
return object.avatar_remote_url if is_gab_avatar?
|
||||
end
|
||||
|
||||
def image
|
||||
object.header
|
||||
return object.header if object.header?
|
||||
return object.header_remote_url if is_gab_header?
|
||||
end
|
||||
|
||||
def public_key
|
||||
@@ -99,11 +110,19 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
|
||||
end
|
||||
|
||||
def avatar_exists?
|
||||
object.avatar?
|
||||
object.avatar? or is_gab_avatar?
|
||||
end
|
||||
|
||||
def header_exists?
|
||||
object.header?
|
||||
object.header? or is_gab_header?
|
||||
end
|
||||
|
||||
def is_gab_avatar?
|
||||
object.avatar_remote_url&.start_with?('gab://') or false
|
||||
end
|
||||
|
||||
def is_gab_header?
|
||||
object.header_remote_url&.start_with?('gab://') or false
|
||||
end
|
||||
|
||||
def manually_approves_followers
|
||||
|
||||
11
app/serializers/activitypub/gab_image_serializer.rb
Normal file
11
app/serializers/activitypub/gab_image_serializer.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::GabImageSerializer < ActivityPub::ImageSerializer
|
||||
def url
|
||||
object
|
||||
.sub('gab://avatar/', 'https://gab.com/media/user/')
|
||||
.sub('gab://header/', 'https://gab.com/media/user/')
|
||||
end
|
||||
|
||||
def media_type; end
|
||||
end
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user