From c79b1462831856c4fdcb6c75842ed326e3c0984e Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 1 Mar 2017 16:36:06 -0500 Subject: [PATCH] FEATURE: make list controller a bit more extensible --- app/controllers/list_controller.rb | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb index fe8d4d44629..6454cc68b24 100644 --- a/app/controllers/list_controller.rb +++ b/app/controllers/list_controller.rb @@ -106,19 +106,39 @@ class ListController < ApplicationController end end - [:topics_by, :private_messages, :private_messages_sent, :private_messages_unread, :private_messages_archive, :private_messages_group, :private_messages_group_archive].each do |action| + def topics_by + list_opts = build_topic_list_options + target_user = fetch_user_from_params({ include_inactive: current_user.try(:staff?) }, [:user_stat, :user_option]) + list = generate_list_for(action.to_s, target_user, list_opts) + list.more_topics_url = url_for(construct_url_with(:next, list_opts)) + list.prev_topics_url = url_for(construct_url_with(:prev, list_opts)) + respond_with_list(list) + end + + def self.generate_message_route(action) define_method("#{action}") do list_opts = build_topic_list_options target_user = fetch_user_from_params({ include_inactive: current_user.try(:staff?) }, [:user_stat, :user_option]) - guardian.ensure_can_see_private_messages!(target_user.id) unless action == :topics_by + guardian.ensure_can_see_private_messages!(target_user.id) list = generate_list_for(action.to_s, target_user, list_opts) - url_prefix = "topics" unless action == :topics_by + url_prefix = "topics" list.more_topics_url = url_for(construct_url_with(:next, list_opts, url_prefix)) list.prev_topics_url = url_for(construct_url_with(:prev, list_opts, url_prefix)) respond_with_list(list) end end + %i{ + private_messages + private_messages_sent + private_messages_unread + private_messages_archive + private_messages_group + private_messages_group_archive + }.each do |action| + generate_message_route(action) + end + def latest_feed discourse_expires_in 1.minute