DEV: Use Notice API for mention warnings (#23238)

This PR swaps out the custom pathway to publishing and rendering mention warnings after a message is sent.

ChatPublisher#publish_notice is used, and expanded. Now, instead of only accepting text_content as an argument, component and component_args are accepted and there is a renderer for these components.

Translations moved to server, as notices expect text to be passed in unless a component is rendered

The warnings are rendered at the top now, outside of the scope of the single message that sent it.

I entirely removed the jit_messages_spec b/c it's duplicate testing of other parts of the app. IMO we don't need a backend test for a feature, a component test for the feature AND a system test (that is slow and potentially even flakey due to timing issues with wait) to test the same thing. So jit_messages_spec is gone.
This commit is contained in:
Mark VanLandingham
2023-09-01 09:07:23 -05:00
committed by GitHub
parent ed35ae4dcd
commit 9c65e2140a
27 changed files with 337 additions and 662 deletions

View File

@ -69,9 +69,10 @@ describe Chat::Notifier do
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)
expect(global_mentions_disabled_message.data[:type].to_sym).to eq(:notice)
expect(global_mentions_disabled_message.data[:text_content]).to eq(
I18n.t("chat.mention_warning.global_mentions_disallowed"),
)
end
it "includes all members of a channel except the sender" do
@ -415,10 +416,10 @@ describe Chat::Notifier do
unreachable_msg = messages.first
expect(unreachable_msg).to be_present
expect(unreachable_msg.data[:without_membership]).to be_empty
unreachable_users = unreachable_msg.data[:cannot_see].map { |u| u["id"] }
expect(unreachable_users).to contain_exactly(user_3.id)
expect(unreachable_msg[:data][:type].to_sym).to eq(:notice)
expect(unreachable_msg[:data][:text_content]).to eq(
I18n.t("chat.mention_warning.cannot_see", first_identifier: user_3.username),
)
end
context "when in a personal message" do
@ -452,10 +453,10 @@ describe Chat::Notifier do
unreachable_msg = messages.first
expect(unreachable_msg).to be_present
expect(unreachable_msg.data[:without_membership]).to be_empty
unreachable_users = unreachable_msg.data[:cannot_see].map { |u| u["id"] }
expect(unreachable_users).to contain_exactly(user_3.id)
expect(unreachable_msg[:data][:type].to_sym).to eq(:notice)
expect(unreachable_msg[:data][:text_content]).to eq(
I18n.t("chat.mention_warning.cannot_see", first_identifier: user_3.username),
)
end
it "notify posts of users who are part of the mentioned group but participating" do
@ -477,10 +478,10 @@ describe Chat::Notifier do
unreachable_msg = messages.first
expect(unreachable_msg).to be_present
expect(unreachable_msg.data[:without_membership]).to be_empty
unreachable_users = unreachable_msg.data[:cannot_see].map { |u| u["id"] }
expect(unreachable_users).to contain_exactly(user_3.id)
expect(unreachable_msg[:data][:type].to_sym).to eq(:notice)
expect(unreachable_msg[:data][:text_content]).to eq(
I18n.t("chat.mention_warning.cannot_see", first_identifier: user_3.username),
)
end
end
end
@ -502,11 +503,15 @@ describe Chat::Notifier do
not_participating_msg = messages.first
expect(not_participating_msg).to be_present
expect(not_participating_msg.data[:cannot_see]).to be_empty
not_participating_users =
not_participating_msg.data[:without_membership].map { |u| u["id"] }
expect(not_participating_users).to contain_exactly(user_3.id)
expect(not_participating_msg[:data][:type].to_sym).to eq(:notice)
expect(not_participating_msg[:data][:text_content]).to be_nil
expect(not_participating_msg[:data][:notice_type].to_sym).to eq(:mention_without_membership)
expect(not_participating_msg[:data][:data]).to eq(
user_ids: [user_3.id],
text:
I18n.t("chat.mention_warning.without_membership", first_identifier: user_3.username),
message_id: msg.id,
)
end
it "cannot invite chat user without channel membership if they are ignoring the user who created the message" do
@ -555,11 +560,15 @@ describe Chat::Notifier do
not_participating_msg = messages.first
expect(not_participating_msg).to be_present
expect(not_participating_msg.data[:cannot_see]).to be_empty
not_participating_users =
not_participating_msg.data[:without_membership].map { |u| u["id"] }
expect(not_participating_users).to contain_exactly(user_3.id)
expect(not_participating_msg[:data][:type].to_sym).to eq(:notice)
expect(not_participating_msg[:data][:text_content]).to be_nil
expect(not_participating_msg[:data][:notice_type].to_sym).to eq(:mention_without_membership)
expect(not_participating_msg[:data][:data]).to eq(
user_ids: [user_3.id],
text:
I18n.t("chat.mention_warning.without_membership", first_identifier: user_3.username),
message_id: msg.id,
)
end
it "can invite other group members to channel" do
@ -580,11 +589,15 @@ describe Chat::Notifier do
not_participating_msg = messages.first
expect(not_participating_msg).to be_present
expect(not_participating_msg.data[:cannot_see]).to be_empty
not_participating_users =
not_participating_msg.data[:without_membership].map { |u| u["id"] }
expect(not_participating_users).to contain_exactly(user_3.id)
expect(not_participating_msg[:data][:type].to_sym).to eq(:notice)
expect(not_participating_msg[:data][:text_content]).to be_nil
expect(not_participating_msg[:data][:notice_type].to_sym).to eq(:mention_without_membership)
expect(not_participating_msg[:data][:data]).to eq(
user_ids: [user_3.id],
text:
I18n.t("chat.mention_warning.without_membership", first_identifier: user_3.username),
message_id: msg.id,
)
end
it "cannot invite a member of a group who is ignoring the user who created the message" do
@ -650,9 +663,11 @@ describe Chat::Notifier do
end
too_many_members_msg = messages.first
expect(too_many_members_msg).to be_present
too_many_members = too_many_members_msg.data[:groups_with_too_many_members]
expect(too_many_members).to contain_exactly(group.name)
expect(too_many_members_msg[:data][:type].to_sym).to eq(:notice)
expect(too_many_members_msg[:data][:text_content]).to eq(
I18n.t("chat.mention_warning.too_many_members", first_identifier: group.name),
)
end
it "sends a message to the client signaling the group doesn't allow mentions" do
@ -667,9 +682,11 @@ describe Chat::Notifier do
end
mentions_disabled_msg = messages.first
expect(mentions_disabled_msg).to be_present
mentions_disabled = mentions_disabled_msg.data[:group_mentions_disabled]
expect(mentions_disabled).to contain_exactly(group.name)
expect(mentions_disabled_msg[:data][:type].to_sym).to eq(:notice)
expect(mentions_disabled_msg[:data][:text_content]).to eq(
I18n.t("chat.mention_warning.group_mentions_disabled", first_identifier: group.name),
)
end
end
end