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
+13 -27
View File
@@ -387,31 +387,6 @@ module Chat
end
end
def self.publish_inaccessible_mentions(
user_id,
chat_message,
cannot_chat_users,
without_membership,
too_many_members,
mentions_disabled,
global_mentions_disabled
)
MessageBus.publish(
"/chat/#{chat_message.chat_channel_id}",
{
type: :mention_warning,
chat_message_id: chat_message.id,
cannot_see: cannot_chat_users.map { |u| { username: u.username, id: u.id } }.as_json,
without_membership:
without_membership.map { |u| { username: u.username, id: u.id } }.as_json,
groups_with_too_many_members: too_many_members.map(&:name).as_json,
group_mentions_disabled: mentions_disabled.map(&:name).as_json,
global_mentions_disabled: global_mentions_disabled,
},
user_ids: [user_id],
)
end
def self.publish_kick_users(channel_id, user_ids)
MessageBus.publish(
kick_users_message_bus_channel(channel_id),
@@ -478,8 +453,19 @@ module Chat
)
end
def self.publish_notice(user_id:, channel_id:, text_content:)
payload = { type: "notice", text_content: text_content, channel_id: channel_id }
def self.publish_notice(user_id:, channel_id:, text_content: nil, type: nil, data: nil)
# Notices are either plain text sent to the client, or a "type" with data. The
# client will then translate that type and data into a front-end component.
if text_content.blank? && type.blank? && data.blank?
raise "Cannot publish notice without text content or a type"
end
payload = { type: "notice", channel_id: channel_id }
if text_content
payload[:text_content] = text_content
else
payload[:notice_type] = type
payload[:data] = data
end
MessageBus.publish("/chat/#{channel_id}", payload, user_ids: [user_id])
end