forked from fedi/mastodon
Prettier account and stream entry URLs
This commit is contained in:
parent
33fac87e81
commit
d6ed2eb512
39
app/controllers/statuses_controller.rb
Normal file
39
app/controllers/statuses_controller.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class StatusesController < ApplicationController
|
||||
layout 'public'
|
||||
|
||||
before_action :set_account
|
||||
before_action :set_status
|
||||
before_action :set_link_headers
|
||||
before_action :check_account_suspension
|
||||
|
||||
def show
|
||||
@ancestors = @status.reply? ? cache_collection(@status.ancestors(current_account), Status) : []
|
||||
@descendants = cache_collection(@status.descendants(current_account), Status)
|
||||
|
||||
render 'stream_entries/show'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_account
|
||||
@account = Account.find_local!(params[:account_username])
|
||||
end
|
||||
|
||||
def set_link_headers
|
||||
response.headers['Link'] = LinkHeader.new([[account_stream_entry_url(@account, @status.stream_entry, format: 'atom'), [%w(rel alternate), %w(type application/atom+xml)]]])
|
||||
end
|
||||
|
||||
def set_status
|
||||
@status = @account.statuses.find(params[:id])
|
||||
@stream_entry = @status.stream_entry
|
||||
@type = @stream_entry.activity_type.downcase
|
||||
|
||||
raise ActiveRecord::RecordNotFound unless @status.permitted?(current_account)
|
||||
end
|
||||
|
||||
def check_account_suspension
|
||||
gone if @account.suspended?
|
||||
end
|
||||
end
|
|
@ -82,7 +82,9 @@ class TagManager
|
|||
|
||||
case target.object_type
|
||||
when :person
|
||||
account_url(target)
|
||||
short_account_url(target)
|
||||
when :note, :comment, :activity
|
||||
short_account_status_url(target.account, target)
|
||||
else
|
||||
account_stream_entry_url(target.account, target.stream_entry)
|
||||
end
|
||||
|
|
|
@ -64,7 +64,7 @@ class ProcessInteractionService < BaseService
|
|||
end
|
||||
|
||||
def mentions_account?(xml, account)
|
||||
xml.xpath('/xmlns:entry/xmlns:link[@rel="mentioned"]', xmlns: TagManager::XMLNS).each { |mention_link| return true if mention_link.attribute('href').value == TagManager.instance.url_for(account) }
|
||||
xml.xpath('/xmlns:entry/xmlns:link[@rel="mentioned"]', xmlns: TagManager::XMLNS).each { |mention_link| return true if [TagManager.instance.uri_for(account), TagManager.instance.url_for(account)].include?(mention_link.attribute('href').value) }
|
||||
false
|
||||
end
|
||||
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
.account__header__content.p-note.emojify= Formatter.instance.simplified_format(@account)
|
||||
|
||||
.details-counters
|
||||
.counter{ class: active_nav_class(account_url(@account)) }
|
||||
= link_to account_url(@account), class: 'u-url u-uid' do
|
||||
.counter{ class: active_nav_class(short_account_url(@account)) }
|
||||
= link_to short_account_url(@account), class: 'u-url u-uid' do
|
||||
%span.counter-label= t('accounts.posts')
|
||||
%span.counter-number= number_with_delimiter @account.statuses.count
|
||||
.counter{ class: active_nav_class(following_account_url(@account)) }
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
- centered ||= include_threads && !is_predecessor && !is_successor
|
||||
|
||||
- if status.reply? && include_threads
|
||||
= render partial: 'status', collection: @ancestors, as: :status, locals: { is_predecessor: true }
|
||||
= render partial: 'stream_entries/status', collection: @ancestors, as: :status, locals: { is_predecessor: true }
|
||||
|
||||
.entry{ class: entry_classes(status, is_predecessor, is_successor, include_threads) }
|
||||
- if status.reblog?
|
||||
|
@ -19,4 +19,4 @@
|
|||
= render partial: centered ? 'stream_entries/detailed_status' : 'stream_entries/simple_status', locals: { status: proper_status(status) }
|
||||
|
||||
- if include_threads
|
||||
= render partial: 'status', collection: @descendants, as: :status, locals: { is_successor: true }
|
||||
= render partial: 'stream_entries/status', collection: @descendants, as: :status, locals: { is_successor: true }
|
||||
|
|
|
@ -24,4 +24,4 @@
|
|||
= render partial: 'shared/landing_strip', locals: { account: @stream_entry.account }
|
||||
|
||||
.activity-stream.activity-stream-headless
|
||||
= render partial: @type, locals: { @type.to_sym => @stream_entry.activity, include_threads: true }
|
||||
= render partial: "stream_entries/#{@type}", locals: { @type.to_sym => @stream_entry.activity, include_threads: true }
|
||||
|
|
|
@ -24,6 +24,8 @@ Rails.application.routes.draw do
|
|||
confirmations: 'auth/confirmations',
|
||||
}
|
||||
|
||||
get '/users/:username', to: redirect('/@%{username}'), constraints: { format: :html }
|
||||
|
||||
resources :accounts, path: 'users', only: [:show], param: :username do
|
||||
resources :stream_entries, path: 'updates', only: [:show] do
|
||||
member do
|
||||
|
@ -43,6 +45,9 @@ Rails.application.routes.draw do
|
|||
end
|
||||
end
|
||||
|
||||
get '/@:username', to: 'accounts#show', as: :short_account
|
||||
get '/@:account_username/:id', to: 'statuses#show', as: :short_account_status
|
||||
|
||||
namespace :settings do
|
||||
resource :profile, only: [:show, :update]
|
||||
resource :preferences, only: [:show, :update]
|
||||
|
@ -189,8 +194,5 @@ Rails.application.routes.draw do
|
|||
|
||||
root 'home#index'
|
||||
|
||||
get '/:username', to: redirect('/users/%{username}')
|
||||
get '/:username/:id', to: redirect('/users/%{username}/updates/%{id}')
|
||||
|
||||
match '*unmatched_route', via: :all, to: 'application#raise_not_found'
|
||||
end
|
||||
|
|
|
@ -6,7 +6,6 @@ RSpec.describe Api::SalmonController, type: :controller do
|
|||
let(:account) { Fabricate(:user, account: Fabricate(:account, username: 'catsrgr8')).account }
|
||||
|
||||
before do
|
||||
stub_request(:post, "https://pubsubhubbub.superfeedr.com/").to_return(:status => 200, :body => "", :headers => {})
|
||||
stub_request(:get, "https://quitter.no/.well-known/host-meta").to_return(request_fixture('.host-meta.txt'))
|
||||
stub_request(:get, "https://quitter.no/.well-known/webfinger?resource=acct:gargron@quitter.no").to_return(request_fixture('webfinger.txt'))
|
||||
stub_request(:get, "https://quitter.no/api/statuses/user_timeline/7477.atom").to_return(request_fixture('feed.txt'))
|
||||
|
|
Loading…
Reference in a new issue