From 364f2ff9aa2b4bf601d68a12bce758aeb5530467 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 4 Feb 2019 04:25:59 +0100 Subject: Add featured hashtags to profiles (#9755) * Add hashtag filter to profiles GET /@:username/tagged/:hashtag GET /api/v1/accounts/:id/statuses?tagged=:hashtag * Display featured hashtags on public profile * Use separate model for featured tags * Update featured hashtag counters on-write * Limit featured tags to 10 --- app/controllers/accounts_controller.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'app/controllers/accounts_controller.rb') diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index f788a9078..6e3a23073 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -57,6 +57,7 @@ class AccountsController < ApplicationController def filtered_statuses default_statuses.tap do |statuses| + statuses.merge!(hashtag_scope) if tag_requested? statuses.merge!(only_media_scope) if media_requested? statuses.merge!(no_replies_scope) unless replies_requested? end @@ -78,12 +79,15 @@ class AccountsController < ApplicationController Status.without_replies end + def hashtag_scope + Status.tagged_with(Tag.find_by(name: params[:tag].downcase)&.id) + end + def set_account @account = Account.find_local!(params[:username]) end def older_url - ::Rails.logger.info("older: max_id #{@statuses.last.id}, url #{pagination_url(max_id: @statuses.last.id)}") pagination_url(max_id: @statuses.last.id) end @@ -92,7 +96,9 @@ class AccountsController < ApplicationController end def pagination_url(max_id: nil, min_id: nil) - if media_requested? + if tag_requested? + short_account_tag_url(@account, params[:tag], max_id: max_id, min_id: min_id) + elsif media_requested? short_account_media_url(@account, max_id: max_id, min_id: min_id) elsif replies_requested? short_account_with_replies_url(@account, max_id: max_id, min_id: min_id) @@ -109,6 +115,10 @@ class AccountsController < ApplicationController request.path.ends_with?('/with_replies') end + def tag_requested? + request.path.ends_with?("/tagged/#{params[:tag]}") + end + def filtered_status_page(params) if params[:min_id].present? filtered_statuses.paginate_by_min_id(PAGE_SIZE, params[:min_id]).reverse -- cgit From 2557cb2f9550f7ab0cd6e6f392642b5249589ed8 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 5 Feb 2019 00:27:18 +0100 Subject: Fix pinned statuses being shown in a featured hashtag (#9971) --- app/controllers/accounts_controller.rb | 2 +- app/controllers/settings/featured_tags_controller.rb | 2 +- app/views/accounts/show.html.haml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'app/controllers/accounts_controller.rb') diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 6e3a23073..cbf1a8287 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -52,7 +52,7 @@ class AccountsController < ApplicationController private def show_pinned_statuses? - [replies_requested?, media_requested?, params[:max_id].present?, params[:min_id].present?].none? + [replies_requested?, media_requested?, tag_requested?, params[:max_id].present?, params[:min_id].present?].none? end def filtered_statuses diff --git a/app/controllers/settings/featured_tags_controller.rb b/app/controllers/settings/featured_tags_controller.rb index 19815e416..3a3241425 100644 --- a/app/controllers/settings/featured_tags_controller.rb +++ b/app/controllers/settings/featured_tags_controller.rb @@ -38,7 +38,7 @@ class Settings::FeaturedTagsController < Settings::BaseController end def set_featured_tags - @featured_tags = current_account.featured_tags.reject(&:new_record?) + @featured_tags = current_account.featured_tags.order(statuses_count: :desc).reject(&:new_record?) end def set_most_used_tags diff --git a/app/views/accounts/show.html.haml b/app/views/accounts/show.html.haml index 23a595205..0da69728f 100644 --- a/app/views/accounts/show.html.haml +++ b/app/views/accounts/show.html.haml @@ -63,7 +63,7 @@ - @endorsed_accounts.each do |account| = account_link_to account - - @account.featured_tags.each do |featured_tag| + - @account.featured_tags.order(statuses_count: :desc).each do |featured_tag| .directory__tag{ class: params[:tag] == featured_tag.name ? 'active' : nil } = link_to short_account_tag_path(@account, featured_tag.tag) do %h4 -- cgit From 5bffb53a763531f6ed1d8e87bacede3ff0938086 Mon Sep 17 00:00:00 2001 From: Takeshi Umeda Date: Tue, 5 Feb 2019 23:11:11 +0900 Subject: Fix it as tagged_request of accounts_controller is not addressable_uri (#9976) --- app/controllers/accounts_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/accounts_controller.rb') diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index cbf1a8287..cad2ecf3f 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -116,7 +116,7 @@ class AccountsController < ApplicationController end def tag_requested? - request.path.ends_with?("/tagged/#{params[:tag]}") + request.path.ends_with?(Addressable::URI.parse("/tagged/#{params[:tag]}").normalize) end def filtered_status_page(params) -- cgit