mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
@@ -5,6 +5,10 @@ class Chat::ChatChannelHashtagDataSource
|
||||
"comment"
|
||||
end
|
||||
|
||||
def self.type
|
||||
"channel"
|
||||
end
|
||||
|
||||
def self.channel_to_hashtag_item(guardian, channel)
|
||||
HashtagAutocompleteService::HashtagItem.new.tap do |item|
|
||||
item.text = channel.title
|
||||
|
||||
@@ -730,11 +730,11 @@ after_initialize do
|
||||
register_about_stat_group("chat_users") { Chat::Statistics.about_users }
|
||||
|
||||
# Make sure to update spec/system/hashtag_autocomplete_spec.rb when changing this.
|
||||
register_hashtag_data_source("channel", Chat::ChatChannelHashtagDataSource)
|
||||
register_hashtag_type_in_context("channel", "chat-composer", 200)
|
||||
register_hashtag_type_in_context("category", "chat-composer", 100)
|
||||
register_hashtag_type_in_context("tag", "chat-composer", 50)
|
||||
register_hashtag_type_in_context("channel", "topic-composer", 10)
|
||||
register_hashtag_data_source(Chat::ChatChannelHashtagDataSource)
|
||||
register_hashtag_type_priority_for_context("channel", "chat-composer", 200)
|
||||
register_hashtag_type_priority_for_context("category", "chat-composer", 100)
|
||||
register_hashtag_type_priority_for_context("tag", "chat-composer", 50)
|
||||
register_hashtag_type_priority_for_context("channel", "topic-composer", 10)
|
||||
|
||||
Site.markdown_additional_options["chat"] = {
|
||||
limited_pretty_text_features: ChatMessage::MARKDOWN_FEATURES,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -19,15 +19,6 @@ describe "Using #hashtag autocompletion to search for and lookup channels",
|
||||
before do
|
||||
SiteSetting.enable_experimental_hashtag_autocomplete = true
|
||||
|
||||
# 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)
|
||||
|
||||
chat_system_bootstrap(user, [channel1, channel2])
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user