diff --git a/app/controllers/message_threads_controller.rb b/app/controllers/message_threads_controller.rb
index b358dd723..dc670ca08 100644
--- a/app/controllers/message_threads_controller.rb
+++ b/app/controllers/message_threads_controller.rb
@@ -1,5 +1,6 @@
class MessageThreadsController < ApplicationController
before_action :set_message_thread, only: %i[show update]
+ before_action :load_threads, only: %i[index scroll]
def show
authorize @message_thread
@@ -18,24 +19,26 @@ def update
def index
authorize MessageThread
+ end
+
+ def scroll
+ authorize MessageThread
+ end
+ def load_threads
cursor = MessageThreadCollection.init_cursor(search_params[:cursor])
- @message_threads, @next_cursor = MessageThreadCollection.all(
- scope: message_thread_policy_scope.includes(:tags, :box),
- search_permissions: search_permissions,
- query: search_params[:q],
- no_visible_tags: search_params[:no_visible_tags] == '1' && Current.user.admin?,
- cursor: cursor
- )
+ @message_threads, @next_cursor =
+ MessageThreadCollection.all(
+ scope: message_thread_policy_scope.includes(:tags, :box),
+ search_permissions: search_permissions,
+ query: search_params[:q],
+ no_visible_tags: search_params[:no_visible_tags] == "1" && Current.user.admin?,
+ cursor: cursor
+ )
@next_cursor = MessageThreadCollection.serialize_cursor(@next_cursor)
@next_page_params = search_params.to_h.merge(cursor: @next_cursor).merge(format: :turbo_stream)
-
- respond_to do |format|
- format.html # GET
- format.turbo_stream # POST
- end
end
def merge
diff --git a/app/policies/message_thread_policy.rb b/app/policies/message_thread_policy.rb
index 6ba588a6a..f62e29c65 100644
--- a/app/policies/message_thread_policy.rb
+++ b/app/policies/message_thread_policy.rb
@@ -31,6 +31,10 @@ def index?
true
end
+ def scroll?
+ true
+ end
+
def update?
true
end
diff --git a/app/views/message_threads/index.html.erb b/app/views/message_threads/index.html.erb
index 7d3b4a33b..b63624c8e 100644
--- a/app/views/message_threads/index.html.erb
+++ b/app/views/message_threads/index.html.erb
@@ -8,7 +8,7 @@
<% component.with_next_page_area do %>
<%= render Turbo::NextPageAreaComponent.new(
id: @next_cursor,
- url: message_threads_url(@next_page_params)
+ url: scroll_message_threads_url(@next_page_params)
)
%>
<% end %>
diff --git a/app/views/message_threads/index.turbo_stream.erb b/app/views/message_threads/scroll.turbo_stream.erb
similarity index 89%
rename from app/views/message_threads/index.turbo_stream.erb
rename to app/views/message_threads/scroll.turbo_stream.erb
index 46fe76d81..b6aa7ab5b 100644
--- a/app/views/message_threads/index.turbo_stream.erb
+++ b/app/views/message_threads/scroll.turbo_stream.erb
@@ -7,7 +7,7 @@
<%= turbo_stream.append "next_page_area" do %>
<%= render Turbo::NextPageComponent.new(
id:@next_cursor,
- url: message_threads_url(@next_page_params)
+ url: scroll_message_threads_url(@next_page_params)
) %>
<% end %>
<% else %>
diff --git a/config/routes.rb b/config/routes.rb
index e0a106de0..a5d92f322 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -50,7 +50,8 @@
resources :message_threads do
collection do
- post 'merge'
+ post :merge
+ get :scroll
end
resources :messages
end