Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge mastodon main branch #1546

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class Account < ApplicationRecord
include Account::Interactions
include Account::Merging
include Account::Search
include Account::Sensitizes
include Account::Silences
include Account::StatusesSearch
include Account::Suspensions
Expand Down Expand Up @@ -130,7 +131,6 @@ class Account < ApplicationRecord
scope :remote, -> { where.not(domain: nil) }
scope :local, -> { where(domain: nil) }
scope :partitioned, -> { order(Arel.sql('row_number() over (partition by domain)')) }
scope :sensitized, -> { where.not(sensitized_at: nil) }
scope :without_instance_actor, -> { where.not(id: INSTANCE_ACTOR_ID) }
scope :recent, -> { reorder(id: :desc) }
scope :bots, -> { where(actor_type: AUTOMATED_ACTOR_TYPES) }
Expand Down Expand Up @@ -243,18 +243,6 @@ def refresh!
ResolveAccountService.new.call(acct) unless local?
end

def sensitized?
sensitized_at.present?
end

def sensitize!(date = Time.now.utc)
update!(sensitized_at: date)
end

def unsensitize!
update!(sensitized_at: nil)
end

def memorialize!
update!(memorial: true)
end
Expand Down
21 changes: 21 additions & 0 deletions app/models/concerns/account/sensitizes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Account::Sensitizes
extend ActiveSupport::Concern

included do
scope :sensitized, -> { where.not(sensitized_at: nil) }
end

def sensitized?
sensitized_at.present?
end

def sensitize!(date = Time.now.utc)
update!(sensitized_at: date)
end

def unsensitize!
update!(sensitized_at: nil)
end
end
2 changes: 2 additions & 0 deletions app/workers/web/push_notification_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def perform(subscription_id, notification_id)
@subscription = Web::PushSubscription.find(subscription_id)
@notification = Notification.find(notification_id)

return if @notification.updated_at < TTL.ago

# Polymorphically associated activity could have been deleted
# in the meantime, so we have to double-check before proceeding
return unless @notification.activity.present? && @subscription.pushable?(@notification)
Expand Down
18 changes: 18 additions & 0 deletions spec/models/concerns/account/sensitizes_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Account::Sensitizes do
describe 'Scopes' do
describe '.sensitized' do
let(:sensitized_account) { Fabricate :account, sensitized_at: 2.days.ago }

before { Fabricate :account, sensitized_at: false }

it 'returns an array of accounts who are sensitized' do
expect(Account.sensitized)
.to contain_exactly(sensitized_account)
end
end
end
end
Loading