DEV: Change HashtagAutocompleteService to use DiscoursePluginRegistry (#19491)

Follow up to a review in #18937, this commit changes the HashtagAutocompleteService to no longer use class variables to register hashtag data sources or types in context priority order. This is to address multisite concerns, where one site could e.g. have chat disabled and another might not. The filtered plugin registers I added will not be included if the plugin is disabled.
This commit is contained in:
Martin Brennan
2022-12-19 13:46:17 +10:00
committed by GitHub
parent 68d5bdefdd
commit 6b9c0ee554
13 changed files with 230 additions and 124 deletions

View File

@ -5,18 +5,6 @@ require "rails_helper"
describe ChatMessage do
fab!(:message) { Fabricate(:chat_message, message: "hey friend, what's up?!") }
# TODO (martin) Remove this after https://github.com/discourse/discourse/pull/19491 is merged
def register_hashtag_contexts
# This is annoying, but we need to reset the hashtag data sources inbetween
# tests, and since this is normally done in plugin.rb with the plugin API
# there is not an easier way to do this.
HashtagAutocompleteService.register_data_source("channel", Chat::ChatChannelHashtagDataSource)
HashtagAutocompleteService.register_type_in_context("channel", "chat-composer", 200)
HashtagAutocompleteService.register_type_in_context("category", "chat-composer", 100)
HashtagAutocompleteService.register_type_in_context("tag", "chat-composer", 50)
HashtagAutocompleteService.register_type_in_context("channel", "topic-composer", 10)
end
describe ".cook" do
it "does not support HTML tags" do
cooked = ChatMessage.cook("<h1>test</h1>")
@ -258,7 +246,7 @@ describe ChatMessage do
end
it "supports hashtag-autocomplete plugin" do
register_hashtag_contexts
SiteSetting.chat_enabled = true
SiteSetting.enable_experimental_hashtag_autocomplete = true
category = Fabricate(:category)
@ -521,7 +509,7 @@ describe ChatMessage do
fab!(:secure_category) { Fabricate(:private_category, group: group) }
before do
register_hashtag_contexts
SiteSetting.chat_enabled = true
SiteSetting.enable_experimental_hashtag_autocomplete = true
SiteSetting.suppress_secured_categories_from_admin = true
end