Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Add a CSS class to the HTML element on background connection error (#10991)

Rafael dos Santos Silvaec35b353a7f6
diff --git a/app/assets/javascripts/discourse/app/initializers/message-bus.js b/app/assets/javascripts/discourse/app/initializers/message-bus.js
index f5dcf26563e..5f44db12731 100644
--- a/app/assets/javascripts/discourse/app/initializers/message-bus.js
+++ b/app/assets/javascripts/discourse/app/initializers/message-bus.js
@@ -5,6 +5,15 @@ import { handleLogoff } from "discourse/lib/ajax";
import { isProduction, isTesting } from "discourse-common/config/environment";
const LONG_POLL_AFTER_UNSEEN_TIME = 1200000; // 20 minutes
+const CONNECTIVITY_ERROR_CLASS = "message-bus-offline";
+
+function updateConnectivityIndicator(stat) {
+ if (stat === "error") {
+ document.documentElement.classList.add(CONNECTIVITY_ERROR_CLASS);
+ } else {
+ document.documentElement.classList.remove(CONNECTIVITY_ERROR_CLASS);
+ }
+}
function ajax(opts) {
if (opts.complete) {
@@ -12,6 +21,7 @@ function ajax(opts) {
opts.complete = function (xhr, stat) {
handleLogoff(xhr);
oldComplete(xhr, stat);
+ updateConnectivityIndicator(stat);
};
} else {
opts.complete = handleLogoff;