add threading unread state to chat launcher

This commit is contained in:
David Battersby 2024-11-22 12:56:34 +04:00
parent 493ec8f177
commit 5aa7170866
No known key found for this signature in database
GPG Key ID: B340A4CBDA2C74DC
3 changed files with 36 additions and 16 deletions

View File

@ -6,6 +6,10 @@ import ChannelTitle from "discourse/plugins/chat/discourse/components/channel-ti
export default class Channel extends Component {
@service currentUser;
get tracking() {
return this.args.item.tracking;
}
get isUrgent() {
return this.args.item.model.isDirectMessageChannel
? this.hasUnreads || this.hasUrgent
@ -13,18 +17,22 @@ export default class Channel extends Component {
}
get hasUnreads() {
return this.args.item.tracking.unreadCount > 0;
return this.tracking?.unreadCount > 0;
}
get hasUrgent() {
return (
this.args.item.tracking.mentionCount > 0 ||
this.args.item.tracking.watchedThreadsUnreadCount > 0
this.tracking?.mentionCount > 0 ||
this.tracking?.watchedThreadsUnreadCount > 0
);
}
get hasUnreadThreads() {
return this.args.item.unread_thread_count > 0;
}
get showIndicator() {
return this.hasUnreads || this.isUrgent;
return this.hasUnreads || this.hasUnreadThreads || this.hasUrgent;
}
<template>

View File

@ -59,7 +59,14 @@ export default class ChatablesLoader {
]
.map((item) => {
const chatable = ChatChatable.create(item);
chatable.tracking = this.#injectTracking(chatable);
const channel = this.#findChannel(chatable);
if (channel) {
chatable.tracking = channel.tracking;
chatable.unread_thread_count =
channel.unreadThreadsCountSinceLastViewed;
}
return chatable;
})
.slice(0, MAX_RESULTS);
@ -74,26 +81,32 @@ export default class ChatablesLoader {
let chatable;
if (channel.chatable?.users?.length === 1) {
chatable = ChatChatable.createUser(channel.chatable.users[0]);
chatable.unread_thread_count =
channel.threadsManager.unreadThreadCount;
} else {
chatable = ChatChatable.createChannel(channel);
}
chatable.tracking = channel.tracking;
chatable.unread_thread_count =
channel.unreadThreadsCountSinceLastViewed;
return chatable;
})
.filter(Boolean)
.slice(0, MAX_RESULTS);
}
#injectTracking(chatable) {
if (!chatable.type === "channel") {
#findChannel(chatable) {
if (!["user", "channel"].includes(chatable.type)) {
return;
}
return this.chatChannelsManager.allChannels.find(
(channel) => channel.id === chatable.model.id
)?.tracking;
const { allChannels } = this.chatChannelsManager;
if (chatable.type === "user") {
return allChannels.find(
({ chatable: { users } }) =>
users?.length === 1 && users[0].id === chatable.model.id
);
} else if (chatable.type === "channel") {
return allChannels.find(({ id }) => id === chatable.model.id);
}
}
}

View File

@ -28,10 +28,9 @@ export default class ChatableUser extends Component {
get isUrgent() {
return (
this.args.item.tracking.unreadCount +
this.args.item.tracking.mentionCount +
this.args.item.tracking.watchedThreadsUnreadCount >
0
this.args.item.tracking?.unreadCount > 0 ||
this.args.item.tracking?.mentionCount > 0 ||
this.args.item.tracking?.watchedThreadsUnreadCount > 0
);
}