mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 06:04:11 +08:00
FIX: correctly syncs current user message in multiple sessions (#20584)
This commit is contained in:
parent
54351e1b8a
commit
4f2dfd3857
|
@ -517,7 +517,8 @@ export default class ChatLivePane extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
handleMessage(data) {
|
||||
@bind
|
||||
onMessage(data) {
|
||||
switch (data.type) {
|
||||
case "sent":
|
||||
this.handleSentMessage(data);
|
||||
|
@ -555,29 +556,26 @@ export default class ChatLivePane extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
_handleOwnSentMessage(data) {
|
||||
const stagedMessage = this.args.channel.findStagedMessage(data.staged_id);
|
||||
if (stagedMessage) {
|
||||
stagedMessage.error = null;
|
||||
stagedMessage.id = data.chat_message.id;
|
||||
stagedMessage.staged = false;
|
||||
stagedMessage.excerpt = data.chat_message.excerpt;
|
||||
stagedMessage.threadId = data.chat_message.thread_id;
|
||||
stagedMessage.channelId = data.chat_message.chat_channel_id;
|
||||
stagedMessage.createdAt = data.chat_message.created_at;
|
||||
_handleStagedMessage(stagedMessage, data) {
|
||||
stagedMessage.error = null;
|
||||
stagedMessage.id = data.chat_message.id;
|
||||
stagedMessage.staged = false;
|
||||
stagedMessage.excerpt = data.chat_message.excerpt;
|
||||
stagedMessage.threadId = data.chat_message.thread_id;
|
||||
stagedMessage.channelId = data.chat_message.chat_channel_id;
|
||||
stagedMessage.createdAt = data.chat_message.created_at;
|
||||
|
||||
const inReplyToMsg = this.args.channel.findMessage(
|
||||
data.chat_message.in_reply_to?.id
|
||||
);
|
||||
if (inReplyToMsg && !inReplyToMsg.threadId) {
|
||||
inReplyToMsg.threadId = data.chat_message.thread_id;
|
||||
}
|
||||
const inReplyToMsg = this.args.channel.findMessage(
|
||||
data.chat_message.in_reply_to?.id
|
||||
);
|
||||
if (inReplyToMsg && !inReplyToMsg.threadId) {
|
||||
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;
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue
Block a user