about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-03-15 20:45:27 +0100
committerClaire <claire.github-309c@sitedethib.com>2022-03-15 20:45:27 +0100
commitc79a03b319e17f5ab8c40d065842607de0d76108 (patch)
tree71debfede36bf8985cd5e3e37b6107560c358f57 /app/models
parent80c4db160ecfd201cb82ed320cbe3eb32236ad20 (diff)
parente798c1c64cf417b88379e1d381592a8920fdeeab (diff)
Merge branch 'main' into glitch-soc/merge-upstream
Conflicts:
- `README.md`:
  Upstream changed their README, we have a completely different one.
  Kept our README.
Diffstat (limited to 'app/models')
-rw-r--r--app/models/admin/account_action.rb14
-rw-r--r--app/models/notification.rb24
-rw-r--r--app/models/preview_card.rb4
-rw-r--r--app/models/status.rb4
4 files changed, 37 insertions, 9 deletions
diff --git a/app/models/admin/account_action.rb b/app/models/admin/account_action.rb
index d3be4be3f..850ea6d82 100644
--- a/app/models/admin/account_action.rb
+++ b/app/models/admin/account_action.rb
@@ -22,6 +22,16 @@ class Admin::AccountAction
 
   attr_reader :warning, :send_email_notification, :include_statuses
 
+  alias send_email_notification? send_email_notification
+  alias include_statuses? include_statuses
+
+  def initialize(attributes = {})
+    @send_email_notification = true
+    @include_statuses        = true
+
+    super
+  end
+
   def send_email_notification=(value)
     @send_email_notification = ActiveModel::Type::Boolean.new.cast(value)
   end
@@ -141,11 +151,11 @@ class Admin::AccountAction
   end
 
   def warnable?
-    send_email_notification && target_account.local?
+    send_email_notification? && target_account.local?
   end
 
   def status_ids
-    report.status_ids if with_report? && include_statuses
+    report.status_ids if with_report? && include_statuses?
   end
 
   def reports
diff --git a/app/models/notification.rb b/app/models/notification.rb
index 9bf296386..ba94b54d1 100644
--- a/app/models/notification.rb
+++ b/app/models/notification.rb
@@ -63,13 +63,6 @@ class Notification < ApplicationRecord
 
   scope :without_suspended, -> { joins(:from_account).merge(Account.without_suspended) }
 
-  scope :browserable, ->(exclude_types = [], account_id = nil) {
-    scope = all
-    scope = where(from_account_id: account_id) if account_id.present?
-    scope = scope.where(type: TYPES - exclude_types.map(&:to_sym)) unless exclude_types.empty?
-    scope
-  }
-
   def type
     @type ||= (super || LEGACY_TYPE_CLASS_MAP[activity_type]).to_sym
   end
@@ -90,6 +83,23 @@ class Notification < ApplicationRecord
   end
 
   class << self
+    def browserable(types: [], exclude_types: [], from_account_id: nil)
+      requested_types = begin
+        if types.empty?
+          TYPES
+        else
+          types.map(&:to_sym) & TYPES
+        end
+      end
+
+      requested_types -= exclude_types.map(&:to_sym)
+
+      all.tap do |scope|
+        scope.merge!(where(from_account_id: from_account_id)) if from_account_id.present?
+        scope.merge!(where(type: requested_types)) unless requested_types.size == TYPES.size
+      end
+    end
+
     def preload_cache_collection_target_statuses(notifications, &_block)
       notifications.group_by(&:type).each do |type, grouped_notifications|
         associations = TARGET_STATUS_INCLUDES_BY_TYPE[type]
diff --git a/app/models/preview_card.rb b/app/models/preview_card.rb
index 0f9e23fa1..0d2c32c35 100644
--- a/app/models/preview_card.rb
+++ b/app/models/preview_card.rb
@@ -80,6 +80,10 @@ class PreviewCard < ApplicationRecord
     end
   end
 
+  def requires_review?
+    attributes['trendable'].nil? && (provider.nil? || provider.requires_review?)
+  end
+
   def requires_review_notification?
     attributes['trendable'].nil? && (provider.nil? || provider.requires_review_notification?)
   end
diff --git a/app/models/status.rb b/app/models/status.rb
index ba9d7f0aa..b979252b3 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -300,6 +300,10 @@ class Status < ApplicationRecord
     end
   end
 
+  def requires_review?
+    attributes['trendable'].nil? && account.requires_review?
+  end
+
   def requires_review_notification?
     attributes['trendable'].nil? && account.requires_review_notification?
   end