mirror of
https://github.com/discourse/discourse.git
synced 2026-08-08 12:08:12 -05:00
FIX: live updates threads from my threads page (#25955)
Prior to this fix if a user was answering to one of the listed screen it wouldn't update while you look at the list.
This commit is contained in:
@@ -7,12 +7,11 @@ import ChannelTitle from "discourse/plugins/chat/discourse/components/channel-ti
|
||||
import List from "discourse/plugins/chat/discourse/components/chat/list";
|
||||
import ThreadIndicator from "discourse/plugins/chat/discourse/components/chat-message-thread-indicator";
|
||||
import ThreadTitle from "discourse/plugins/chat/discourse/components/thread-title";
|
||||
import ChatChannel from "discourse/plugins/chat/discourse/models/chat-channel";
|
||||
import ChatThread from "discourse/plugins/chat/discourse/models/chat-thread";
|
||||
|
||||
export default class UserThreads extends Component {
|
||||
@service chat;
|
||||
@service chatApi;
|
||||
@service chatChannelsManager;
|
||||
|
||||
@cached
|
||||
get threadsCollection() {
|
||||
@@ -22,9 +21,10 @@ export default class UserThreads extends Component {
|
||||
@bind
|
||||
handleLoadedThreads(result) {
|
||||
return result.threads.map((threadObject) => {
|
||||
const channel = ChatChannel.create(threadObject.channel);
|
||||
const thread = ChatThread.create(channel, threadObject);
|
||||
const channel = this.chatChannelsManager.store(threadObject.channel);
|
||||
const thread = channel.threadsManager.add(channel, threadObject);
|
||||
const tracking = result.tracking[thread.id];
|
||||
|
||||
if (tracking) {
|
||||
thread.tracking.mentionCount = tracking.mention_count;
|
||||
thread.tracking.unreadCount = tracking.unread_count;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { tracked } from "@glimmer/tracking";
|
||||
import { TrackedArray } from "@ember-compat/tracked-built-ins";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
export default class ChatThreadPreview {
|
||||
static create(args = {}) {
|
||||
@@ -36,4 +37,17 @@ export default class ChatThreadPreview {
|
||||
get otherParticipantCount() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,6 +265,7 @@ export default class ChatSubscriptionsManager extends Service {
|
||||
busData.thread_id,
|
||||
busData.message.created_at
|
||||
);
|
||||
thread.preview.updateFromMessageObject(busData.message);
|
||||
thread.tracking.unreadCount++;
|
||||
this._updateActiveLastViewedAt(channel);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user