2016-11-16 02:56:29 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-01 05:42:08 +11:00
|
|
|
class AccountsController < ApplicationController
|
2016-03-06 09:42:40 +11:00
|
|
|
layout 'public'
|
|
|
|
|
2016-03-01 05:42:08 +11:00
|
|
|
before_action :set_account
|
Fix #24 - Thread resolving for remote statuses
This is a big one, so let me enumerate:
Accounts as well as stream entry pages now contain Link headers that
reference the Atom feed and Webfinger URL for the former and Atom entry
for the latter. So you only need to HEAD those resources to get that
information, no need to download and parse HTML <link>s.
ProcessFeedService will now queue ThreadResolveWorker for each remote
status that it cannot find otherwise. Furthermore, entries are now
processed in reverse order (from bottom to top) in case a newer entry
references a chronologically previous one.
ThreadResolveWorker uses FetchRemoteStatusService to obtain a status
and attach the child status it was queued for to it.
FetchRemoteStatusService looks up the URL, first with a HEAD, tests
if it's an Atom feed, in which case it processes it directly. Next
for Link headers to the Atom feed, in which case that is fetched
and processed. Lastly if it's HTML, it is checked for <link>s to the Atom
feed, and if such is found, that is fetched and processed. The account for
the status is derived from author/name attribute in the XML and the hostname
in the URL (domain). FollowRemoteAccountService and ProcessFeedService
are used.
This means that potentially threads are resolved recursively until a dead-end
is encountered, however it is performed asynchronously over background jobs,
so it should be ok.
2016-09-21 09:34:14 +10:00
|
|
|
before_action :set_link_headers
|
2016-12-07 04:03:30 +11:00
|
|
|
before_action :authenticate_user!, only: [:follow, :unfollow]
|
|
|
|
before_action :check_account_suspension
|
2016-03-01 05:42:08 +11:00
|
|
|
|
|
|
|
def show
|
|
|
|
respond_to do |format|
|
2016-09-09 04:36:01 +10:00
|
|
|
format.html do
|
2016-12-22 06:00:18 +11:00
|
|
|
@statuses = @account.statuses.permitted_for(@account, current_account).order('id desc').paginate_by_max_id(20, params[:max_id], params[:since_id])
|
2016-12-02 02:26:25 +11:00
|
|
|
@statuses = cache_collection(@statuses, Status)
|
2016-09-09 04:36:01 +10:00
|
|
|
end
|
2016-03-24 23:21:53 +11:00
|
|
|
|
|
|
|
format.atom do
|
2017-04-07 13:56:56 +10:00
|
|
|
@entries = @account.stream_entries.order('id desc').where(hidden: false).with_includes.paginate_by_max_id(20, params[:max_id], params[:since_id])
|
|
|
|
render xml: AtomSerializer.render(AtomSerializer.new.feed(@account, @entries.to_a))
|
2016-03-24 23:21:53 +11:00
|
|
|
end
|
2017-02-06 20:19:05 +11:00
|
|
|
|
|
|
|
format.activitystreams2
|
2016-03-01 05:42:08 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-07 06:27:58 +11:00
|
|
|
def follow
|
|
|
|
FollowService.new.call(current_user.account, @account.acct)
|
|
|
|
redirect_to account_path(@account)
|
|
|
|
end
|
|
|
|
|
|
|
|
def unfollow
|
|
|
|
UnfollowService.new.call(current_user.account, @account)
|
|
|
|
redirect_to account_path(@account)
|
|
|
|
end
|
|
|
|
|
2016-03-20 00:02:30 +11:00
|
|
|
def followers
|
2016-12-02 02:26:25 +11:00
|
|
|
@followers = @account.followers.order('follows.created_at desc').paginate(page: params[:page], per_page: 12)
|
2016-03-20 00:02:30 +11:00
|
|
|
end
|
|
|
|
|
|
|
|
def following
|
2016-12-02 02:26:25 +11:00
|
|
|
@following = @account.following.order('follows.created_at desc').paginate(page: params[:page], per_page: 12)
|
2016-03-20 00:02:30 +11:00
|
|
|
end
|
|
|
|
|
2016-03-01 05:42:08 +11:00
|
|
|
private
|
|
|
|
|
|
|
|
def set_account
|
2016-09-05 05:06:04 +10:00
|
|
|
@account = Account.find_local!(params[:username])
|
2016-03-01 05:42:08 +11:00
|
|
|
end
|
2016-03-05 22:50:59 +11:00
|
|
|
|
Fix #24 - Thread resolving for remote statuses
This is a big one, so let me enumerate:
Accounts as well as stream entry pages now contain Link headers that
reference the Atom feed and Webfinger URL for the former and Atom entry
for the latter. So you only need to HEAD those resources to get that
information, no need to download and parse HTML <link>s.
ProcessFeedService will now queue ThreadResolveWorker for each remote
status that it cannot find otherwise. Furthermore, entries are now
processed in reverse order (from bottom to top) in case a newer entry
references a chronologically previous one.
ThreadResolveWorker uses FetchRemoteStatusService to obtain a status
and attach the child status it was queued for to it.
FetchRemoteStatusService looks up the URL, first with a HEAD, tests
if it's an Atom feed, in which case it processes it directly. Next
for Link headers to the Atom feed, in which case that is fetched
and processed. Lastly if it's HTML, it is checked for <link>s to the Atom
feed, and if such is found, that is fetched and processed. The account for
the status is derived from author/name attribute in the XML and the hostname
in the URL (domain). FollowRemoteAccountService and ProcessFeedService
are used.
This means that potentially threads are resolved recursively until a dead-end
is encountered, however it is performed asynchronously over background jobs,
so it should be ok.
2016-09-21 09:34:14 +10:00
|
|
|
def set_link_headers
|
2016-11-16 02:56:29 +11:00
|
|
|
response.headers['Link'] = LinkHeader.new([[webfinger_account_url, [%w(rel lrdd), %w(type application/xrd+xml)]], [account_url(@account, format: 'atom'), [%w(rel alternate), %w(type application/atom+xml)]]])
|
2016-03-05 22:50:59 +11:00
|
|
|
end
|
|
|
|
|
|
|
|
def webfinger_account_url
|
2017-04-11 06:58:06 +10:00
|
|
|
webfinger_url(resource: @account.to_webfinger_s)
|
2016-03-05 22:50:59 +11:00
|
|
|
end
|
2016-12-07 04:03:30 +11:00
|
|
|
|
|
|
|
def check_account_suspension
|
2017-03-20 06:03:28 +11:00
|
|
|
gone if @account.suspended?
|
2016-12-07 04:03:30 +11:00
|
|
|
end
|
2016-03-01 05:42:08 +11:00
|
|
|
end
|