about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-03-22 19:26:22 +0100
committerEugen Rochko <eugen@zeonfederated.com>2017-03-22 19:55:14 +0100
commitd6ed2eb512f09600d7cd8150bb9b547442a9d68b (patch)
treef7f2fd55bf288b5380732b03460750e2ba519ec1 /app
parent33fac87e81918e69c781ce07ca339f23a7ac593f (diff)
Prettier account and stream entry URLs
Diffstat (limited to 'app')
-rw-r--r--app/controllers/statuses_controller.rb39
-rw-r--r--app/lib/tag_manager.rb4
-rw-r--r--app/services/process_interaction_service.rb2
-rw-r--r--app/views/accounts/_header.html.haml4
-rw-r--r--app/views/stream_entries/_status.html.haml4
-rw-r--r--app/views/stream_entries/show.html.haml2
6 files changed, 48 insertions, 7 deletions
diff --git a/app/controllers/statuses_controller.rb b/app/controllers/statuses_controller.rb
new file mode 100644
index 000000000..696bb4f52
--- /dev/null
+++ b/app/controllers/statuses_controller.rb
@@ -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
diff --git a/app/lib/tag_manager.rb b/app/lib/tag_manager.rb
index 9fef70fda..34c3edc4b 100644
--- a/app/lib/tag_manager.rb
+++ b/app/lib/tag_manager.rb
@@ -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
diff --git a/app/services/process_interaction_service.rb b/app/services/process_interaction_service.rb
index c74ff9e22..d5f7b4b3c 100644
--- a/app/services/process_interaction_service.rb
+++ b/app/services/process_interaction_service.rb
@@ -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
 
diff --git a/app/views/accounts/_header.html.haml b/app/views/accounts/_header.html.haml
index f575e855e..e35b08317 100644
--- a/app/views/accounts/_header.html.haml
+++ b/app/views/accounts/_header.html.haml
@@ -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)) }
diff --git a/app/views/stream_entries/_status.html.haml b/app/views/stream_entries/_status.html.haml
index f70e2c890..cdd0dde3b 100644
--- a/app/views/stream_entries/_status.html.haml
+++ b/app/views/stream_entries/_status.html.haml
@@ -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 }
diff --git a/app/views/stream_entries/show.html.haml b/app/views/stream_entries/show.html.haml
index 7a1afdd96..c109ff4b8 100644
--- a/app/views/stream_entries/show.html.haml
+++ b/app/views/stream_entries/show.html.haml
@@ -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 }