mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
parent
1372c5c435
commit
731282c2ec
@ -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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user