FEATURE: Chat global mention warnings (pre-send & post-send) (#22764)

This is also fixes the issue of chat composer warnings persisting across channels. Currently if you try to mention more groups than is allowed for example, a mention warning pops up. When you change channels the mention warning will not disappear even if there is no text in the composer.

This adds a reset function to the chat-composer-warnings-tracker.js, which is called when the channel is changed and the message is empty. In the event that the message is not empty we call captureMentions to check the loaded drafts' mentions.

This PR would be nicer if the post-send notice used the new chat notices API to publish the mention warnings but we would have to change the existing ones and I thought that would be too much change for this PR. It'd be a good followup though.
This commit is contained in:
Mark VanLandingham
2023-08-22 15:54:35 -05:00
committed by GitHub
parent c9de84c63d
commit 68eba53e09
13 changed files with 137 additions and 10 deletions

View File

@ -58,6 +58,22 @@ describe Chat::Notifier do
expect(to_notify[list_key]).to be_empty
end
it "will publish a mention warning" do
channel.update!(allow_channel_wide_mentions: false)
msg = build_cooked_msg(mention, user_1)
messages =
MessageBus.track_publish("/chat/#{channel.id}") do
to_notify = described_class.new(msg, msg.created_at).notify_new
end
global_mentions_disabled_message = messages.first
expect(global_mentions_disabled_message).to be_present
expect(global_mentions_disabled_message.data[:type].to_sym).to eq(:mention_warning)
expect(global_mentions_disabled_message.data[:global_mentions_disabled]).to eq(true)
end
it "includes all members of a channel except the sender" do
msg = build_cooked_msg(mention, user_1)