From 806199ed4ae23fd165397b41405523e672c7e090 Mon Sep 17 00:00:00 2001 From: multiple creatures Date: Sat, 21 Dec 2019 15:24:34 -0600 Subject: add virtual scopes for `#``self.boosts` (your boosts) & `#``self.home.boosts` (boosts on your home timeline) --- app/controllers/api/v1/timelines/tag_controller.rb | 30 +++++++++++++++++++++- app/models/status.rb | 5 ++-- 2 files changed, 32 insertions(+), 3 deletions(-) (limited to 'app') diff --git a/app/controllers/api/v1/timelines/tag_controller.rb b/app/controllers/api/v1/timelines/tag_controller.rb index 8316d8a9f..7e60e422b 100644 --- a/app/controllers/api/v1/timelines/tag_controller.rb +++ b/app/controllers/api/v1/timelines/tag_controller.rb @@ -30,6 +30,10 @@ class Api::V1::Timelines::TagController < Api::BaseController [] elsif @tag.name.in?(['self.bookmarks', '.self.bookmarks']) Status.reorder(nil).joins(:bookmarks).merge(bookmark_results) + elsif @tag.name.in?(['self.boosts', '.self.boosts']) + reblog_results + elsif @tag.name.in?(['self.home.boosts', '.self.home.boosts']) + home_reblog_results else statuses = tag_timeline_statuses.paginate_by_id( limit_param(DEFAULT_STATUSES_LIMIT), @@ -51,7 +55,7 @@ class Api::V1::Timelines::TagController < Api::BaseController end def bookmark_results - @_results ||= account_bookmarks.paginate_by_max_id( + account_bookmarks.paginate_by_max_id( limit_param(DEFAULT_STATUSES_LIMIT), params[:max_id], params[:since_id] @@ -62,6 +66,30 @@ class Api::V1::Timelines::TagController < Api::BaseController current_account.bookmarks end + def reblog_results + account_reblogs.paginate_by_max_id( + limit_param(DEFAULT_STATUSES_LIMIT), + params[:max_id], + params[:since_id] + ) + end + + def account_reblogs + current_account.statuses.reblogs + end + + def home_reblog_results + account_home_reblogs.paginate_by_max_id( + limit_param(DEFAULT_STATUSES_LIMIT), + params[:max_id], + params[:since_id] + ) + end + + def account_home_reblogs + Status.as_home_timeline(current_account, reblogs_only: true) + end + def insert_pagination_headers set_pagination_headers(next_path, prev_path) end diff --git a/app/models/status.rb b/app/models/status.rb index a47f846a5..f4c90fea2 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -391,9 +391,10 @@ class Status < ApplicationRecord where(language: nil).or where(language: account.chosen_languages) end - def as_home_timeline(account) + def as_home_timeline(account, reblogs_only: false) query = where(account: [account] + account.following, visibility: [:public, :unlisted, :local, :private]) - query = query.without_reblogs if account.present? && account&.user&.hide_boosts + query = query.without_reblogs if !reblogs_only && account.present? && account&.user&.hide_boosts + query = query.reblogs if reblogs_only query end -- cgit