From 5c93b7792ced5bc34b4f993541edfd97032067cf Mon Sep 17 00:00:00 2001 From: David Taylor Date: Wed, 26 Jul 2017 19:51:44 +0100 Subject: [PATCH] =?UTF-8?q?Add=20=E2=80=98view=20on=20slack=E2=80=99=20lin?= =?UTF-8?q?k=20to=20transcripts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/locales/server.en.yml | 1 + .../provider/slack/slack_command_controller.rb | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index f23528e..0516f0d 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -96,6 +96,7 @@ en: transcript_error: "Something went wrong when building the transcript, sorry!" post_to_discourse: "Click here to post on Discourse" api_required: "Sorry, this integration isn't setup to support posting transcripts." + view_on_slack: "View on Slack" ####################################### ########## TELEGRAM STRINGS ########### diff --git a/lib/discourse_chat/provider/slack/slack_command_controller.rb b/lib/discourse_chat/provider/slack/slack_command_controller.rb index d8e52af..4052cf1 100644 --- a/lib/discourse_chat/provider/slack/slack_command_controller.rb +++ b/lib/discourse_chat/provider/slack/slack_command_controller.rb @@ -89,10 +89,16 @@ module DiscourseChat::Provider::SlackProvider return error_text unless response.kind_of? Net::HTTPSuccess json = JSON.parse(response.body) return error_text unless json['ok'] + + first_post_link = "https://slack.com/archives/#{slack_channel_id}/p" + first_post_link += json["messages"].reverse.first["ts"].gsub('.','') + post_content = "" post_content << "[quote]\n" + post_content << "[**#{I18n.t('chat_integration.provider.slack.view_on_slack')}**](#{first_post_link})\n" + users_in_transcript = [] last_user = '' json["messages"].reverse.each do |message| @@ -110,8 +116,11 @@ module DiscourseChat::Provider::SlackProvider same_user = last_user == username last_user = username - post_content << "\n![#{username}] " if message["user"] and not same_user - post_content << "**@#{username}:** " if not same_user + if not same_user + post_content << "\n" + post_content << "![#{username}] " if message["user"] + post_content << "**@#{username}:** " + end text = message["text"]