2019-05-13 10:37:49 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-03 11:08:14 +01:00
|
|
|
# name: discourse-chat-integration
|
2017-06-26 15:08:06 +01:00
|
|
|
# about: This plugin integrates discourse with a number of chat providers
|
|
|
|
# version: 0.1
|
2017-07-03 11:08:14 +01:00
|
|
|
# url: https://github.com/discourse/discourse-chat-integration
|
2017-07-13 13:32:11 +01:00
|
|
|
# author: David Taylor
|
2017-06-26 15:08:06 +01:00
|
|
|
|
2017-07-03 11:08:14 +01:00
|
|
|
enabled_site_setting :chat_integration_enabled
|
2017-06-26 15:08:06 +01:00
|
|
|
|
2017-07-03 22:11:17 +01:00
|
|
|
register_asset "stylesheets/chat-integration-admin.scss"
|
|
|
|
|
2018-11-01 18:03:39 -04:00
|
|
|
register_svg_icon "rocket" if respond_to?(:register_svg_icon)
|
|
|
|
|
2017-07-03 16:28:26 +01:00
|
|
|
# Site setting validators must be loaded before initialize
|
2017-07-13 13:32:11 +01:00
|
|
|
require_relative "lib/discourse_chat/provider/slack/slack_enabled_setting_validator"
|
2017-06-29 17:50:54 +01:00
|
|
|
|
2017-06-26 15:08:06 +01:00
|
|
|
after_initialize do
|
2017-07-13 13:32:11 +01:00
|
|
|
require_relative "app/initializers/discourse_chat"
|
2017-08-01 20:53:39 +01:00
|
|
|
|
2017-10-10 10:08:26 +08:00
|
|
|
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)
|
2017-06-26 19:19:50 +01:00
|
|
|
end
|
|
|
|
|
2017-07-03 15:53:26 +01:00
|
|
|
add_admin_route 'chat_integration.menu_title', 'chat'
|
2017-06-26 19:19:50 +01:00
|
|
|
|
2018-08-20 12:05:59 +01:00
|
|
|
AdminDashboardData.add_problem_check do
|
2018-12-04 11:45:17 +00:00
|
|
|
error = false
|
2018-08-20 12:05:59 +01:00
|
|
|
DiscourseChat::Channel.find_each do |channel|
|
|
|
|
error = true unless channel.error_key.blank?
|
|
|
|
end
|
2018-11-07 23:26:36 +01:00
|
|
|
|
|
|
|
if error
|
|
|
|
base_path = Discourse.respond_to?(:base_path) ? Discourse.base_path : Discourse.base_uri
|
|
|
|
I18n.t("chat_integration.admin_error", base_path: base_path)
|
|
|
|
end
|
2018-08-20 12:05:59 +01:00
|
|
|
end
|
|
|
|
|
2017-07-05 15:03:02 +01:00
|
|
|
DiscourseChat::Provider.mount_engines
|
2017-06-26 15:08:06 +01:00
|
|
|
end
|