FIX: correctly syncs current user message in multiple sessions (#20584)

This commit is contained in:
Joffrey JAFFEUX 2023-03-08 17:28:39 +01:00 committed by GitHub
parent 54351e1b8a
commit 4f2dfd3857
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 30 deletions

View File

@ -517,7 +517,8 @@ export default class ChatLivePane extends Component {
}
}
handleMessage(data) {
@bind
onMessage(data) {
switch (data.type) {
case "sent":
this.handleSentMessage(data);
@ -555,9 +556,7 @@ export default class ChatLivePane extends Component {
}
}
_handleOwnSentMessage(data) {
const stagedMessage = this.args.channel.findStagedMessage(data.staged_id);
if (stagedMessage) {
_handleStagedMessage(stagedMessage, data) {
stagedMessage.error = null;
stagedMessage.id = data.chat_message.id;
stagedMessage.staged = false;
@ -579,7 +578,6 @@ export default class ChatLivePane extends Component {
stagedMessage.cooked = data.chat_message.cooked;
}
}
}
handleSentMessage(data) {
if (this.args.channel.isFollowing) {
@ -587,7 +585,10 @@ export default class ChatLivePane extends Component {
}
if (data.chat_message.user.id === this.currentUser.id && data.staged_id) {
return this._handleOwnSentMessage(data);
const stagedMessage = this.args.channel.findStagedMessage(data.staged_id);
if (stagedMessage) {
return this._handleStagedMessage(stagedMessage, data);
}
}
if (this.args.channel.canLoadMoreFuture) {
@ -1138,13 +1139,6 @@ export default class ChatLivePane extends Component {
);
}
@bind
onMessage(busData) {
if (!this.args.channel.canLoadMoreFuture || busData.type !== "sent") {
this.handleMessage(busData);
}
}
@bind
_forceBodyScroll() {
// when keyboard is visible this will ensure body

View File

@ -33,6 +33,24 @@ RSpec.describe "Chat channel", type: :system, js: true do
end
end
context "with two sessions opened on same channel" do
it "syncs the messages" do
using_session(:tab_1) do
sign_in(current_user)
chat.visit_channel(channel_1)
end
using_session(:tab_2) do
sign_in(current_user)
chat.visit_channel(channel_1)
end
using_session(:tab_1) { channel.send_message("test_message") }
using_session(:tab_2) { expect(channel).to have_message(text: "test_message") }
end
end
it "allows to edit this message once persisted" do
chat.visit_channel(channel_1)
channel.send_message("aaaaaaaaaaaaaaaaaaaa")