mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 02:11:08 -06:00
d8d756cd2f
This commit introduces the possibility to stream messages. To allow plugins to use streaming this commit also ships a `ChatSDK` library to allow to interact with few parts of discourse chat. ```ruby ChatSDK::Message.create_with_stream(raw: "test") do |helper| 5.times do |i| is_streaming = helper.stream(raw: "more #{i}") next if !is_streaming sleep 2 end end ``` This commit also introduces all the frontend parts: - messages can now be marked as streaming - when streaming their content will be updated when a new content is appended - a special UI will be showing (a blinking indicator) - a cancel button allows the user to stop the streaming, when cancelled `helper.stream(...)` will return `false`, and the plugin can decide exit early
57 lines
1.8 KiB
Ruby
57 lines
1.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# This custom inflector is needed because of our jobs directory structure.
|
|
# Ideally, we should not prefix our jobs with a `Jobs` namespace but instead
|
|
# have a `Job` suffix to follow the Rails conventions on naming.
|
|
#
|
|
# Based on:
|
|
# https://github.com/rails/rails/blob/75e6c0ac/railties/lib/rails/autoloaders/inflector.rb#L7-L19
|
|
module DiscourseInflector
|
|
@overrides = {}
|
|
|
|
def self.camelize(basename, abspath)
|
|
return basename.camelize if abspath.ends_with?("onceoff.rb")
|
|
return "Jobs" if abspath.ends_with?("jobs/base.rb")
|
|
@overrides[basename] || basename.camelize
|
|
end
|
|
|
|
def self.inflect(overrides)
|
|
@overrides.merge!(overrides)
|
|
end
|
|
end
|
|
|
|
Rails.autoloaders.each do |autoloader|
|
|
autoloader.inflector = DiscourseInflector
|
|
|
|
# We have filenames that do not follow Zeitwerk's camelization convention. Maintain an inflections for these files
|
|
# for now until we decide to fix them one day.
|
|
autoloader.inflector.inflect(
|
|
"canonical_url" => "CanonicalURL",
|
|
"clean_up_unmatched_ips" => "CleanUpUnmatchedIPs",
|
|
"homepage_constraint" => "HomePageConstraint",
|
|
"ip_addr" => "IPAddr",
|
|
"onpdiff" => "ONPDiff",
|
|
"pop3_polling_enabled_setting_validator" => "POP3PollingEnabledSettingValidator",
|
|
"version" => "Discourse",
|
|
"onceoff" => "Jobs",
|
|
"regular" => "Jobs",
|
|
"scheduled" => "Jobs",
|
|
"google_oauth2_authenticator" => "GoogleOAuth2Authenticator",
|
|
"omniauth_strategies" => "OmniAuthStrategies",
|
|
"csrf_token_verifier" => "CSRFTokenVerifier",
|
|
"html" => "HTML",
|
|
"json" => "JSON",
|
|
"ssrf_detector" => "SSRFDetector",
|
|
"http" => "HTTP",
|
|
"gc_stat_instrumenter" => "GCStatInstrumenter",
|
|
"chat_sdk" => "ChatSDK",
|
|
)
|
|
end
|
|
Rails.autoloaders.main.ignore(
|
|
"lib/tasks",
|
|
"lib/generators",
|
|
"lib/freedom_patches",
|
|
"lib/i18n/backend",
|
|
"lib/unicorn_logstash_patch.rb",
|
|
)
|