From aefbac9c142e6bfefb81e4c7d1a69e9a60a536ab Mon Sep 17 00:00:00 2001
From: David Heinemeier Hansson
Date: Sat, 5 Apr 2025 13:17:42 +0200
Subject: [PATCH] Get rid of single-use and slight awkward model scope
Really dont like that raw Arel.sql wrapping that is required.
---
app/helpers/users_helper.rb | 5 +++++
app/models/user.rb | 1 -
app/views/bubbles/_messages.html.erb | 2 +-
3 files changed, 6 insertions(+), 2 deletions(-)
create mode 100644 app/helpers/users_helper.rb
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
new file mode 100644
index 000000000..58b3e12d6
--- /dev/null
+++ b/app/helpers/users_helper.rb
@@ -0,0 +1,5 @@
+module UsersHelper
+ def prepend_current_user_to(users_scope)
+ users_scope.to_a.prepend(Current.user).uniq
+ end
+end
diff --git a/app/models/user.rb b/app/models/user.rb
index b4d36c032..5b5137ae1 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -18,7 +18,6 @@ class User < ApplicationRecord
normalizes :email_address, with: ->(value) { value.strip.downcase }
scope :alphabetically, -> { order("lower(name)") }
- scope :sorted_with_user_first, ->(user) { order(Arel.sql("users.id != ?, lower(name)", user.id)) }
def initials
name.to_s.scan(/\b\p{L}/).join.upcase
diff --git a/app/views/bubbles/_messages.html.erb b/app/views/bubbles/_messages.html.erb
index 3bc0610d0..85ea86c05 100644
--- a/app/views/bubbles/_messages.html.erb
+++ b/app/views/bubbles/_messages.html.erb
@@ -12,7 +12,7 @@
- <%= render partial: "bubbles/watches/watcher", collection: @bubble.watchers.sorted_with_user_first(Current.user) %>
+ <%= render partial: "bubbles/watches/watcher", collection: prepend_current_user_to(@bubble.watchers.alphabetically) %>
<% end %>