From efddfe1d9b9f5ddba7082b56b66d309d354a7215 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Tue, 10 Oct 2017 10:08:26 +0800 Subject: [PATCH] Minor refactor. --- .../provider/slack/slack_command_controller.rb | 18 ++++++++++-------- plugin.rb | 12 ++++-------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/discourse_chat/provider/slack/slack_command_controller.rb b/lib/discourse_chat/provider/slack/slack_command_controller.rb index 3a008b4..b0357c9 100644 --- a/lib/discourse_chat/provider/slack/slack_command_controller.rb +++ b/lib/discourse_chat/provider/slack/slack_command_controller.rb @@ -34,17 +34,20 @@ module DiscourseChat::Provider::SlackProvider provider = DiscourseChat::Provider::SlackProvider::PROVIDER_NAME - channel = DiscourseChat::Channel.with_provider(provider).with_data_value('identifier', channel_id).first + channel = DiscourseChat::Channel.with_provider(provider) + .with_data_value('identifier', channel_id) + .first - # Create channel if doesn't exist - channel ||= DiscourseChat::Channel.create!(provider: provider, data: { identifier: channel_id }) + channel ||= DiscourseChat::Channel.create!( + provider: provider, + data: { identifier: channel_id } + ) if tokens[0] == 'post' - return process_post_request(channel, tokens, params[:channel_id], channel_id, params[:response_url]) + process_post_request(channel, tokens, params[:channel_id], channel_id, params[:response_url]) + else + { text: ::DiscourseChat::Helper.process_command(channel, tokens) } end - - return { text: ::DiscourseChat::Helper.process_command(channel, tokens) } - end def process_post_request(channel, tokens, slack_channel_id, channel_name, response_url) @@ -89,7 +92,6 @@ module DiscourseChat::Provider::SlackProvider end return { text: I18n.t("chat_integration.provider.slack.transcript.loading") } - end def interactive diff --git a/plugin.rb b/plugin.rb index 3068d45..b86f077 100644 --- a/plugin.rb +++ b/plugin.rb @@ -12,19 +12,15 @@ register_asset "stylesheets/chat-integration-admin.scss" require_relative "lib/discourse_chat/provider/slack/slack_enabled_setting_validator" after_initialize do - require_relative "app/initializers/discourse_chat" - DiscourseEvent.on(:post_created) do |post| - if SiteSetting.chat_integration_enabled? - # This will run for every post, even PMs. Don't worry, they're filtered out later. - time = SiteSetting.chat_integration_delay_seconds.seconds - Jobs.enqueue_in(time, :notify_chats, post_id: post.id) - end + on(:post_created) do |post| + # This will run for every post, even PMs. Don't worry, they're filtered out later. + time = SiteSetting.chat_integration_delay_seconds.seconds + Jobs.enqueue_in(time, :notify_chats, post_id: post.id) end add_admin_route 'chat_integration.menu_title', 'chat' DiscourseChat::Provider.mount_engines - end