Show Private Messages pill as a topic list rather than individual messages.

This commit is contained in:
Robin Ward
2013-08-24 16:58:16 -04:00
parent 2ce59d2585
commit c0b051c9f6
10 changed files with 149 additions and 66 deletions

View File

@ -135,6 +135,17 @@ class TopicQuery
end
end
def list_private_messages(user)
list = private_messages_for(user)
TopicList.new(:private_messages, user, list)
end
def list_private_messages_sent(user)
list = private_messages_for(user)
list = list.where(user_id: user.id)
TopicList.new(:private_messages, user, list)
end
def list_uncategorized
create_list(:uncategorized, unordered: true) do |list|
@ -190,6 +201,22 @@ class TopicQuery
TopicList.new(filter, @user, topics)
end
def private_messages_for(user)
options = @options
options.reverse_merge!(per_page: SiteSetting.topics_per_page)
# Start with a list of all topics
result = Topic.where(id: TopicAllowedUser.where(user_id: user.id).pluck(:topic_id))
result = result.joins("LEFT OUTER JOIN topic_users AS tu ON (topics.id = tu.topic_id AND tu.user_id = #{user.id.to_i})")
result = result.order(TopicQuery.order_nocategory_basic_bumped)
result = result.private_messages
result = result.limit(options[:per_page]) unless options[:limit] == false
result = result.visible if options[:visible] || @user.nil? || @user.regular?
result = result.offset(options[:page].to_i * options[:per_page]) if options[:page]
result
end
# Create results based on a bunch of default options
def default_results(options={})
options.reverse_merge!(@options)