mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 09:10:25 +08:00
FEATURE: push related PMs to take first 3 slots
Previously the related PMs were last meaning you would have to work through all unread to see them. Also amends it so it either asks for related by group OR user not both.
This commit is contained in:
parent
760e09907b
commit
9933059426
2 changed files with 19 additions and 21 deletions
|
@ -22,10 +22,6 @@ class TopicQuery
|
|||
int.call(x) && x.to_i.between?(0, PG_MAX_INT)
|
||||
end
|
||||
|
||||
one_up_to_max_int = lambda do |x|
|
||||
int.call(x) && x.to_i.between?(1, PG_MAX_INT)
|
||||
end
|
||||
|
||||
array_int_or_int = lambda do |x|
|
||||
int.call(x) || (
|
||||
Array === x && x.length > 0 && x.all?(&int)
|
||||
|
@ -173,6 +169,19 @@ class TopicQuery
|
|||
if @user
|
||||
if topic.private_message?
|
||||
|
||||
# we start with related conversations cause they are the most relevant
|
||||
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)
|
||||
))
|
||||
else
|
||||
builder.add_results(related_messages_user(
|
||||
pm_params.merge(count: [3, builder.results_left].max,
|
||||
exclude: builder.excluded_topic_ids)
|
||||
))
|
||||
end
|
||||
|
||||
builder.add_results(new_messages(
|
||||
pm_params.merge(count: builder.results_left)
|
||||
)) unless builder.full?
|
||||
|
@ -187,18 +196,7 @@ class TopicQuery
|
|||
end
|
||||
end
|
||||
|
||||
if topic.private_message?
|
||||
|
||||
builder.add_results(related_messages_group(
|
||||
pm_params.merge(count: [3, builder.results_left].max,
|
||||
exclude: builder.excluded_topic_ids)
|
||||
)) if pm_params[:my_group_ids].present?
|
||||
|
||||
builder.add_results(related_messages_user(
|
||||
pm_params.merge(count: [3, builder.results_left].max,
|
||||
exclude: builder.excluded_topic_ids)
|
||||
))
|
||||
else
|
||||
if !topic.private_message?
|
||||
builder.add_results(random_suggested(topic, builder.results_left, builder.excluded_topic_ids)) unless builder.full?
|
||||
end
|
||||
|
||||
|
|
|
@ -212,9 +212,9 @@ describe TopicQuery do
|
|||
|
||||
it "returns topics in the given category with the given tag" do
|
||||
tagged_topic1 = Fabricate(:topic, category: category1, tags: [tag])
|
||||
tagged_topic2 = Fabricate(:topic, category: category2, tags: [tag])
|
||||
_tagged_topic2 = Fabricate(:topic, category: category2, tags: [tag])
|
||||
tagged_topic3 = Fabricate(:topic, category: category1, tags: [tag, other_tag])
|
||||
no_tags_topic = Fabricate(:topic, category: category1)
|
||||
_no_tags_topic = Fabricate(:topic, category: category1)
|
||||
|
||||
expect(TopicQuery.new(moderator, category: category1.id, tags: [tag.name]).list_latest.topics.map(&:id).sort).to eq([tagged_topic1.id, tagged_topic3.id].sort)
|
||||
expect(TopicQuery.new(moderator, category: category2.id, tags: [other_tag.name]).list_latest.topics.size).to eq(0)
|
||||
|
@ -489,7 +489,7 @@ describe TopicQuery do
|
|||
|
||||
context 'list_unread' do
|
||||
it 'lists topics correctly' do
|
||||
new_topic = Fabricate(:post, user: creator).topic
|
||||
_new_topic = Fabricate(:post, user: creator).topic
|
||||
|
||||
expect(topic_query.list_unread.topics).to eq([])
|
||||
expect(topic_query.list_read.topics).to match_array([fully_read, partially_read])
|
||||
|
@ -694,11 +694,11 @@ describe TopicQuery do
|
|||
read(user, related_by_group_pm, 1)
|
||||
|
||||
expect(TopicQuery.new(user).list_suggested_for(pm_to_group).topics.map(&:id)).to(
|
||||
eq([related_by_group_pm.id, related_by_user_pm.id, pm_to_user.id])
|
||||
eq([related_by_group_pm.id])
|
||||
)
|
||||
|
||||
expect(TopicQuery.new(user).list_suggested_for(pm_to_user).topics.map(&:id)).to(
|
||||
eq([new_pm.id, unread_pm.id, related_by_user_pm.id])
|
||||
eq([related_by_user_pm.id, new_pm.id, unread_pm.id])
|
||||
)
|
||||
|
||||
SiteSetting.enable_personal_messages = false
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue