From 591ef9f352efd98a85e6d04c0c9072c4c2987527 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 5 Jan 2018 16:17:57 -0600 Subject: Remove utils.ClientCfg and utils.ClientCfgHash (#8041) * remove utils.ClientCfg and utils.ClientCfgHash * remove unused import --- utils/config.go | 14 ++------------ utils/config_test.go | 2 +- utils/license.go | 19 +++++++++++++++++-- 3 files changed, 20 insertions(+), 15 deletions(-) (limited to 'utils') diff --git a/utils/config.go b/utils/config.go index e2622cff9..d75ec732b 100644 --- a/utils/config.go +++ b/utils/config.go @@ -37,12 +37,9 @@ const ( var cfgMutex = &sync.Mutex{} var watcher *fsnotify.Watcher var Cfg *model.Config = &model.Config{} -var CfgDiagnosticId = "" var CfgHash = "" -var ClientCfgHash = "" var CfgFileName string = "" var CfgDisableConfigWatch = false -var ClientCfg map[string]string = map[string]string{} var originalDisableDebugLvl l4g.Level = l4g.DEBUG var siteURL = "" @@ -416,9 +413,6 @@ func LoadGlobalConfig(fileName string) *model.Config { Cfg = config CfgHash = fmt.Sprintf("%x", md5.Sum([]byte(Cfg.ToJson()))) - ClientCfg = getClientConfig(Cfg) - clientCfgJson, _ := json.Marshal(ClientCfg) - ClientCfgHash = fmt.Sprintf("%x", md5.Sum(clientCfgJson)) SetSiteURL(*Cfg.ServiceSettings.SiteURL) @@ -433,11 +427,7 @@ func InvokeGlobalConfigListeners(old, current *model.Config) { } } -func RegenerateClientConfig() { - ClientCfg = getClientConfig(Cfg) -} - -func getClientConfig(c *model.Config) map[string]string { +func GenerateClientConfig(c *model.Config, diagnosticId string) map[string]string { props := make(map[string]string) props["Version"] = model.CurrentVersion @@ -544,7 +534,7 @@ func getClientConfig(c *model.Config) map[string]string { props["EnableUserTypingMessages"] = strconv.FormatBool(*c.ServiceSettings.EnableUserTypingMessages) props["EnableChannelViewedMessages"] = strconv.FormatBool(*c.ServiceSettings.EnableChannelViewedMessages) - props["DiagnosticId"] = CfgDiagnosticId + props["DiagnosticId"] = diagnosticId props["DiagnosticsEnabled"] = strconv.FormatBool(*c.LogSettings.EnableDiagnostics) props["PluginsEnabled"] = strconv.FormatBool(*c.PluginSettings.Enable) diff --git a/utils/config_test.go b/utils/config_test.go index 157fd7fed..8a89940e8 100644 --- a/utils/config_test.go +++ b/utils/config_test.go @@ -299,7 +299,7 @@ func TestGetClientConfig(t *testing.T) { TranslationsPreInit() LoadGlobalConfig("config.json") - configMap := getClientConfig(Cfg) + configMap := GenerateClientConfig(Cfg, "") if configMap["EmailNotificationContentsType"] != *Cfg.EmailSettings.EmailNotificationContentsType { t.Fatal("EmailSettings.EmailNotificationContentsType not exposed to client config") } diff --git a/utils/license.go b/utils/license.go index 54bad45b5..fa731c6b5 100644 --- a/utils/license.go +++ b/utils/license.go @@ -75,7 +75,24 @@ func LoadLicense(licenseBytes []byte) { l4g.Warn(T("utils.license.load_license.invalid.warn")) } +var licenseListeners = map[string]func(){} + +func AddLicenseListener(listener func()) string { + id := model.NewId() + licenseListeners[id] = listener + return id +} + +func RemoveLicenseListener(id string) { + delete(licenseListeners, id) +} + func SetLicense(license *model.License) bool { + defer func() { + for _, listener := range licenseListeners { + listener() + } + }() if license == nil { SetIsLicensed(false) @@ -95,7 +112,6 @@ func SetLicense(license *model.License) bool { licenseValue.Store(license) SetIsLicensed(true) clientLicenseValue.Store(getClientLicense(license)) - ClientCfg = getClientConfig(Cfg) return true } @@ -105,7 +121,6 @@ func SetLicense(license *model.License) bool { func RemoveLicense() { SetLicense(nil) - ClientCfg = getClientConfig(Cfg) } func ValidateLicense(signed []byte) (bool, string) { -- cgit v1.2.3-1-g7c22