From cef085d0b627317ed0299cb47774abc4f9fdd8b6 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Thu, 6 Jun 2019 10:26:24 +0800 Subject: [PATCH] Fix the build. --- .../provider/telegram/telegram_initializer.rb | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/lib/discourse_chat/provider/telegram/telegram_initializer.rb b/lib/discourse_chat/provider/telegram/telegram_initializer.rb index 6b36afd..21132d9 100644 --- a/lib/discourse_chat/provider/telegram/telegram_initializer.rb +++ b/lib/discourse_chat/provider/telegram/telegram_initializer.rb @@ -1,21 +1,31 @@ # frozen_string_literal: true -event = - if Gem::Version.new(Discourse::VERSION::STRING) > Gem::Version.new("2.3.0.beta8") - :site_setting_changed - else - :site_setting_saved +if Gem::Version.new(Discourse::VERSION::STRING) > Gem::Version.new("2.3.0.beta8") + DiscourseEvent.on(:site_setting_changed) do |setting_name, old_value, new_value| + isEnabledSetting = setting_name == 'chat_integration_telegram_enabled' + isAccessToken = setting_name == 'chat_integration_telegram_access_token' + + if (isEnabledSetting || isAccessToken) + enabled = isEnabledSetting ? new_value == true : SiteSetting.chat_integration_telegram_enabled + + if enabled + Scheduler::Defer.later("Setup Telegram Webhook") do + DiscourseChat::Provider::TelegramProvider.setup_webhook() + end + end + end end +else + DiscourseEvent.on(site_setting_saved) do |sitesetting| + isEnabledSetting = sitesetting.name == 'chat_integration_telegram_enabled' + isAccessToken = sitesetting.name == 'chat_integration_telegram_access_token' -DiscourseEvent.on(event) do |sitesetting| - isEnabledSetting = sitesetting.name == 'chat_integration_telegram_enabled' - isAccessToken = sitesetting.name == 'chat_integration_telegram_access_token' - - if (isEnabledSetting || isAccessToken) - enabled = isEnabledSetting ? sitesetting.value == 't' : SiteSetting.chat_integration_telegram_enabled - if enabled - Scheduler::Defer.later("Setup Telegram Webhook") do - DiscourseChat::Provider::TelegramProvider.setup_webhook() + if (isEnabledSetting || isAccessToken) + enabled = isEnabledSetting ? sitesetting.value == 't' : SiteSetting.chat_integration_telegram_enabled + if enabled + Scheduler::Defer.later("Setup Telegram Webhook") do + DiscourseChat::Provider::TelegramProvider.setup_webhook() + end end end end