Michael K Johnson da9106127a
FEATURE: Enable optional support for threading slack posts (#38)
When creating a new Discourse post from slack with the `post` feature, record the
slack `ts` thread ID for the resulting topic post using an HTML comment to pass
the `ts` through.

When notifying slack of new Discourse posts, record the slack `ts` thread ID in
the post's topic if it has not yet been recorded. (Normally, this will be done
for the topic post, except where notifications are being posted for old topics
before this feature was created.)

Add a new rule filter `thread` which posts threaded responses to slack if there
is a `ts` recorded for the post topic.

Modify the `trigger_notifications` interface to enable other integrations to
implement similar functionality.

Present the `thread` rule in the help text and admin UI only for the slack
providers.

https://meta.discourse.org/t/optionally-threading-posts-to-parent-topic-in-slack-integration/150759
2020-06-15 16:45:25 +01:00

44 lines
1.4 KiB
Ruby

# frozen_string_literal: true
# name: discourse-chat-integration
# about: This plugin integrates discourse with a number of chat providers
# version: 0.1
# url: https://github.com/discourse/discourse-chat-integration
# author: David Taylor
enabled_site_setting :chat_integration_enabled
register_asset "stylesheets/chat-integration-admin.scss"
register_svg_icon "rocket" if respond_to?(:register_svg_icon)
register_svg_icon "fa-arrow-circle-o-right" if respond_to?(:register_svg_icon)
# Site setting validators must be loaded before initialize
require_relative "lib/discourse_chat/provider/slack/slack_enabled_setting_validator"
after_initialize do
require_relative "app/initializers/discourse_chat"
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'
AdminDashboardData.add_problem_check do
error = false
DiscourseChat::Channel.find_each do |channel|
error = true unless channel.error_key.blank?
end
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
end
DiscourseChat::Provider.mount_engines
end