mirror of
https://github.com/discourse/discourse.git
synced 2025-02-06 03:18:23 +00:00
FIX: group activity's mentions infinite loading (#27070)
In 07ecbb5a3b
we ensure the mentions in a group's activity page worked properly but we missed adding proper support for infinite loading.
The client is using the `before` parameter instead of the `before_post_id` to do the pagination.
This adds support for `before` as well as some tests to ensure it doesn't regress.
I also added tests to the group's activity posts as well since those were missing.
Finally I deleted some unused code (`group.messages_for`) which is not used anymore.
Context - https://meta.discourse.org/t/-/308044/9
This commit is contained in:
parent
a1843104dd
commit
bf80688cd3
@ -229,7 +229,10 @@ class GroupsController < ApplicationController
|
|||||||
guardian.ensure_can_see_group_members!(group)
|
guardian.ensure_can_see_group_members!(group)
|
||||||
|
|
||||||
posts =
|
posts =
|
||||||
group.mentioned_posts_for(guardian, params.permit(:before_post_id, :category_id)).limit(20)
|
group.mentioned_posts_for(
|
||||||
|
guardian,
|
||||||
|
params.permit(:before_post_id, :before, :category_id),
|
||||||
|
).limit(20)
|
||||||
|
|
||||||
response = { posts: serialize_data(posts, GroupPostSerializer) }
|
response = { posts: serialize_data(posts, GroupPostSerializer) }
|
||||||
|
|
||||||
@ -249,7 +252,10 @@ class GroupsController < ApplicationController
|
|||||||
guardian.ensure_can_see_group_members!(group)
|
guardian.ensure_can_see_group_members!(group)
|
||||||
|
|
||||||
@posts =
|
@posts =
|
||||||
group.mentioned_posts_for(guardian, params.permit(:before_post_id, :category_id)).limit(50)
|
group.mentioned_posts_for(
|
||||||
|
guardian,
|
||||||
|
params.permit(:before_post_id, :before, :category_id),
|
||||||
|
).limit(50)
|
||||||
@title =
|
@title =
|
||||||
"#{SiteSetting.title} - #{I18n.t("rss_description.group_mentions", group_name: group.name)}"
|
"#{SiteSetting.title} - #{I18n.t("rss_description.group_mentions", group_name: group.name)}"
|
||||||
@link = Discourse.base_url
|
@link = Discourse.base_url
|
||||||
|
@ -433,29 +433,6 @@ class Group < ActiveRecord::Base
|
|||||||
result.order("posts.created_at desc")
|
result.order("posts.created_at desc")
|
||||||
end
|
end
|
||||||
|
|
||||||
def messages_for(guardian, opts = nil)
|
|
||||||
opts ||= {}
|
|
||||||
|
|
||||||
result =
|
|
||||||
Post
|
|
||||||
.includes(:user, :topic, topic: :category)
|
|
||||||
.references(:posts, :topics, :category)
|
|
||||||
.where("topics.archetype = ?", Archetype.private_message)
|
|
||||||
.where(post_type: Post.types[:regular])
|
|
||||||
.where(
|
|
||||||
"topics.id IN (SELECT topic_id FROM topic_allowed_groups WHERE group_id = ?)",
|
|
||||||
self.id,
|
|
||||||
)
|
|
||||||
|
|
||||||
if opts[:category_id].present?
|
|
||||||
result = result.where("topics.category_id = ?", opts[:category_id].to_i)
|
|
||||||
end
|
|
||||||
|
|
||||||
result = guardian.filter_allowed_categories(result)
|
|
||||||
result = result.where("posts.id < ?", opts[:before_post_id].to_i) if opts[:before_post_id]
|
|
||||||
result.order("posts.created_at desc")
|
|
||||||
end
|
|
||||||
|
|
||||||
def mentioned_posts_for(guardian, opts = nil)
|
def mentioned_posts_for(guardian, opts = nil)
|
||||||
opts ||= {}
|
opts ||= {}
|
||||||
result =
|
result =
|
||||||
@ -473,6 +450,7 @@ class Group < ActiveRecord::Base
|
|||||||
|
|
||||||
result = guardian.filter_allowed_categories(result)
|
result = guardian.filter_allowed_categories(result)
|
||||||
result = result.where("posts.id < ?", opts[:before_post_id].to_i) if opts[:before_post_id]
|
result = result.where("posts.id < ?", opts[:before_post_id].to_i) if opts[:before_post_id]
|
||||||
|
result = result.where("posts.created_at < ?", opts[:before].to_datetime) if opts[:before]
|
||||||
result.order("posts.created_at desc")
|
result.order("posts.created_at desc")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -564,6 +564,38 @@ RSpec.describe GroupsController do
|
|||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
expect(response.parsed_body["posts"].first["id"]).to eq(post.id)
|
expect(response.parsed_body["posts"].first["id"]).to eq(post.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "supports pagination using before (date)" do
|
||||||
|
post = Fabricate(:post)
|
||||||
|
GroupMention.create!(post: post, group: group)
|
||||||
|
|
||||||
|
sign_in(user)
|
||||||
|
get "/groups/#{group.name}/mentions.json"
|
||||||
|
|
||||||
|
expect(response.status).to eq(200)
|
||||||
|
expect(response.parsed_body["posts"].first["id"]).to eq(post.id)
|
||||||
|
|
||||||
|
get "/groups/#{group.name}/mentions.json", params: { before: post.created_at }
|
||||||
|
|
||||||
|
expect(response.status).to eq(200)
|
||||||
|
expect(response.parsed_body["posts"]).to be_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
it "supports pagination using before_post_id" do
|
||||||
|
post = Fabricate(:post)
|
||||||
|
GroupMention.create!(post: post, group: group)
|
||||||
|
|
||||||
|
sign_in(user)
|
||||||
|
get "/groups/#{group.name}/mentions.json"
|
||||||
|
|
||||||
|
expect(response.status).to eq(200)
|
||||||
|
expect(response.parsed_body["posts"].first["id"]).to eq(post.id)
|
||||||
|
|
||||||
|
get "/groups/#{group.name}/mentions.json", params: { before_post_id: post.id }
|
||||||
|
|
||||||
|
expect(response.status).to eq(200)
|
||||||
|
expect(response.parsed_body["posts"]).to be_empty
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#posts" do
|
describe "#posts" do
|
||||||
@ -602,6 +634,36 @@ RSpec.describe GroupsController do
|
|||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
expect(response.parsed_body["posts"].first["id"]).to eq(post.id)
|
expect(response.parsed_body["posts"].first["id"]).to eq(post.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "supports pagination using before (date)" do
|
||||||
|
post = Fabricate(:post, user: user)
|
||||||
|
|
||||||
|
sign_in(user)
|
||||||
|
get "/groups/#{group.name}/posts.json"
|
||||||
|
|
||||||
|
expect(response.status).to eq(200)
|
||||||
|
expect(response.parsed_body["posts"].first["id"]).to eq(post.id)
|
||||||
|
|
||||||
|
get "/groups/#{group.name}/posts.json", params: { before: post.created_at }
|
||||||
|
|
||||||
|
expect(response.status).to eq(200)
|
||||||
|
expect(response.parsed_body["posts"]).to be_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
it "supports pagination using before_post_id" do
|
||||||
|
post = Fabricate(:post, user: user)
|
||||||
|
|
||||||
|
sign_in(user)
|
||||||
|
get "/groups/#{group.name}/posts.json"
|
||||||
|
|
||||||
|
expect(response.status).to eq(200)
|
||||||
|
expect(response.parsed_body["posts"].first["id"]).to eq(post.id)
|
||||||
|
|
||||||
|
get "/groups/#{group.name}/posts.json", params: { before_post_id: post.id }
|
||||||
|
|
||||||
|
expect(response.status).to eq(200)
|
||||||
|
expect(response.parsed_body["posts"]).to be_empty
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#members" do
|
describe "#members" do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user