]> jfr.im git - irc/quakenet/qwebirc.git/commitdiff
add dynamic configuration support
authorChris Porter <redacted>
Sat, 30 Nov 2019 22:02:54 +0000 (22:02 +0000)
committerChris Porter <redacted>
Sat, 30 Nov 2019 22:02:54 +0000 (22:02 +0000)
.gitignore
bin/optionsgen.py
config.py.example
js/irc/ircconnection.js
js/qwebircinterface.js

index d28785d3b424ee65870fb921cd737b1bab95f066..96e0c623232e2bda5d9761876795578330c25249 100644 (file)
@@ -28,3 +28,4 @@ run.sh
 .idea
 *.iml
 .virtualenv
+venv
index 541ce1907a13c31215341fa149810c89e35c14ed..4b9dd875b605f32729bff2dae11982e3b5a9eb0a 100644 (file)
@@ -10,6 +10,7 @@ def get_options():
     baseURL=config.BASE_URL,
     staticBaseURL=config.STATIC_BASE_URL,
     dynamicBaseURL=config.DYNAMIC_BASE_URL,
+    dynamicConfiguration=False,
     validateNickname=False,
     customMenuItems=[]
   )
@@ -34,4 +35,7 @@ def get_options():
   if hasattr(config, "ACCOUNT_WHOIS_COMMAND") and config.ACCOUNT_WHOIS_COMMAND:
     options["accountWhoisCommand"] = config.ACCOUNT_WHOIS_COMMAND
 
+  if hasattr(config, "DYNAMIC_CONFIGURATION") and config.DYNAMIC_CONFIGURATION:
+    options["dynamicConfiguration"] = True
+
   return json.dumps(options)
index d9f7381a704360c0a46a5ea1d9a1779208b83e56..7cf2d795446b961786031ca954bf3fc931379171 100644 (file)
@@ -258,6 +258,11 @@ STATIC_BASE_URL = ""
 #         instances on the same host.
 DYNAMIC_BASE_URL = ""
 
+# OPTION: DYNAMIC_CONFIGURATION
+#         If True then request configuration from the backend when we
+#         initially connect.
+DYNAMIC_CONFIGURATION = False
+
 # OPTION: CONNECTION_RESOLVER
 #         A list of (ip, port) tuples of resolvers to use for looking
 #         the SRV record(s) used for connecting to the name set in
index e866aea1f25741a9c23d00fa4168fca337bcf3f2..19f1cb3919e2d53ccf1711d17541c9c1b6e7f945 100644 (file)
@@ -396,8 +396,11 @@ qwebirc.irc.IRCConnection = new Class({
     r.send("s=" + this.sessionid + "&n=" + this.__subSeqNo);
   },
   connect: function() {
+    qwebirc.ui.requireDynamicConfiguration(this.__innerConnect.bind(this));
+  },
+  __innerConnect: function() {
     this.cacheAvoidance = qwebirc.util.randHexString(16);
-    
+
     var r = this.newRequest("n");
     r.addEvent("complete", function(o) {
       if(!o) {
@@ -416,7 +419,7 @@ qwebirc.irc.IRCConnection = new Class({
       this.__wsSupported = false;
       this.__decideTransport(transports);
     }.bind(this));
-    
+
     var postdata = "nick=" + encodeURIComponent(this.initialNickname);
     if($defined(this.options.serverPassword))
       postdata+="&password=" + encodeURIComponent(this.options.serverPassword);
index 3b23ffe90df84992d9b6763268a4f90e2c06ab83..3418bdd3b64506df04988a75334890d748372638 100644 (file)
@@ -30,6 +30,7 @@ qwebirc.ui.Interface = new Class({
     nickValidation: null,
     dynamicBaseURL: "/",
     staticBaseURL: "/",
+    dynamicConfiguration: false,
     cloak: false,
     logoURL: null,
     accountWhoisCommand: null
@@ -62,9 +63,11 @@ qwebirc.ui.Interface = new Class({
     /* HACK */
     qwebirc.global = {
       dynamicBaseURL: options.dynamicBaseURL,
+      dynamicConfiguration: options.dynamicConfiguration,
       staticBaseURL: options.staticBaseURL,
       baseURL: options.baseURL,
-      nicknameValidator: $defined(options.nickValidation) ? new qwebirc.irc.NicknameValidator(options.nickValidation) : new qwebirc.irc.DummyNicknameValidator()
+      nicknameValidator: $defined(options.nickValidation) ? new qwebirc.irc.NicknameValidator(options.nickValidation) : new qwebirc.irc.DummyNicknameValidator(),
+      dynamicConfigurationLoaded: false
     };
 
     window.addEvent("domready", function() {
@@ -273,3 +276,17 @@ qwebirc.ui.Interface = new Class({
     return channel;
   }
 });
+
+qwebirc.ui.requireDynamicConfiguration = function(callback) {
+  if (!qwebirc.global.dynamicConfiguration || qwebirc.global.dynamicConfigurationLoaded) {
+    callback();
+    return;
+  }
+
+  var r = new Request.JSON({url: qwebirc.global.dynamicBaseURL + "configuration", onSuccess: function(data) {
+    qwebirc.global.dynamicBaseURL = data["dynamicBaseURL"];
+
+    callback();
+  }});
+  r.get();
+};