FIX: do not display the message content when it errors (#21008)

This commit is contained in:
Joffrey JAFFEUX 2023-04-06 19:32:21 +02:00 committed by GitHub
parent 0ff86feb96
commit fef279acd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -764,7 +764,7 @@ export default class ChatLivePane extends Component {
const stagedMessage = ChatMessage.createStagedMessage(this.args.channel, {
message,
created_at: new Date(),
created_at: moment.utc().format(),
uploads: cloneJSON(uploads),
user: this.currentUser,
});
@ -790,6 +790,7 @@ export default class ChatLivePane extends Component {
})
.catch((error) => {
this._onSendError(stagedMessage.id, error);
this.scrollToBottom();
})
.finally(() => {
if (this._selfDeleted) {
@ -827,6 +828,9 @@ export default class ChatLivePane extends Component {
this.args.channel.messagesManager.findStagedMessage(id);
if (stagedMessage) {
if (error.jqXHR?.responseJSON?.errors?.length) {
// only network errors are retryable
stagedMessage.message = "";
stagedMessage.cooked = "";
stagedMessage.error = error.jqXHR.responseJSON.errors[0];
} else {
this.chat.markNetworkAsUnreliable();

View File

@ -0,0 +1,25 @@
# frozen_string_literal: true
RSpec.describe "Message errors", type: :system, js: true do
fab!(:current_user) { Fabricate(:admin) }
let(:chat_page) { PageObjects::Pages::Chat.new }
let(:channel_page) { PageObjects::Pages::ChatChannel.new }
let(:max_length) { SiteSetting.chat_maximum_message_length }
before { chat_system_bootstrap }
context "when message is too long" do
fab!(:channel) { Fabricate(:chat_channel) }
it "only shows the error, not the message" do
channel.add(current_user)
sign_in(current_user)
chat_page.visit_channel(channel)
channel_page.send_message("atoolongmessage" + "a" * max_length)
expect(page).to have_no_content("atoolongmessage")
expect(page).to have_content(I18n.t("chat.errors.message_too_long", count: max_length))
end
end
end