From 6344b55b447b3e7a033f91ccbb49bd6e3da4bb58 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Mon, 18 Jul 2022 22:26:13 +0200 Subject: [PATCH] Move public & list timelines into `TimelineController` --- app/controllers/list_controller.rb | 15 ------------ app/controllers/public_controller.rb | 14 ----------- app/controllers/timeline_controller.rb | 23 +++++++++++++++++++ .../{list/index.haml => timeline/list.haml} | 0 .../index.js.erb => timeline/list.js.erb} | 0 .../index.haml => timeline/public.haml} | 0 .../index.js.erb => timeline/public.js.erb} | 0 config/routes.rb | 4 ++-- 8 files changed, 25 insertions(+), 31 deletions(-) delete mode 100644 app/controllers/list_controller.rb delete mode 100644 app/controllers/public_controller.rb rename app/views/{list/index.haml => timeline/list.haml} (100%) rename app/views/{list/index.js.erb => timeline/list.js.erb} (100%) rename app/views/{public/index.haml => timeline/public.haml} (100%) rename app/views/{public/index.js.erb => timeline/public.js.erb} (100%) diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb deleted file mode 100644 index 0c305dee..00000000 --- a/app/controllers/list_controller.rb +++ /dev/null @@ -1,15 +0,0 @@ -class ListController < ApplicationController - before_action :authenticate_user! - - def index - @list = current_user.lists.find_by_name!(params[:list_name]) - @timeline = @list.cursored_timeline(last_id: params[:last_id]) - @timeline_last_id = @timeline.map(&:id).min - @more_data_available = !@list.cursored_timeline(last_id: @timeline_last_id, size: 1).count.zero? - - respond_to do |format| - format.html - format.js { render layout: false } - end - end -end diff --git a/app/controllers/public_controller.rb b/app/controllers/public_controller.rb deleted file mode 100644 index c5fc1143..00000000 --- a/app/controllers/public_controller.rb +++ /dev/null @@ -1,14 +0,0 @@ -class PublicController < ApplicationController - before_action :authenticate_user! - - def index - @timeline = Answer.cursored_public_timeline(last_id: params[:last_id]) - @timeline_last_id = @timeline.map(&:id).min - @more_data_available = !Answer.cursored_public_timeline(last_id: @timeline_last_id, size: 1).count.zero? - - respond_to do |format| - format.html - format.js { render layout: false } - end - end -end diff --git a/app/controllers/timeline_controller.rb b/app/controllers/timeline_controller.rb index b0eb549d..5fe3731a 100644 --- a/app/controllers/timeline_controller.rb +++ b/app/controllers/timeline_controller.rb @@ -13,4 +13,27 @@ class TimelineController < ApplicationController format.js { render layout: false } end end + + def list + @list = current_user.lists.find_by_name!(params[:list_name]) + @timeline = @list.cursored_timeline(last_id: params[:last_id]) + @timeline_last_id = @timeline.map(&:id).min + @more_data_available = !@list.cursored_timeline(last_id: @timeline_last_id, size: 1).count.zero? + + respond_to do |format| + format.html + format.js { render layout: false } + end + end + + def public + @timeline = Answer.cursored_public_timeline(last_id: params[:last_id]) + @timeline_last_id = @timeline.map(&:id).min + @more_data_available = !Answer.cursored_public_timeline(last_id: @timeline_last_id, size: 1).count.zero? + + respond_to do |format| + format.html + format.js { render layout: false } + end + end end diff --git a/app/views/list/index.haml b/app/views/timeline/list.haml similarity index 100% rename from app/views/list/index.haml rename to app/views/timeline/list.haml diff --git a/app/views/list/index.js.erb b/app/views/timeline/list.js.erb similarity index 100% rename from app/views/list/index.js.erb rename to app/views/timeline/list.js.erb diff --git a/app/views/public/index.haml b/app/views/timeline/public.haml similarity index 100% rename from app/views/public/index.haml rename to app/views/timeline/public.haml diff --git a/app/views/public/index.js.erb b/app/views/timeline/public.js.erb similarity index 100% rename from app/views/public/index.js.erb rename to app/views/timeline/public.js.erb diff --git a/config/routes.rb b/config/routes.rb index ddd11311..6f88c2ca 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -138,8 +138,8 @@ Rails.application.routes.draw do end match '/discover', to: 'discover#index', via: :get, as: :discover - match '/public', to: 'public#index', via: :get, as: :public_timeline if APP_CONFIG.dig(:features, :public, :enabled) - match '/list/:list_name', to: 'list#index', via: :get, as: :list_timeline + match '/public', to: 'timeline#public', via: :get, as: :public_timeline if APP_CONFIG.dig(:features, :public, :enabled) + match '/list/:list_name', to: 'timeline#list', via: :get, as: :list_timeline match '/notifications(/:type)', to: 'notifications#index', via: :get, as: :notifications, defaults: {type: 'new'}