FEATURE: make list controller a bit more extensible

This commit is contained in:
Sam 2017-03-01 16:36:06 -05:00
parent f0b79cf54b
commit c79b146283
1 changed files with 23 additions and 3 deletions

View File

@ -106,19 +106,39 @@ class ListController < ApplicationController
end end
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 define_method("#{action}") do
list_opts = build_topic_list_options list_opts = build_topic_list_options
target_user = fetch_user_from_params({ include_inactive: current_user.try(:staff?) }, [:user_stat, :user_option]) 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) 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.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)) list.prev_topics_url = url_for(construct_url_with(:prev, list_opts, url_prefix))
respond_with_list(list) respond_with_list(list)
end end
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 def latest_feed
discourse_expires_in 1.minute discourse_expires_in 1.minute