FIX: Use hashtags in channel archive PMs if available (#19859)

If the enable_experimental_hashtag_autocomplete setting is
enabled, then we should autolink hashtag references to the
archived channels (e.g. #blah::channel) for a nicer UX, and
just show the channel name if not (since doing #channelName
can lead to weird inconsistent results).
This commit is contained in:
Martin Brennan 2023-01-16 10:20:37 +10:00 committed by GitHub
parent d59ed1cbfe
commit 2eb0a300b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 4 deletions

View File

@ -29,17 +29,17 @@ en:
title: "Chat Channel Archive Complete"
subject_template: "Chat channel archive completed successfully"
text_body_template: |
Archiving the chat channel **\#%{channel_name}** has been completed successfully. The messages were copied into the topic [%{topic_title}](%{topic_url}).
Archiving the chat channel %{channel_hashtag_or_name} has been completed successfully. The messages were copied into the topic [%{topic_title}](%{topic_url}).
chat_channel_archive_failed:
title: "Chat Channel Archive Failed"
subject_template: "Chat channel archive failed"
text_body_template: |
Archiving the chat channel **\#%{channel_name}** has failed. %{messages_archived} messages have been archived. Partially archived messages were copied into the topic [%{topic_title}](%{topic_url}). Visit the channel at %{channel_url} to retry.
Archiving the chat channel %{channel_hashtag_or_name} has failed. %{messages_archived} messages have been archived. Partially archived messages were copied into the topic [%{topic_title}](%{topic_url}). Visit the channel at %{channel_url} to retry.
chat_channel_archive_failed_no_topic:
title: "Chat Channel Archive Failed"
subject_template: "Chat channel archive failed"
text_body_template: |
Archiving the chat channel **\#%{channel_name}** has failed. No messages have been archived. The topic was not created successfully for the following reasons:
Archiving the chat channel %{channel_hashtag_or_name} has failed. No messages have been archived. The topic was not created successfully for the following reasons:
%{topic_validation_errors}

View File

@ -248,7 +248,7 @@ class Chat::ChatChannelArchiveService
def notify_archiver(result, error_message: nil)
base_translation_params = {
channel_name: chat_channel_title,
channel_hashtag_or_name: channel_hashtag_or_name,
topic_title: chat_channel_archive.destination_topic&.title,
topic_url: chat_channel_archive.destination_topic&.url,
topic_validation_errors: result == :failed_no_topic ? error_message : nil,
@ -301,4 +301,11 @@ class Chat::ChatChannelArchiveService
def kick_all_users
Chat::ChatChannelMembershipManager.new(chat_channel).unfollow_all_users
end
def channel_hashtag_or_name
if chat_channel.slug.present? && SiteSetting.enable_experimental_hashtag_autocomplete
return "##{chat_channel.slug}::channel"
end
chat_channel_title
end
end

View File

@ -12,6 +12,8 @@ describe Chat::ChatChannelArchiveService do
let(:topic_params) { { topic_title: "This will be a new topic", category_id: category.id } }
subject { Chat::ChatChannelArchiveService }
before { SiteSetting.chat_enabled = true }
describe "#create_archive_process" do
before { 3.times { Fabricate(:chat_message, chat_channel: channel) } }
@ -184,6 +186,20 @@ describe Chat::ChatChannelArchiveService do
expect(pm_topic.first_post.raw).to include("Title can't have more than 1 emoji")
end
context "when enable_experimental_hashtag_autocomplete" do
before { SiteSetting.enable_experimental_hashtag_autocomplete = true }
it "uses the channel slug to autolink a hashtag for the channel in the PM" do
create_messages(3) && start_archive
subject.new(@channel_archive).execute
expect(@channel_archive.reload.complete?).to eq(true)
pm_topic = Topic.private_messages.last
expect(pm_topic.first_post.cooked).to include(
"<a class=\"hashtag-cooked\" href=\"#{channel.relative_url}\" data-type=\"channel\" data-slug=\"#{channel.slug}\" data-ref=\"#{channel.slug}::channel\"><svg class=\"fa d-icon d-icon-comment svg-icon svg-node\"><use href=\"#comment\"></use></svg><span>#{channel.title(user)}</span></a>",
)
end
end
describe "channel members" do
before do
create_messages(3)