2016-11-15 10:56:29 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-29 13:42:08 -05:00
|
|
|
class AccountsController < ApplicationController
|
2016-03-05 17:42:40 -05:00
|
|
|
layout 'public'
|
|
|
|
|
2016-02-29 13:42:08 -05: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-20 19:34:14 -04:00
|
|
|
before_action :set_link_headers
|
2016-02-29 13:42:08 -05:00
|
|
|
|
|
|
|
def show
|
|
|
|
respond_to do |format|
|
2016-09-08 14:36:01 -04:00
|
|
|
format.html do
|
2016-12-03 13:30:13 -05:00
|
|
|
@statuses = @account.statuses.order('id desc').paginate_by_max_id(20, params[:max_id], params[:since_id])
|
2016-12-01 10:26:25 -05:00
|
|
|
@statuses = cache_collection(@statuses, Status)
|
2016-09-08 14:36:01 -04:00
|
|
|
end
|
2016-03-24 08:21:53 -04:00
|
|
|
|
|
|
|
format.atom do
|
2016-12-03 13:30:13 -05:00
|
|
|
@entries = @account.stream_entries.order('id desc').with_includes.paginate_by_max_id(20, params[:max_id], params[:since_id])
|
2016-03-24 08:21:53 -04:00
|
|
|
end
|
2016-02-29 13:42:08 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-06 15:27:58 -04: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-19 09:02:30 -04:00
|
|
|
def followers
|
2016-12-01 10:26:25 -05:00
|
|
|
@followers = @account.followers.order('follows.created_at desc').paginate(page: params[:page], per_page: 12)
|
2016-03-19 09:02:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def following
|
2016-12-01 10:26:25 -05:00
|
|
|
@following = @account.following.order('follows.created_at desc').paginate(page: params[:page], per_page: 12)
|
2016-03-19 09:02:30 -04:00
|
|
|
end
|
|
|
|
|
2016-02-29 13:42:08 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def set_account
|
2016-09-04 15:06:04 -04:00
|
|
|
@account = Account.find_local!(params[:username])
|
2016-02-29 13:42:08 -05:00
|
|
|
end
|
2016-03-05 06:50:59 -05: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-20 19:34:14 -04:00
|
|
|
def set_link_headers
|
2016-11-15 10:56:29 -05: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 06:50:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def webfinger_account_url
|
|
|
|
webfinger_url(resource: "acct:#{@account.acct}@#{Rails.configuration.x.local_domain}")
|
|
|
|
end
|
2016-02-29 13:42:08 -05:00
|
|
|
end
|