Adding remote follow button
This commit is contained in:
		
							
								
								
									
										10
									
								
								Gemfile.lock
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								Gemfile.lock
									
									
									
									
									
								
							@@ -39,7 +39,8 @@ GEM
 | 
				
			|||||||
      i18n (~> 0.7)
 | 
					      i18n (~> 0.7)
 | 
				
			||||||
      minitest (~> 5.1)
 | 
					      minitest (~> 5.1)
 | 
				
			||||||
      tzinfo (~> 1.1)
 | 
					      tzinfo (~> 1.1)
 | 
				
			||||||
    addressable (2.4.0)
 | 
					    addressable (2.5.0)
 | 
				
			||||||
 | 
					      public_suffix (~> 2.0, >= 2.0.2)
 | 
				
			||||||
    arel (7.1.4)
 | 
					    arel (7.1.4)
 | 
				
			||||||
    ast (2.3.0)
 | 
					    ast (2.3.0)
 | 
				
			||||||
    autoprefixer-rails (6.5.0.2)
 | 
					    autoprefixer-rails (6.5.0.2)
 | 
				
			||||||
@@ -98,7 +99,7 @@ GEM
 | 
				
			|||||||
      warden (~> 1.2.3)
 | 
					      warden (~> 1.2.3)
 | 
				
			||||||
    diff-lcs (1.2.5)
 | 
					    diff-lcs (1.2.5)
 | 
				
			||||||
    docile (1.1.5)
 | 
					    docile (1.1.5)
 | 
				
			||||||
    domain_name (0.5.20160826)
 | 
					    domain_name (0.5.20161129)
 | 
				
			||||||
      unf (>= 0.0.5, < 1.0.0)
 | 
					      unf (>= 0.0.5, < 1.0.0)
 | 
				
			||||||
    doorkeeper (4.2.0)
 | 
					    doorkeeper (4.2.0)
 | 
				
			||||||
      railties (>= 4.2)
 | 
					      railties (>= 4.2)
 | 
				
			||||||
@@ -121,7 +122,7 @@ GEM
 | 
				
			|||||||
      ruby-progressbar (~> 1.4)
 | 
					      ruby-progressbar (~> 1.4)
 | 
				
			||||||
    globalid (0.3.7)
 | 
					    globalid (0.3.7)
 | 
				
			||||||
      activesupport (>= 4.1.0)
 | 
					      activesupport (>= 4.1.0)
 | 
				
			||||||
    goldfinger (1.1.0)
 | 
					    goldfinger (1.1.2)
 | 
				
			||||||
      addressable (~> 2.4)
 | 
					      addressable (~> 2.4)
 | 
				
			||||||
      http (~> 2.0)
 | 
					      http (~> 2.0)
 | 
				
			||||||
      nokogiri (~> 1.6)
 | 
					      nokogiri (~> 1.6)
 | 
				
			||||||
@@ -138,7 +139,7 @@ GEM
 | 
				
			|||||||
    highline (1.7.8)
 | 
					    highline (1.7.8)
 | 
				
			||||||
    hiredis (0.6.1)
 | 
					    hiredis (0.6.1)
 | 
				
			||||||
    htmlentities (4.3.4)
 | 
					    htmlentities (4.3.4)
 | 
				
			||||||
    http (2.0.3)
 | 
					    http (2.1.0)
 | 
				
			||||||
      addressable (~> 2.3)
 | 
					      addressable (~> 2.3)
 | 
				
			||||||
      http-cookie (~> 1.0)
 | 
					      http-cookie (~> 1.0)
 | 
				
			||||||
      http-form_data (~> 1.0.1)
 | 
					      http-form_data (~> 1.0.1)
 | 
				
			||||||
@@ -226,6 +227,7 @@ GEM
 | 
				
			|||||||
      slop (~> 3.4)
 | 
					      slop (~> 3.4)
 | 
				
			||||||
    pry-rails (0.3.4)
 | 
					    pry-rails (0.3.4)
 | 
				
			||||||
      pry (>= 0.9.10)
 | 
					      pry (>= 0.9.10)
 | 
				
			||||||
 | 
					    public_suffix (2.0.4)
 | 
				
			||||||
    puma (3.6.0)
 | 
					    puma (3.6.0)
 | 
				
			||||||
    rabl (0.13.1)
 | 
					    rabl (0.13.1)
 | 
				
			||||||
      activesupport (>= 2.3.14)
 | 
					      activesupport (>= 2.3.14)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -61,10 +61,10 @@ const Header = React.createClass({
 | 
				
			|||||||
    const displayNameHTML = { __html: emojify(escapeTextContentForBrowser(displayName)) };
 | 
					    const displayNameHTML = { __html: emojify(escapeTextContentForBrowser(displayName)) };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
      <div style={{ flex: '0 0 auto', background: '#2f3441', textAlign: 'center', backgroundImage: `url(${account.get('header')})`, backgroundSize: 'cover', backgroundPosition: 'center', position: 'relative' }}>
 | 
					      <div className='account__header' style={{ flex: '0 0 auto', background: '#2f3441', textAlign: 'center', backgroundImage: `url(${account.get('header')})`, backgroundSize: 'cover', backgroundPosition: 'center', position: 'relative' }}>
 | 
				
			||||||
        <div style={{ background: 'rgba(47, 52, 65, 0.9)', padding: '20px 10px' }}>
 | 
					        <div style={{ background: 'rgba(47, 52, 65, 0.9)', padding: '20px 10px' }}>
 | 
				
			||||||
          <a href={account.get('url')} target='_blank' rel='noopener' style={{ display: 'block', color: 'inherit', textDecoration: 'none' }}>
 | 
					          <a href={account.get('url')} target='_blank' rel='noopener' style={{ display: 'block', color: 'inherit', textDecoration: 'none' }}>
 | 
				
			||||||
            <div style={{ width: '90px', margin: '0 auto', marginBottom: '10px' }}>
 | 
					            <div className='account__header__avatar' style={{ width: '90px', margin: '0 auto', marginBottom: '10px' }}>
 | 
				
			||||||
              <img src={account.get('avatar')} alt='' style={{ display: 'block', width: '90px', height: '90px', borderRadius: '90px' }} />
 | 
					              <img src={account.get('avatar')} alt='' style={{ display: 'block', width: '90px', height: '90px', borderRadius: '90px' }} />
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -147,6 +147,12 @@
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@media screen and (max-height: 800px) {
 | 
				
			||||||
 | 
					  .account__header__avatar, .account__header__content {
 | 
				
			||||||
 | 
					    display: none;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.account__header__content {
 | 
					.account__header__content {
 | 
				
			||||||
  word-wrap: break-word;
 | 
					  word-wrap: break-word;
 | 
				
			||||||
  font-weight: 300;
 | 
					  font-weight: 300;
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										47
									
								
								app/controllers/remote_follow_controller.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								app/controllers/remote_follow_controller.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,47 @@
 | 
				
			|||||||
 | 
					# frozen_string_literal: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class RemoteFollowController < ApplicationController
 | 
				
			||||||
 | 
					  layout 'public'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  before_action :set_account
 | 
				
			||||||
 | 
					  before_action :check_account_suspension
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def new
 | 
				
			||||||
 | 
					    @remote_follow = RemoteFollow.new
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def create
 | 
				
			||||||
 | 
					    @remote_follow = RemoteFollow.new(resource_params)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if @remote_follow.valid?
 | 
				
			||||||
 | 
					      resource          = Goldfinger.finger("acct:#{@remote_follow.acct}")
 | 
				
			||||||
 | 
					      redirect_url_link = resource&.link('http://ostatus.org/schema/1.0/subscribe')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if redirect_url_link.nil? || redirect_url_link.template.nil?
 | 
				
			||||||
 | 
					        @remote_follow.errors.add(:acct, I18n.t('remote_follow.missing_resource'))
 | 
				
			||||||
 | 
					        render(:new) && return
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      redirect_to Addressable::Template.new(redirect_url_link.template).expand(uri: "acct:#{@account.username}@#{Rails.configuration.x.local_domain}").to_s
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					      render :new
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					  rescue Goldfinger::Error
 | 
				
			||||||
 | 
					    @remote_follow.errors.add(:acct, I18n.t('remote_follow.missing_resource'))
 | 
				
			||||||
 | 
					    render :new
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def resource_params
 | 
				
			||||||
 | 
					    params.require(:remote_follow).permit(:acct)
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def set_account
 | 
				
			||||||
 | 
					    @account = Account.find_local!(params[:account_username])
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def check_account_suspension
 | 
				
			||||||
 | 
					    head 410 if @account.suspended?
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
							
								
								
									
										13
									
								
								app/models/remote_follow.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								app/models/remote_follow.rb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
				
			|||||||
 | 
					# frozen_string_literal: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class RemoteFollow
 | 
				
			||||||
 | 
					  include ActiveModel::Validations
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  attr_accessor :acct
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  validates :acct, presence: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def initialize(attrs = {})
 | 
				
			||||||
 | 
					    @acct = attrs[:acct]
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
@@ -5,7 +5,10 @@
 | 
				
			|||||||
        = link_to t('accounts.unfollow'), unfollow_account_path(@account), data: { method: :post }, class: 'button'
 | 
					        = link_to t('accounts.unfollow'), unfollow_account_path(@account), data: { method: :post }, class: 'button'
 | 
				
			||||||
      - else
 | 
					      - else
 | 
				
			||||||
        = link_to t('accounts.follow'), follow_account_path(@account), data: { method: :post }, class: 'button'
 | 
					        = link_to t('accounts.follow'), follow_account_path(@account), data: { method: :post }, class: 'button'
 | 
				
			||||||
 | 
					  - else
 | 
				
			||||||
 | 
					    .controls
 | 
				
			||||||
 | 
					      .remote-follow
 | 
				
			||||||
 | 
					        = link_to t('accounts.remote_follow'), account_remote_follow_path(@account), class: 'button'
 | 
				
			||||||
  .avatar= image_tag @account.avatar.url(:original)
 | 
					  .avatar= image_tag @account.avatar.url(:original)
 | 
				
			||||||
  %h1.name
 | 
					  %h1.name
 | 
				
			||||||
    = display_name(@account)
 | 
					    = display_name(@account)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										11
									
								
								app/views/authorize_follow/_card.html.haml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								app/views/authorize_follow/_card.html.haml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
				
			|||||||
 | 
					.account-card
 | 
				
			||||||
 | 
					  .detailed-status__display-name
 | 
				
			||||||
 | 
					    %div
 | 
				
			||||||
 | 
					      = image_tag account.avatar.url(:original), alt: '', width: 48, height: 48, class: 'avatar'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    %span.display-name
 | 
				
			||||||
 | 
					      %strong= display_name(account)
 | 
				
			||||||
 | 
					      %span= "@#{account.acct}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  - unless account.note.blank?
 | 
				
			||||||
 | 
					    .account__header__content= Formatter.instance.simplified_format(account)
 | 
				
			||||||
@@ -5,17 +5,7 @@
 | 
				
			|||||||
  .follow-prompt
 | 
					  .follow-prompt
 | 
				
			||||||
    %h2= t('authorize_follow.prompt_html', self: current_account.username)
 | 
					    %h2= t('authorize_follow.prompt_html', self: current_account.username)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    .account-card
 | 
					    = render partial: 'card', locals: { account: @account }
 | 
				
			||||||
      .detailed-status__display-name
 | 
					 | 
				
			||||||
        %div
 | 
					 | 
				
			||||||
          = image_tag @account.avatar.url(:original), alt: '', width: 48, height: 48, class: 'avatar'
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        %span.display-name
 | 
					 | 
				
			||||||
          %strong= display_name(@account)
 | 
					 | 
				
			||||||
          %span= "@#{@account.acct}"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      - unless @account.note.blank?
 | 
					 | 
				
			||||||
        .account__header__content= Formatter.instance.simplified_format(@account)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  = form_tag authorize_follow_path, method: :post, class: 'simple_form' do
 | 
					  = form_tag authorize_follow_path, method: :post, class: 'simple_form' do
 | 
				
			||||||
    = hidden_field_tag :acct, @account.acct
 | 
					    = hidden_field_tag :acct, @account.acct
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										13
									
								
								app/views/remote_follow/new.html.haml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								app/views/remote_follow/new.html.haml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
				
			|||||||
 | 
					.form-container
 | 
				
			||||||
 | 
					  .follow-prompt
 | 
				
			||||||
 | 
					    %h2= t('remote_follow.prompt')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    = render partial: 'authorize_follow/card', locals: { account: @account }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  = simple_form_for @remote_follow, as: :remote_follow, url: account_remote_follow_path(@account) do |f|
 | 
				
			||||||
 | 
					    = render 'shared/error_messages', object: @remote_follow
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    = f.input :acct, placeholder: t('remote_follow.acct')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    .actions
 | 
				
			||||||
 | 
					      = f.button :button, t('remote_follow.proceed'), type: :submit
 | 
				
			||||||
@@ -14,6 +14,7 @@ en:
 | 
				
			|||||||
    people_followed_by: People whom %{name} follows
 | 
					    people_followed_by: People whom %{name} follows
 | 
				
			||||||
    people_who_follow: People who follow %{name}
 | 
					    people_who_follow: People who follow %{name}
 | 
				
			||||||
    posts: Posts
 | 
					    posts: Posts
 | 
				
			||||||
 | 
					    remote_follow: Remote follow
 | 
				
			||||||
    unfollow: Unfollow
 | 
					    unfollow: Unfollow
 | 
				
			||||||
  application_mailer:
 | 
					  application_mailer:
 | 
				
			||||||
    signature: Mastodon notifications from %{instance}
 | 
					    signature: Mastodon notifications from %{instance}
 | 
				
			||||||
@@ -71,6 +72,11 @@ en:
 | 
				
			|||||||
  pagination:
 | 
					  pagination:
 | 
				
			||||||
    next: Next
 | 
					    next: Next
 | 
				
			||||||
    prev: Prev
 | 
					    prev: Prev
 | 
				
			||||||
 | 
					  remote_follow:
 | 
				
			||||||
 | 
					    acct: Enter your username@domain you want to follow from
 | 
				
			||||||
 | 
					    missing_resource: Could not find the required redirect URL for your account
 | 
				
			||||||
 | 
					    proceed: Proceed to follow
 | 
				
			||||||
 | 
					    prompt: 'You are going to follow:'
 | 
				
			||||||
  settings:
 | 
					  settings:
 | 
				
			||||||
    edit_profile: Edit profile
 | 
					    edit_profile: Edit profile
 | 
				
			||||||
    preferences: Preferences
 | 
					    preferences: Preferences
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -31,6 +31,9 @@ Rails.application.routes.draw do
 | 
				
			|||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    get :remote_follow,  to: 'remote_follow#new'
 | 
				
			||||||
 | 
					    post :remote_follow, to: 'remote_follow#create'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    member do
 | 
					    member do
 | 
				
			||||||
      get :followers
 | 
					      get :followers
 | 
				
			||||||
      get :following
 | 
					      get :following
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user