about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2023-03-05 20:37:42 +0100
committerGitHub <noreply@github.com>2023-03-05 20:37:42 +0100
commitbcbc2a43d4a8913475d47d77cfb5d54b15bfe5cc (patch)
treeae50a1c4344476421eb36fc254ec9bbcfcfc6f8a /app/models
parent6a4be4e96677eb3e1303ddcab8f8b4bea7298453 (diff)
parent0e476f3c4fbbcab9b4895b8abff93075dfd2bf0c (diff)
Merge pull request #2121 from ClearlyClaire/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/models')
-rw-r--r--app/models/account_filter.rb24
-rw-r--r--app/models/poll_vote.rb1
2 files changed, 22 insertions, 3 deletions
diff --git a/app/models/account_filter.rb b/app/models/account_filter.rb
index d27bb46fc..1666ea883 100644
--- a/app/models/account_filter.rb
+++ b/app/models/account_filter.rb
@@ -17,13 +17,13 @@ class AccountFilter
   attr_reader :params
 
   def initialize(params)
-    @params = params
+    @params = params.to_h.symbolize_keys
   end
 
   def results
     scope = Account.includes(:account_stat, user: [:ips, :invite_request]).without_instance_actor.reorder(nil)
 
-    params.each do |key, value|
+    relevant_params.each do |key, value|
       next if key.to_s == 'page'
 
       scope.merge!(scope_for(key, value)) if value.present?
@@ -34,6 +34,16 @@ class AccountFilter
 
   private
 
+  def relevant_params
+    params.tap do |args|
+      args.delete(:origin) if origin_is_remote_and_domain_present?
+    end
+  end
+
+  def origin_is_remote_and_domain_present?
+    params[:origin] == 'remote' && params[:by_domain].present?
+  end
+
   def scope_for(key, value)
     case key.to_s
     when 'origin'
@@ -94,7 +104,15 @@ class AccountFilter
   def order_scope(value)
     case value.to_s
     when 'active'
-      accounts_with_users.left_joins(:account_stat).order(Arel.sql('coalesce(users.current_sign_in_at, account_stats.last_status_at, to_timestamp(0)) desc, accounts.id desc'))
+      accounts_with_users
+        .left_joins(:account_stat)
+        .order(
+          Arel.sql(
+            <<~SQL.squish
+              COALESCE(users.current_sign_in_at, account_stats.last_status_at, to_timestamp(0)) DESC, accounts.id DESC
+            SQL
+          )
+        )
     when 'recent'
       Account.recent
     else
diff --git a/app/models/poll_vote.rb b/app/models/poll_vote.rb
index 00eaedd12..92d74a6db 100644
--- a/app/models/poll_vote.rb
+++ b/app/models/poll_vote.rb
@@ -23,6 +23,7 @@ class PollVote < ApplicationRecord
   after_create_commit :increment_counter_cache
 
   delegate :local?, to: :account
+  delegate :multiple?, :expired?, to: :poll, prefix: true
 
   def object_type
     :vote