FIX: do not increment reply count manually (#26769)
That could cause flakeyness in specs depending in which timing message bus would arrive and it's not necessary as it should be updated with `handleThreadOriginalMessageUpdate`.
This commit is contained in:
parent
a7f596da7a
commit
351d212e8a
|
@ -92,6 +92,8 @@ module Chat
|
||||||
{
|
{
|
||||||
type: :update_thread_original_message,
|
type: :update_thread_original_message,
|
||||||
original_message_id: thread.original_message_id,
|
original_message_id: thread.original_message_id,
|
||||||
|
thread_id: thread.id,
|
||||||
|
channel_id: thread.channel.id,
|
||||||
preview: preview.as_json,
|
preview: preview.as_json,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -9,18 +9,32 @@ import List from "discourse/plugins/chat/discourse/components/chat/list";
|
||||||
import ThreadIndicator from "discourse/plugins/chat/discourse/components/chat-message-thread-indicator";
|
import ThreadIndicator from "discourse/plugins/chat/discourse/components/chat-message-thread-indicator";
|
||||||
import ThreadTitle from "discourse/plugins/chat/discourse/components/thread-title";
|
import ThreadTitle from "discourse/plugins/chat/discourse/components/thread-title";
|
||||||
import ThreadPreview from "discourse/plugins/chat/discourse/components/user-threads/preview";
|
import ThreadPreview from "discourse/plugins/chat/discourse/components/user-threads/preview";
|
||||||
|
import ChatThreadPreview from "discourse/plugins/chat/discourse/models/chat-thread-preview";
|
||||||
|
|
||||||
export default class UserThreads extends Component {
|
export default class UserThreads extends Component {
|
||||||
@service chat;
|
@service chat;
|
||||||
@service chatApi;
|
@service chatApi;
|
||||||
@service chatChannelsManager;
|
@service chatChannelsManager;
|
||||||
|
@service messageBus;
|
||||||
@service site;
|
@service site;
|
||||||
|
|
||||||
|
trackedChannels = {};
|
||||||
|
|
||||||
@cached
|
@cached
|
||||||
get threadsCollection() {
|
get threadsCollection() {
|
||||||
return this.chatApi.userThreads(this.handleLoadedThreads);
|
return this.chatApi.userThreads(this.handleLoadedThreads);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
willDestroy() {
|
||||||
|
super.willDestroy(...arguments);
|
||||||
|
|
||||||
|
Object.keys(this.trackedChannels).forEach((id) => {
|
||||||
|
this.messageBus.unsubscribe(`/chat/${id}`, this.onMessage);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.trackedChannels = {};
|
||||||
|
}
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
handleLoadedThreads(result) {
|
handleLoadedThreads(result) {
|
||||||
return result.threads.map((threadObject) => {
|
return result.threads.map((threadObject) => {
|
||||||
|
@ -32,10 +46,45 @@ export default class UserThreads extends Component {
|
||||||
thread.tracking.mentionCount = tracking.mention_count;
|
thread.tracking.mentionCount = tracking.mention_count;
|
||||||
thread.tracking.unreadCount = tracking.unread_count;
|
thread.tracking.unreadCount = tracking.unread_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.trackChannel(thread.channel);
|
||||||
return thread;
|
return thread;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trackChannel(channel) {
|
||||||
|
if (this.trackedChannels[channel.id]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.trackedChannels[channel.id] = channel;
|
||||||
|
|
||||||
|
this.messageBus.subscribe(
|
||||||
|
`/chat/${channel.id}`,
|
||||||
|
this.onMessage,
|
||||||
|
channel.channelMessageBusLastId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@bind
|
||||||
|
onMessage(data) {
|
||||||
|
if (data.type === "update_thread_original_message") {
|
||||||
|
const channel = this.trackedChannels[data.channel_id];
|
||||||
|
|
||||||
|
if (!channel) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const thread = channel.threadsManager.threads.find(
|
||||||
|
(t) => t.id === data.thread_id
|
||||||
|
);
|
||||||
|
|
||||||
|
if (thread) {
|
||||||
|
thread.preview = ChatThreadPreview.create(data.preview);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<List
|
<List
|
||||||
@collection={{this.threadsCollection}}
|
@collection={{this.threadsCollection}}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { tracked } from "@glimmer/tracking";
|
import { tracked } from "@glimmer/tracking";
|
||||||
import { TrackedArray } from "@ember-compat/tracked-built-ins";
|
import { TrackedArray } from "@ember-compat/tracked-built-ins";
|
||||||
import User from "discourse/models/user";
|
|
||||||
|
|
||||||
export default class ChatThreadPreview {
|
export default class ChatThreadPreview {
|
||||||
static create(args = {}) {
|
static create(args = {}) {
|
||||||
|
@ -37,17 +36,4 @@ export default class ChatThreadPreview {
|
||||||
get otherParticipantCount() {
|
get otherParticipantCount() {
|
||||||
return this.participantCount - this.participantUsers.length;
|
return this.participantCount - this.participantUsers.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateFromMessageObject(messageObject) {
|
|
||||||
const user = User.create(messageObject.user);
|
|
||||||
if (!this.participantUsers.find((u) => u.id === user.id)) {
|
|
||||||
this.participantUsers.push(user);
|
|
||||||
this.participantCount += 1;
|
|
||||||
}
|
|
||||||
this.replyCount += 1;
|
|
||||||
this.lastReplyAt = messageObject.created_at;
|
|
||||||
this.lastReplyId = messageObject.id;
|
|
||||||
this.lastReplyExcerpt = messageObject.excerpt;
|
|
||||||
this.lastReplyUser = user;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -267,7 +267,6 @@ export default class ChatSubscriptionsManager extends Service {
|
||||||
busData.thread_id,
|
busData.thread_id,
|
||||||
busData.message.created_at
|
busData.message.created_at
|
||||||
);
|
);
|
||||||
thread.preview.updateFromMessageObject(busData.message);
|
|
||||||
thread.tracking.unreadCount++;
|
thread.tracking.unreadCount++;
|
||||||
this._updateActiveLastViewedAt(channel);
|
this._updateActiveLastViewedAt(channel);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,9 @@ RSpec.describe "Reply to message - smoke", type: :system do
|
||||||
end
|
end
|
||||||
|
|
||||||
thread_page.send_message("user1reply")
|
thread_page.send_message("user1reply")
|
||||||
expect(channel_page.message_thread_indicator(original_message)).to have_reply_count(1)
|
|
||||||
expect(thread_page.messages).to have_message(text: "user1reply")
|
expect(thread_page.messages).to have_message(text: "user1reply")
|
||||||
|
expect(channel_page.message_thread_indicator(original_message)).to have_reply_count(1)
|
||||||
|
|
||||||
using_session(:user_2) do |session|
|
using_session(:user_2) do |session|
|
||||||
expect(thread_page.messages).to have_message(text: "user1reply")
|
expect(thread_page.messages).to have_message(text: "user1reply")
|
||||||
|
@ -50,7 +51,7 @@ RSpec.describe "Reply to message - smoke", type: :system do
|
||||||
|
|
||||||
expect(thread_page.messages).to have_message(text: "user1reply")
|
expect(thread_page.messages).to have_message(text: "user1reply")
|
||||||
expect(thread_page.messages).to have_message(text: "user2reply")
|
expect(thread_page.messages).to have_message(text: "user2reply")
|
||||||
expect(channel_page.message_thread_indicator(original_message)).to have_reply_count(3)
|
expect(channel_page.message_thread_indicator(original_message)).to have_reply_count(2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -118,7 +118,6 @@ RSpec.describe "User threads", type: :system do
|
||||||
it "updates the thread when another user replies" do
|
it "updates the thread when another user replies" do
|
||||||
chat_thread_chain_bootstrap(channel: channel_1, users: [current_user, Fabricate(:user)])
|
chat_thread_chain_bootstrap(channel: channel_1, users: [current_user, Fabricate(:user)])
|
||||||
thread = channel_1.threads.last
|
thread = channel_1.threads.last
|
||||||
message = thread.original_message
|
|
||||||
last_user = Fabricate(:user)
|
last_user = Fabricate(:user)
|
||||||
|
|
||||||
chat_page.visit_user_threads
|
chat_page.visit_user_threads
|
||||||
|
@ -126,7 +125,6 @@ RSpec.describe "User threads", type: :system do
|
||||||
last_message = Fabricate(:chat_message, thread: thread, user: last_user, use_service: true)
|
last_message = Fabricate(:chat_message, thread: thread, user: last_user, use_service: true)
|
||||||
|
|
||||||
indicator = PageObjects::Components::Chat::ThreadIndicator.new(".c-user-thread")
|
indicator = PageObjects::Components::Chat::ThreadIndicator.new(".c-user-thread")
|
||||||
|
|
||||||
expect(indicator).to have_reply_count(4)
|
expect(indicator).to have_reply_count(4)
|
||||||
expect(indicator).to have_participant(last_user)
|
expect(indicator).to have_participant(last_user)
|
||||||
expect(indicator).to have_excerpt(last_message.excerpt)
|
expect(indicator).to have_excerpt(last_message.excerpt)
|
||||||
|
|
Loading…
Reference in New Issue