Minor refactor.

This commit is contained in:
Guo Xiang Tan 2017-10-10 10:08:26 +08:00
parent 2e69d6a934
commit efddfe1d9b
2 changed files with 14 additions and 16 deletions

View File

@ -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

View File

@ -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