Compare commits

...

2 Commits

Author SHA1 Message Date
Matt Jankowski
d6f4575213
Merge bb89b3dc37 into 94bceb8683 2025-07-11 14:05:44 +00:00
Matt Jankowski
bb89b3dc37 Add Status.only_replies scope 2025-07-10 09:35:52 -04:00
4 changed files with 14 additions and 2 deletions

View File

@ -36,7 +36,7 @@ class AnnualReport::Archetype < AnnualReport::Source
end
def replies_count
@replies_count ||= report_statuses.where.not(in_reply_to_id: nil).not_replying_to_account(@account).count
@replies_count ||= report_statuses.only_replies.not_replying_to_account(@account).count
end
def standalone_count

View File

@ -6,7 +6,7 @@ class AnnualReport::TypeDistribution < AnnualReport::Source
type_distribution: {
total: report_statuses.count,
reblogs: report_statuses.only_reblogs.count,
replies: report_statuses.where.not(in_reply_to_id: nil).not_replying_to_account(@account).count,
replies: report_statuses.only_replies.not_replying_to_account(@account).count,
standalone: report_statuses.without_replies.without_reblogs.count,
},
}

View File

@ -120,6 +120,7 @@ class Status < ApplicationRecord
scope :with_accounts, ->(ids) { where(id: ids).includes(:account) }
scope :without_replies, -> { not_reply.or(reply_to_account) }
scope :not_reply, -> { where(reply: false) }
scope :only_replies, -> { where.not(in_reply_to_id: nil) }
scope :only_reblogs, -> { where.not(reblog_of_id: nil) }
scope :only_polls, -> { where.not(poll_id: nil) }
scope :without_polls, -> { where(poll_id: nil) }

View File

@ -376,6 +376,17 @@ RSpec.describe Status do
end
end
describe '.only_replies' do
let!(:status) { Fabricate :status }
let!(:replying_status) { Fabricate :status, thread: Fabricate(:status) }
it 'returns the expected statuses' do
expect(described_class.only_replies)
.to include(replying_status)
.and not_include(status)
end
end
describe '.only_polls' do
let!(:poll_status) { Fabricate :status, poll: Fabricate(:poll) }
let!(:no_poll_status) { Fabricate :status }