FIX: attempts to make cooking less order dependent (#21253)

It's very hard to repro but under specific circumstances I suspect it was possible for this sequence to happen:

- set message TEXT
- cooking starts
- set message COOKED through another mean (like a message bus)
- the cooking started sooner finished and erases the cooked set at the step before causing the message to have the incorrect cooked
This commit is contained in:
Joffrey JAFFEUX 2023-04-26 16:50:38 +02:00 committed by GitHub
parent 1372c5c435
commit 731282c2ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 37 deletions

View File

@ -31,13 +31,11 @@ export default class ChatMessage {
@tracked deletedAt;
@tracked uploads;
@tracked excerpt;
@tracked message;
@tracked threadId;
@tracked threadReplyCount;
@tracked reactions;
@tracked reviewableId;
@tracked user;
@tracked cooked;
@tracked inReplyTo;
@tracked expanded;
@tracked bookmark;
@ -51,6 +49,9 @@ export default class ChatMessage {
@tracked newest = false;
@tracked highlighted = false;
@tracked firstOfResults = false;
@tracked message;
@tracked _cooked;
constructor(channel, args = {}) {
this.channel = channel;
@ -77,14 +78,7 @@ export default class ChatMessage {
: null);
this.draft = args.draft;
this.message = args.message || "";
if (args.cooked) {
this.cooked = args.cooked;
} else {
this.cooked = "";
this.cook();
}
this._cooked = args.cooked || "";
this.reactions = this.#initChatMessageReactionModel(
args.id,
args.reactions
@ -94,6 +88,19 @@ export default class ChatMessage {
this.bookmark = args.bookmark ? Bookmark.create(args.bookmark) : null;
}
get cooked() {
return this._cooked;
}
set cooked(newCooked) {
// some markdown is cooked differently on the server-side, e.g.
// quotes, avatar images etc.
if (newCooked !== this._cooked) {
this._cooked = newCooked;
this.incrementVersion();
}
}
cook() {
const site = getOwner(this).lookup("service:site");
@ -110,7 +117,6 @@ export default class ChatMessage {
if (ChatMessage.cookFunction) {
this.cooked = ChatMessage.cookFunction(this.message);
this.incrementVersion();
} else {
generateCookFunction(markdownOptions).then((cookFunction) => {
ChatMessage.cookFunction = (raw) => {
@ -121,7 +127,6 @@ export default class ChatMessage {
};
this.cooked = ChatMessage.cookFunction(this.message);
this.incrementVersion();
});
}
}

View File

@ -20,12 +20,6 @@ export default class ChatChannelPaneSubscriptionsManager extends ChatPaneBaseSub
return;
}
// TODO (martin) Move scrolling functionality to pane from ChatLivePane?
afterProcessedMessage() {
// this.scrollToLatestMessage();
return;
}
handleThreadCreated(data) {
const message = this.messagesManager.findMessage(data.chat_message.id);
if (message) {

View File

@ -39,10 +39,4 @@ export default class ChatChannelThreadPaneSubscriptionsManager extends ChatPaneB
handleThreadOriginalMessageUpdate() {
return;
}
// NOTE: noop for now, later we may want to do scrolling or something like
// we do in the channel pane.
afterProcessedMessage() {
return;
}
}

View File

@ -28,11 +28,7 @@ export function handleStagedMessage(messagesManager, data) {
inReplyToMsg.threadId = data.chat_message.thread_id;
}
// some markdown is cooked differently on the server-side, e.g.
// quotes, avatar images etc.
if (data.chat_message?.cooked !== stagedMessage.cooked) {
stagedMessage.cooked = data.chat_message.cooked;
}
return stagedMessage;
}
@ -142,15 +138,9 @@ export default class ChatPaneBaseSubscriptionsManager extends Service {
const message = this.messagesManager.findMessage(data.chat_message.id);
if (message) {
message.cooked = data.chat_message.cooked;
message.incrementVersion();
this.afterProcessedMessage(message);
}
}
afterProcessedMessage() {
throw "not implemented";
}
handleReactionMessage(data) {
const message = this.messagesManager.findMessage(data.chat_message_id);
if (message) {
@ -166,7 +156,6 @@ export default class ChatPaneBaseSubscriptionsManager extends Service {
message.excerpt = data.chat_message.excerpt;
message.uploads = cloneJSON(data.chat_message.uploads || []);
message.edited = true;
message.incrementVersion();
}
}

View File

@ -39,7 +39,7 @@ RSpec.describe "Chat message onebox", type: :system, js: true do
chat_page.visit_channel(channel_1)
channel_page.send_message("https://en.wikipedia.org/wiki/Hyperlink")
expect(page).to have_content("This is a test")
expect(page).to have_content("This is a test", wait: 20)
end
end
end