mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 22:51:24 +08:00
FIX: ensures loading more doesn’t erase filter on browse (#19675)
This commit is contained in:
@ -5,16 +5,14 @@ CATEGORY_CHANNEL_EDITABLE_PARAMS = %i[auto_join_users allow_channel_wide_mention
|
|||||||
|
|
||||||
class Chat::Api::ChatChannelsController < Chat::Api
|
class Chat::Api::ChatChannelsController < Chat::Api
|
||||||
def index
|
def index
|
||||||
options = { status: params[:status] ? ChatChannel.statuses[params[:status]] : nil }.merge(
|
permitted = params.permit(:filter, :limit, :offset, :status)
|
||||||
params.permit(:filter, :limit, :offset),
|
|
||||||
).symbolize_keys!
|
|
||||||
|
|
||||||
options[:offset] = options[:offset].to_i
|
options = { filter: permitted[:filter], limit: (permitted[:limit] || 25).to_i }
|
||||||
options[:limit] = (options[:limit] || 25).to_i
|
options[:offset] = permitted[:offset].to_i
|
||||||
|
options[:status] = ChatChannel.statuses[permitted[:status]] ? permitted[:status] : nil
|
||||||
|
|
||||||
memberships = Chat::ChatChannelMembershipManager.all_for_user(current_user)
|
memberships = Chat::ChatChannelMembershipManager.all_for_user(current_user)
|
||||||
channels = Chat::ChatChannelFetcher.secured_public_channels(guardian, memberships, options)
|
channels = Chat::ChatChannelFetcher.secured_public_channels(guardian, memberships, options)
|
||||||
|
|
||||||
serialized_channels =
|
serialized_channels =
|
||||||
channels.map do |channel|
|
channels.map do |channel|
|
||||||
ChatChannelSerializer.new(
|
ChatChannelSerializer.new(
|
||||||
@ -24,14 +22,10 @@ class Chat::Api::ChatChannelsController < Chat::Api
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
pagination_options =
|
load_more_params = options.merge(offset: options[:offset] + options[:limit]).to_query
|
||||||
options.slice(:offset, :limit, :filter).merge(offset: options[:offset] + options[:limit])
|
load_more_url = URI::HTTP.build(path: "/chat/api/channels", query: load_more_params)
|
||||||
pagination_params = pagination_options.map { |k, v| "#{k}=#{v}" }.join("&")
|
|
||||||
render json: serialized_channels,
|
render json: serialized_channels, root: "channels", meta: { load_more_url: load_more_url }
|
||||||
root: "channels",
|
|
||||||
meta: {
|
|
||||||
load_more_url: "/chat/api/channels?#{pagination_params}",
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
@ -149,6 +149,18 @@ RSpec.describe "Browse page", type: :system, js: true do
|
|||||||
expect(browse_view).to have_no_content(category_channel_4.name)
|
expect(browse_view).to have_no_content(category_channel_4.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when loading more" do
|
||||||
|
fab!(:valid_channel) { Fabricate(:chat_channel, status: :open) }
|
||||||
|
fab!(:invalid_channel) { Fabricate(:chat_channel, status: :closed) }
|
||||||
|
|
||||||
|
it "keeps the filter" do
|
||||||
|
visit("/chat/browse/open")
|
||||||
|
|
||||||
|
expect(page).to have_content(valid_channel.title)
|
||||||
|
expect(page).to have_no_content(invalid_channel.title)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
include_examples "never visible channels" do
|
include_examples "never visible channels" do
|
||||||
before { visit("/chat/browse/open") }
|
before { visit("/chat/browse/open") }
|
||||||
end
|
end
|
||||||
@ -164,6 +176,18 @@ RSpec.describe "Browse page", type: :system, js: true do
|
|||||||
expect(browse_view).to have_no_content(category_channel_4.name)
|
expect(browse_view).to have_no_content(category_channel_4.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when loading more" do
|
||||||
|
fab!(:valid_channel) { Fabricate(:chat_channel, status: :closed) }
|
||||||
|
fab!(:invalid_channel) { Fabricate(:chat_channel, status: :open) }
|
||||||
|
|
||||||
|
it "keeps the filter" do
|
||||||
|
visit("/chat/browse/closed")
|
||||||
|
|
||||||
|
expect(page).to have_content(valid_channel.title)
|
||||||
|
expect(page).to have_no_content(invalid_channel.title)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
include_examples "never visible channels" do
|
include_examples "never visible channels" do
|
||||||
before { visit("/chat/browse/closed") }
|
before { visit("/chat/browse/closed") }
|
||||||
end
|
end
|
||||||
@ -181,6 +205,18 @@ RSpec.describe "Browse page", type: :system, js: true do
|
|||||||
expect(browse_view).to have_content(category_channel_4.name)
|
expect(browse_view).to have_content(category_channel_4.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when loading more" do
|
||||||
|
fab!(:valid_channel) { Fabricate(:chat_channel, status: :archived) }
|
||||||
|
fab!(:invalid_channel) { Fabricate(:chat_channel, status: :open) }
|
||||||
|
|
||||||
|
it "keeps the filter" do
|
||||||
|
visit("/chat/browse/archived")
|
||||||
|
|
||||||
|
expect(page).to have_content(valid_channel.title)
|
||||||
|
expect(page).to have_no_content(invalid_channel.title)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
include_examples "never visible channels" do
|
include_examples "never visible channels" do
|
||||||
before { visit("/chat/browse/archived") }
|
before { visit("/chat/browse/archived") }
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user