From 3cde55b76f6d681a243876b360bd8368c0a81ac6 Mon Sep 17 00:00:00 2001 From: David Battersby Date: Fri, 29 Nov 2024 12:52:55 +0400 Subject: [PATCH] FIX: show urgent badge for mentions in DM threads (#29821) When thread tracking level is Normal in a DM channel, we should still show notification badges to the mentioned user. --- .../chat-channel-unread-indicator.gjs | 68 +++++++------- .../chat/footer/unread-indicator.gjs | 5 +- .../chat/message-creator/channel.gjs | 33 +++++-- .../message-creator/lib/chatables-loader.js | 31 +++++-- .../components/chat/message-creator/user.gjs | 25 +++++- .../discourse/initializers/chat-sidebar.js | 14 ++- .../services/chat-channels-manager.js | 32 ++++--- .../services/chat-tracking-state-manager.js | 2 +- plugins/chat/spec/system/chat_footer_spec.rb | 36 +++++++- .../message_notifications_mobile_spec.rb | 29 ++++++ ...message_notifications_with_sidebar_spec.rb | 88 ++++++++++++++----- 11 files changed, 265 insertions(+), 98 deletions(-) diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel-unread-indicator.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-channel-unread-indicator.gjs index af37fd903a0..e8fc3cff002 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-channel-unread-indicator.gjs +++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel-unread-indicator.gjs @@ -1,7 +1,8 @@ import Component from "@glimmer/component"; import { service } from "@ember/service"; import concatClass from "discourse/helpers/concat-class"; -import { hasChatIndicator } from "../lib/chat-user-preferences"; + +const MAX_UNREAD_COUNT = 99; export default class ChatChannelUnreadIndicator extends Component { @service chat; @@ -10,48 +11,41 @@ export default class ChatChannelUnreadIndicator extends Component { get showUnreadIndicator() { return ( - this.args.channel.tracking.unreadCount > 0 || - this.args.channel.tracking.mentionCount > 0 || - this.args.channel.unreadThreadsCountSinceLastViewed > 0 + this.args.channel.tracking.unreadCount + + this.args.channel.tracking.mentionCount + + this.args.channel.unreadThreadsCountSinceLastViewed > + 0 + ); + } + + get publicUrgentCount() { + return ( + this.args.channel.tracking.mentionCount + + this.args.channel.tracking.watchedThreadsUnreadCount + ); + } + + get directUrgentCount() { + return ( + this.args.channel.tracking.unreadCount + + this.args.channel.tracking.mentionCount + + this.args.channel.tracking.watchedThreadsUnreadCount ); } get urgentCount() { - if (this.hasChannelMentions) { - return this.args.channel.tracking.mentionCount; - } - if (this.hasWatchedThreads) { - return this.args.channel.tracking.watchedThreadsUnreadCount; - } - return this.args.channel.tracking.unreadCount; + return this.args.channel.isDirectMessageChannel + ? this.directUrgentCount + : this.publicUrgentCount; } get isUrgent() { - if (this.onlyMentions) { - return this.hasChannelMentions; - } - return ( - this.isDirectMessage || this.hasChannelMentions || this.hasWatchedThreads - ); + return this.urgentCount > 0; } - get isDirectMessage() { - return ( - this.args.channel.isDirectMessageChannel && - this.args.channel.tracking.unreadCount > 0 - ); - } - - get hasChannelMentions() { - return this.args.channel.tracking.mentionCount > 0; - } - - get hasWatchedThreads() { - return this.args.channel.tracking.watchedThreadsUnreadCount > 0; - } - - get onlyMentions() { - return hasChatIndicator(this.currentUser).ONLY_MENTIONS; + get urgentBadgeCount() { + let totalCount = this.urgentCount; + return totalCount > MAX_UNREAD_COUNT ? `${MAX_UNREAD_COUNT}+` : totalCount; } diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/footer/unread-indicator.gjs b/plugins/chat/assets/javascripts/discourse/components/chat/footer/unread-indicator.gjs index dc57ad8d175..0a7d8ec30ca 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat/footer/unread-indicator.gjs +++ b/plugins/chat/assets/javascripts/discourse/components/chat/footer/unread-indicator.gjs @@ -27,7 +27,10 @@ export default class FooterUnreadIndicator extends Component { if (this.badgeType === CHANNELS_TAB) { return this.chatTrackingStateManager.publicChannelMentionCount; } else if (this.badgeType === DMS_TAB) { - return this.chatTrackingStateManager.directMessageUnreadCount; + return ( + this.chatTrackingStateManager.directMessageUnreadCount + + this.chatTrackingStateManager.directMessageMentionCount + ); } else if (this.badgeType === THREADS_TAB) { return this.chatTrackingStateManager.watchedThreadsUnreadCount; } else { diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/message-creator/channel.gjs b/plugins/chat/assets/javascripts/discourse/components/chat/message-creator/channel.gjs index 94b36fa4db9..df8d595f582 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat/message-creator/channel.gjs +++ b/plugins/chat/assets/javascripts/discourse/components/chat/message-creator/channel.gjs @@ -1,21 +1,40 @@ import Component from "@glimmer/component"; import { service } from "@ember/service"; -import { gt, not } from "truth-helpers"; +import { not } from "truth-helpers"; import ChannelTitle from "discourse/plugins/chat/discourse/components/channel-title"; 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 + : this.hasUrgent; + } + + get hasUnreads() { + return this.tracking?.unreadCount > 0; + } + + get hasUrgent() { return ( - this.args.item.model.isDirectMessageChannel || - (this.args.item.model.isCategoryChannel && - this.args.item.model.tracking.mentionCount > 0) || - (this.args.item.model.isCategoryChannel && - this.args.item.model.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.hasUnreadThreads || this.hasUrgent; + } +