A platform for community discussion. Free, open, simple.
tweaks to related message list generation
Sam5c86e2d74962
diff --git a/lib/suggested_topics_builder.rb b/lib/suggested_topics_builder.rbindex fc7d0cc728d..4d5888db8ea 100644--- a/lib/suggested_topics_builder.rb+++ b/lib/suggested_topics_builder.rb@@ -17,7 +17,8 @@ class SuggestedTopicsBuilderreturn unless results# Only add results if we don't have those topic ids already- results = results.where('topics.id NOT IN (?)', @excluded_topic_ids)+ results = results+ .where('topics.id NOT IN (?)', @excluded_topic_ids).where(visible: true)# If limit suggested to category is enabled, restrict to that category@@ -29,17 +30,27 @@ class SuggestedTopicsBuilderresults.reject! { |topic| @category_topic_ids.include?(topic.id) }unless results.empty?- # Keep track of the ids we've added- @excluded_topic_ids.concat results.map { |r| r.id }++ # protect against dupes+ temp = results+ results = []+ temp.each do |r|+ if !@excluded_topic_ids.include?(r.id)+ results << r+ @excluded_topic_ids << r.id+ end+ end+splice_results(results, priority)endenddef splice_results(results, priority)- if @category_id && priority == :high+ if priority == :ultra_high+ @results.insert 0, *results+ elsif @category_id && priority == :high# Topics from category @category_id need to be first in the list, all others after.-other_category_index = @results.index { |r| r.category_id != @category_id }category_results, other_category_results = results.partition { |r| r.category_id == @category_id }diff --git a/lib/topic_query.rb b/lib/topic_query.rbindex eb631adda7c..aa2ba5f31f0 100644--- a/lib/topic_query.rb+++ b/lib/topic_query.rb@@ -148,20 +148,37 @@ class TopicQuerypm_params =if topic.private_message?- group_ids = topic.topic_allowed_groups+ my_group_ids = topic.topic_allowed_groups.joins("LEFT JOIN group_users guON topic_allowed_groups.group_id = gu.group_id- AND user_id = #{@user.id.to_i}+ AND gu.user_id = #{@user.id.to_i}").where("gu.group_id IS NOT NULL").pluck(:group_id)+ target_group_ids = topic.topic_allowed_groups.pluck(:group_id)++ target_users = topic+ .topic_allowed_users++ if my_group_ids.present?++ # strip out users in groups you already belong to+ target_users = target_users+ .joins("LEFT JOIN group_users gu ON gu.user_id = topic_allowed_users.user_id AND gu.group_id IN (#{sanitize_sql_array(my_group_ids)})")+ .where('gu.group_id IS NULL')+ end++ target_user_ids = target_users+ .where('NOT topic_allowed_users.user_id = ?', @user.id)+ .pluck(:user_id)+{topic: topic,- my_group_ids: group_ids,- target_group_ids: topic.topic_allowed_groups.pluck(:group_id),- target_user_ids: topic.topic_allowed_users.pluck(:user_id) - [@user.id]+ my_group_ids: my_group_ids,+ target_group_ids: target_group_ids,+ target_user_ids: target_user_ids}end@@ -169,27 +186,26 @@ class TopicQueryif @userif topic.private_message?- # we start with related conversations cause they are the most relevant+ builder.add_results(new_messages(+ pm_params.merge(count: builder.results_left)+ )) unless builder.full?++ builder.add_results(unread_messages(+ pm_params.merge(count: builder.results_left)+ )) unless builder.full?+if pm_params[:my_group_ids].present?builder.add_results(related_messages_group(pm_params.merge(count: [3, builder.results_left].max,exclude: builder.excluded_topic_ids)- ))+ ), :ultra_high)elsebuilder.add_results(related_messages_user(pm_params.merge(count: [3, builder.results_left].max,exclude: builder.excluded_topic_ids)- ))+ ), :ultra_high)end- builder.add_results(new_messages(- pm_params.merge(count: builder.results_left)- )) unless builder.full?-- builder.add_results(unread_messages(- pm_params.merge(count: builder.results_left)- )) unless builder.full?-elsebuilder.add_results(unread_results(topic: topic, per_page: builder.results_left), :high)builder.add_results(new_results(topic: topic, per_page: builder.category_results_left)) unless builder.full?@@ -830,16 +846,19 @@ class TopicQueryenddef new_messages(params)- TopicQuery.new_filter(messages_for_groups_or_user(params[:my_group_ids]), Time.at(SiteSetting.min_new_topics_time).to_datetime)+ query = TopicQuery+ .new_filter(messages_for_groups_or_user(params[:my_group_ids]), Time.at(SiteSetting.min_new_topics_time).to_datetime).limit(params[:count])+ queryenddef unread_messages(params)- TopicQuery.unread_filter(+ query = TopicQuery.unread_filter(messages_for_groups_or_user(params[:my_group_ids]),@user&.id,staff: @user&.staff?).limit(params[:count])+ queryenddef related_messages_user(params)