parent
91c5426455
commit
8f47f6a7ec
@ -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
|
@ -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
|
@ -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)
|
@ -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
|
Loading…
Reference in new issue