From 05756c9a14864655ae6777505a4ee5cfa9b0ee93 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 10 Jan 2020 22:58:16 +0100 Subject: improve status title (#8596) * improve shown status title, useful for atom/rss * use single quotes to satisfy codeclimate * fix tests, make message more pretty * fix tests * fix codestyle * fix codestyle * remove atom_serializer_spec Co-authored-by: Yamagishi Kazutoshi --- app/models/status.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app/models/status.rb') diff --git a/app/models/status.rb b/app/models/status.rb index 1cb381400..670109762 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -194,8 +194,12 @@ class Status < ApplicationRecord def title if destroyed? "#{account.acct} deleted status" + elsif reblog? + preview = sensitive ? '' : text.slice(0, 10).split("\n")[0] + "#{account.acct} shared #{reblog.account.acct}'s: #{preview}" else - reblog? ? "#{account.acct} shared a status by #{reblog.account.acct}" : "New status by #{account.acct}" + preview = sensitive ? '' : text.slice(0, 20).split("\n")[0] + "#{account.acct}: #{preview}" end end -- cgit From 6f8f018e3ed7811998bf2cc10d1b6f0dad54dcef Mon Sep 17 00:00:00 2001 From: ysksn Date: Sat, 11 Jan 2020 19:55:33 +0900 Subject: Refactor StatusThreadingConcern (#9626) * Remove #filter_from_context? * Create scope Status.with_accounts Retrieving AR objects should be their model's scope --- app/models/concerns/status_threading_concern.rb | 12 ++---------- app/models/status.rb | 1 + 2 files changed, 3 insertions(+), 10 deletions(-) (limited to 'app/models/status.rb') diff --git a/app/models/concerns/status_threading_concern.rb b/app/models/concerns/status_threading_concern.rb index 15eb695cd..a0ead1995 100644 --- a/app/models/concerns/status_threading_concern.rb +++ b/app/models/concerns/status_threading_concern.rb @@ -81,12 +81,12 @@ module StatusThreadingConcern end def find_statuses_from_tree_path(ids, account, promote: false) - statuses = statuses_with_accounts(ids).to_a + statuses = Status.with_accounts(ids).to_a account_ids = statuses.map(&:account_id).uniq domains = statuses.map(&:account_domain).compact.uniq relations = relations_map_for_account(account, account_ids, domains) - statuses.reject! { |status| filter_from_context?(status, account, relations) } + statuses.reject! { |status| StatusFilter.new(status, account, relations).filtered? } # Order ancestors/descendants by tree path statuses.sort_by! { |status| ids.index(status.id) } @@ -125,12 +125,4 @@ module StatusThreadingConcern domain_blocking_by_domain: Account.domain_blocking_map_by_domain(domains, account.id), } end - - def statuses_with_accounts(ids) - Status.where(id: ids).includes(:account) - end - - def filter_from_context?(status, account, relations) - StatusFilter.new(status, account, relations).filtered? - end end diff --git a/app/models/status.rb b/app/models/status.rb index 670109762..1e630196b 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -83,6 +83,7 @@ class Status < ApplicationRecord scope :remote, -> { where(local: false).where.not(uri: nil) } scope :local, -> { where(local: true).or(where(uri: nil)) } + scope :with_accounts, ->(ids) { where(id: ids).includes(:account) } scope :without_replies, -> { where('statuses.reply = FALSE OR statuses.in_reply_to_account_id = statuses.account_id') } scope :without_reblogs, -> { where('statuses.reblog_of_id IS NULL') } scope :with_public_visibility, -> { where(visibility: :public) } -- cgit