mirror of
https://github.com/discourse/discourse.git
synced 2024-12-11 21:16:14 +08:00
07ef828db9
## Why do we need this change?
When loading the ember app, [MessageBus does not start polling immediately](f31f0b70f8/app/assets/javascripts/discourse/app/initializers/message-bus.js (L71-L81)
) and instead waits for `document.readyState` to be `complete`. What this means is that if there are new messages being created while we have yet to start polling, those messages will not be received by the client.
With sidebar being the default navigation menu, the counts derived from `topic-tracking-state.js` on the client side is prominently displayed on every page. Therefore, we want to ensure that we are not dropping any messages on the channels that `topic-tracking-state.js` subscribes to.
## What does this change do?
This includes the `MessageBus.last_id`s for the MessageBus channels which `topic-tracking-state.js` subscribes to as part of the preloaded data when loading a page. The last ids are then used when we subscribe the MessageBus channels so that messages which are published before MessageBus starts polling will not be missed.
## Review Notes
1. See https://github.com/discourse/message_bus#client-support for documentation about subscribing from a given message id.
45 lines
1.5 KiB
Ruby
45 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe TopicTrackingStateItemSerializer do
|
|
fab!(:user) { Fabricate(:user) }
|
|
fab!(:post) { create_post }
|
|
|
|
before do
|
|
SiteSetting.navigation_menu = "legacy"
|
|
SiteSetting.chat_enabled = false if defined?(::Chat)
|
|
end
|
|
|
|
it "serializes topic tracking state reports" do
|
|
report = TopicTrackingState.report(user)
|
|
serialized = described_class.new(report[0], scope: Guardian.new(user), root: false).as_json
|
|
|
|
expect(serialized[:topic_id]).to eq(post.topic_id)
|
|
expect(serialized[:highest_post_number]).to eq(post.topic.highest_post_number)
|
|
expect(serialized[:last_read_post_number]).to eq(nil)
|
|
expect(serialized[:created_at]).to be_present
|
|
expect(serialized[:notification_level]).to eq(nil)
|
|
expect(serialized[:created_in_new_period]).to eq(true)
|
|
expect(serialized[:treat_as_new_topic_start_date]).to be_present
|
|
expect(serialized.has_key?(:tags)).to eq(false)
|
|
end
|
|
|
|
it "includes tags attribute when tags are present" do
|
|
TopicTrackingState.include_tags_in_report = true
|
|
|
|
post.topic.notifier.watch_topic!(post.topic.user_id)
|
|
|
|
DiscourseTagging.tag_topic_by_names(
|
|
post.topic,
|
|
Guardian.new(Discourse.system_user),
|
|
%w[bananas apples],
|
|
)
|
|
|
|
report = TopicTrackingState.report(user)
|
|
serialized = described_class.new(report[0], scope: Guardian.new(user), root: false).as_json
|
|
|
|
expect(serialized[:tags]).to contain_exactly("bananas", "apples")
|
|
ensure
|
|
TopicTrackingState.include_tags_in_report = false
|
|
end
|
|
end
|