Skip to content

A platform for community discussion. Free, open, simple.

DEV: Split mobile chat unread indicators by current vs other channels (#39115)

chapoi4359fd7c75d1
diff --git a/plugins/chat/assets/javascripts/discourse/components/channels-list-public.gjs b/plugins/chat/assets/javascripts/discourse/components/channels-list-public.gjs
index ff7929410eb..48830d40446 100644
--- a/plugins/chat/assets/javascripts/discourse/components/channels-list-public.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/channels-list-public.gjs
@@ -25,7 +25,7 @@ export default class ChannelsListPublic extends Component {
}
get hasUnreadThreads() {
- return this.chatTrackingStateManager.hasUnreadThreads;
+ return this.chatTrackingStateManager.hasUnreadThreads();
}
get shouldShowMyThreads() {
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs
index 878d958ec98..5ca05d77a33 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs
@@ -760,6 +760,7 @@ export default class ChatChannel extends Component {
<ChatScrollToBottomArrow
@onScrollToBottom={{this.scrollToLatestMessage}}
@isVisible={{this.paneState.hasPendingContentBelow}}
+ @channel={{@channel}}
/>
{{#if this.pane.selectingMessages}}
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 8c857e052b7..26f607b4abc 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
@@ -49,7 +49,7 @@ export default class FooterUnreadIndicator extends Component {
} else if (this.badgeType === STARRED_TAB) {
return this.starredChannelsUnreadCount;
} else if (this.badgeType === THREADS_TAB) {
- return this.chatTrackingStateManager.hasUnreadThreads ? 1 : 0;
+ return this.chatTrackingStateManager.hasUnreadThreads() ? 1 : 0;
} else {
return 0;
}
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/header/icon/unread-indicator.gjs b/plugins/chat/assets/javascripts/discourse/components/chat/header/icon/unread-indicator.gjs
index fb3883eb7a3..c858b225d81 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat/header/icon/unread-indicator.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat/header/icon/unread-indicator.gjs
@@ -15,28 +15,30 @@ export default class ChatHeaderIconUnreadIndicator extends Component {
get urgentCount() {
return (
- this.args.urgentCount ||
- this.chatTrackingStateManager.allChannelUrgentCount
+ this.args.urgentCount ??
+ this.chatTrackingStateManager.allChannelUrgentCount()
);
}
get mentionCount() {
return (
- this.args.mentionCount ||
- this.chatTrackingStateManager.allChannelMentionCount
+ this.args.mentionCount ??
+ this.chatTrackingStateManager.allChannelMentionCount()
);
}
get unreadCount() {
return (
- this.args.unreadCount ||
- this.chatTrackingStateManager.publicChannelUnreadCount
+ this.args.unreadCount ??
+ this.chatTrackingStateManager.publicChannelUnreadCount()
);
}
get hasUnreads() {
return (
- this.unreadCount > 0 || this.chatTrackingStateManager.hasUnreadThreads
+ this.unreadCount > 0 ||
+ (this.args.hasUnreadThreads ??
+ this.chatTrackingStateManager.hasUnreadThreads())
);
}
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/navbar/back-button.gjs b/plugins/chat/assets/javascripts/discourse/components/chat/navbar/back-button.gjs
index 123a5f5a004..1dce216f8b1 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat/navbar/back-button.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat/navbar/back-button.gjs
@@ -46,6 +46,8 @@ export default class ChatNavbarBackButton extends Component {
<ChatHeaderIconUnreadIndicator
@urgentCount={{@urgentCount}}
@unreadCount={{@unreadCount}}
+ @mentionCount={{@mentionCount}}
+ @hasUnreadThreads={{@hasUnreadThreads}}
@indicatorPreference={{@indicatorPreference}}
/>
{{/if}}
@@ -65,6 +67,8 @@ export default class ChatNavbarBackButton extends Component {
<ChatHeaderIconUnreadIndicator
@urgentCount={{@urgentCount}}
@unreadCount={{@unreadCount}}
+ @mentionCount={{@mentionCount}}
+ @hasUnreadThreads={{@hasUnreadThreads}}
@indicatorPreference={{@indicatorPreference}}
/>
{{/if}}
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/routes/channel.gjs b/plugins/chat/assets/javascripts/discourse/components/chat/routes/channel.gjs
index a3d72d6e9f7..b671f343246 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat/routes/channel.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat/routes/channel.gjs
@@ -11,6 +11,7 @@ export default class ChatRoutesChannel extends Component {
@service siteSettings;
@service chat;
@service chatHistory;
+ @service chatTrackingStateManager;
@tracked isFiltering = false;
@@ -34,11 +35,41 @@ export default class ChatRoutesChannel extends Component {
}
}
+ get otherChannelsUrgentCount() {
+ return this.chatTrackingStateManager.allChannelUrgentCount({
+ exclude: this.args.channel,
+ });
+ }
+
+ get otherChannelsMentionCount() {
+ return this.chatTrackingStateManager.allChannelMentionCount({
+ exclude: this.args.channel,
+ });
+ }
+
+ get otherChannelsUnreadCount() {
+ return this.chatTrackingStateManager.publicChannelUnreadCount({
+ exclude: this.args.channel,
+ });
+ }
+
+ get otherChannelsHasUnreadThreads() {
+ return this.chatTrackingStateManager.hasUnreadThreads({
+ exclude: this.args.channel,
+ });
+ }
+
<template>
<div class="c-routes --channel">
<Navbar as |navbar|>
{{#if this.site.mobileView}}
- <navbar.BackButton @route={{this.getChannelsRoute}} />
+ <navbar.BackButton
+ @route={{this.getChannelsRoute}}
+ @urgentCount={{this.otherChannelsUrgentCount}}
+ @unreadCount={{this.otherChannelsUnreadCount}}
+ @mentionCount={{this.otherChannelsMentionCount}}
+ @hasUnreadThreads={{this.otherChannelsHasUnreadThreads}}
+ />
{{/if}}
<navbar.ChannelTitle @channel={{@channel}} />
<navbar.Actions as |a|>
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/scroll-to-bottom-arrow.gjs b/plugins/chat/assets/javascripts/discourse/components/chat/scroll-to-bottom-arrow.gjs
index b317c12cedb..bfc8953117f 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat/scroll-to-bottom-arrow.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat/scroll-to-bottom-arrow.gjs
@@ -1,22 +1,44 @@
+import Component from "@glimmer/component";
+import { service } from "@ember/service";
import DButton from "discourse/components/d-button";
import concatClass from "discourse/helpers/concat-class";
import icon from "discourse/helpers/d-icon";
+import { and } from "discourse/truth-helpers";
+import { i18n } from "discourse-i18n";
-const ScrollToBottomArrow = <template>
- <div class="chat-scroll-to-bottom">
- <DButton
- class={{concatClass
- "btn-flat"
- "chat-scroll-to-bottom__button"
- (if @isVisible "visible")
- }}
- @action={{@onScrollToBottom}}
- >
- <span class="chat-scroll-to-bottom__arrow">
- {{icon "arrow-down"}}
- </span>
- </DButton>
- </div>
-</template>;
+export default class ScrollToBottomArrow extends Component {
+ @service site;
-export default ScrollToBottomArrow;
+ get newMessageCount() {
+ if (!this.site.mobileView) {
+ return 0;
+ }
+ const channel = this.args.channel;
+ if (!channel) {
+ return 0;
+ }
+ return channel.tracking.unreadCount;
+ }
+
+ <template>
+ <div class="chat-scroll-to-bottom">
+ <DButton
+ class={{concatClass
+ "btn-flat"
+ "chat-scroll-to-bottom__button"
+ (if @isVisible "visible")
+ }}
+ @action={{@onScrollToBottom}}
+ >
+ <span class="chat-scroll-to-bottom__arrow">
+ {{icon "arrow-down"}}
+ </span>
+ {{#if (and @isVisible this.newMessageCount)}}
+ <span class="chat-scroll-to-bottom__new-messages">
+ {{i18n "chat.new_messages" count=this.newMessageCount}}
+ </span>
+ {{/if}}
+ </DButton>
+ </div>
+ </template>
+}
diff --git a/plugins/chat/assets/javascripts/discourse/services/chat-tracking-state-manager.js b/plugins/chat/assets/javascripts/discourse/services/chat-tracking-state-manager.js
index ff7ec661af2..9cc215aef62 100644
--- a/plugins/chat/assets/javascripts/discourse/services/chat-tracking-state-manager.js
+++ b/plugins/chat/assets/javascripts/discourse/services/chat-tracking-state-manager.js
@@ -46,44 +46,43 @@ export default class ChatTrackingStateManager extends Service {
});
}
- get publicChannelUnreadCount() {
- return this.#publicChannels.reduce((unreadCount, channel) => {
- return unreadCount + channel.tracking.unreadCount;
- }, 0);
- }
-
- get directMessageUnreadCount() {
- return this.#directMessageChannels.reduce((unreadCount, channel) => {
- return unreadCount + channel.tracking.unreadCount;
- }, 0);
- }
-
- get publicChannelMentionCount() {
- return this.#publicChannels.reduce((mentionCount, channel) => {
- return mentionCount + channel.tracking.mentionCount;
- }, 0);
- }
-
- get directMessageMentionCount() {
- return this.#directMessageChannels.reduce((dmMentionCount, channel) => {
- return dmMentionCount + channel.tracking.mentionCount;
+ allChannelMentionCount({ exclude } = {}) {
+ return this.#allChannels.reduce((count, channel) => {
+ if (channel.id === exclude?.id) {
+ return count;
+ }
+ return count + channel.tracking.mentionCount;
}, 0);
}
- get allChannelMentionCount() {
- return this.publicChannelMentionCount + this.directMessageMentionCount;
+ allChannelUrgentCount({ exclude } = {}) {
+ let count = 0;
+ for (const channel of this.#allChannels) {
+ if (channel.id === exclude?.id) {
+ continue;
+ }
+ count += channel.tracking.mentionCount;
+ count += channel.tracking.watchedThreadsUnreadCount;
+ if (channel.isDirectMessageChannel) {
+ count += channel.tracking.unreadCount;
+ }
+ }
+ return count;
}
- get allChannelUrgentCount() {
- return (
- this.allChannelMentionCount +
- this.directMessageUnreadCount +
- this.watchedThreadsUnreadCount
+ hasUnreadThreads({ exclude } = {}) {
+ return this.#allChannels.some(
+ (channel) => channel.id !== exclude?.id && channel.unreadThreadsCount > 0
);
}
- get hasUnreadThreads() {
- return this.#allChannels.some((channel) => channel.unreadThreadsCount > 0);
+ publicChannelUnreadCount({ exclude } = {}) {
+ return this.#publicChannels.reduce((count, channel) => {
+ if (channel.id === exclude?.id) {
+ return count;
+ }
+ return count + channel.tracking.unreadCount;
+ }, 0);
}
get watchedThreadsUnreadCount() {
@@ -124,10 +123,6 @@ export default class ChatTrackingStateManager extends Service {
return this.chatChannelsManager.publicMessageChannels;
}
- get #directMessageChannels() {
- return this.chatChannelsManager.directMessageChannels;
- }
-
get #allChannels() {
return this.chatChannelsManager.allChannels;
}
diff --git a/plugins/chat/assets/javascripts/discourse/services/chat.js b/plugins/chat/assets/javascripts/discourse/services/chat.js
index 16553378838..8cfc46b26ee 100644
--- a/plugins/chat/assets/javascripts/discourse/services/chat.js
+++ b/plugins/chat/assets/javascripts/discourse/services/chat.js
@@ -259,7 +259,7 @@ export default class Chat extends Service {
getDocumentTitleCount() {
if (this.currentUser?.user_option?.title_count_mode === "notifications") {
- return this.chatTrackingStateManager.allChannelUrgentCount;
+ return this.chatTrackingStateManager.allChannelUrgentCount();
} else {
return this.chatPanePendingManager.totalPendingMessageCount;
}
diff --git a/plugins/chat/assets/stylesheets/common/chat-scroll-to-bottom.scss b/plugins/chat/assets/stylesheets/common/chat-scroll-to-bottom.scss
index 2a29c36d5d9..707c227a138 100644
--- a/plugins/chat/assets/stylesheets/common/chat-scroll-to-bottom.scss
+++ b/plugins/chat/assets/stylesheets/common/chat-scroll-to-bottom.scss
@@ -1,37 +1,27 @@
.chat-scroll-to-bottom {
display: flex;
justify-content: center;
- margin: 0 1rem;
position: relative;
- &__arrow {
- display: flex;
- background: var(--primary-medium);
- border-radius: 100%;
- align-items: center;
- justify-content: center;
- height: 32px;
- width: 32px;
- position: relative;
- }
-
&__button {
align-items: center;
justify-content: center;
+ gap: var(--space-2);
position: absolute;
- flex-direction: column;
+ height: 2rem;
bottom: -25px;
- background: none;
+ padding: 0 var(--space-2);
+ background: var(--primary-medium);
opacity: 0;
transition:
opacity 0.25s ease,
transform 0.5s ease;
transform: scale(0.1);
- padding: 0;
z-index: z("dropdown");
+ color: var(--secondary);
.d-icon {
- color: var(--secondary);
+ color: inherit;
}
> * {
@@ -71,4 +61,8 @@
}
}
}
+
+ &__new-messages {
+ font-size: var(--font-down-1-rem);
+ }
}
diff --git a/plugins/chat/config/locales/client.en.yml b/plugins/chat/config/locales/client.en.yml
index b80d1f5a813..df05857647d 100644
--- a/plugins/chat/config/locales/client.en.yml
+++ b/plugins/chat/config/locales/client.en.yml
@@ -315,6 +315,9 @@ en:
other: "You have %{count} unread discussions"
scroll_to_bottom: "Scroll to bottom"
scroll_to_new_messages: "See new messages"
+ new_messages:
+ one: "%{count} new message"
+ other: "%{count} new messages"
sound:
title: "Desktop chat notification sound"
sounds:
diff --git a/plugins/chat/spec/system/message_notifications_mobile_spec.rb b/plugins/chat/spec/system/message_notifications_mobile_spec.rb
index d27a52c9c30..101e28d9d3d 100644
--- a/plugins/chat/spec/system/message_notifications_mobile_spec.rb
+++ b/plugins/chat/spec/system/message_notifications_mobile_spec.rb
@@ -221,5 +221,46 @@ RSpec.describe "Message notifications - mobile", mobile: true do
end
end
end
+
+ context "when viewing a channel" do
+ fab!(:channel_1, :category_channel)
+ fab!(:channel_2, :category_channel)
+ fab!(:user_1, :user)
+
+ before do
+ channel_1.add(current_user)
+ channel_1.add(user_1)
+ channel_2.add(current_user)
+ channel_2.add(user_1)
+
+ Jobs.run_immediately!
+ end
+
+ it "shows back button urgent indicator for mentions in other channels" do
+ chat_page.visit_channel(channel_1)
+
+ create_message(channel_2, user: user_1, message: "hey @#{current_user.username}")
+
+ expect(page).to have_css(".c-navbar__back-button .chat-channel-unread-indicator.-urgent")
+ end
+
+ it "shows back button unread indicator for messages in other channels" do
+ chat_page.visit_channel(channel_1)
+
+ create_message(channel_2, user: user_1)
+
+ expect(page).to have_css(
+ ".c-navbar__back-button .chat-channel-unread-indicator:not(.-urgent)",
+ )
+ end
+
+ it "does not show back button indicator for current channel unreads" do
+ create_message(channel_1, user: user_1, message: "hey @#{current_user.username}")
+
+ chat_page.visit_channel(channel_1)
+
+ expect(page).to have_no_css(".c-navbar__back-button .chat-channel-unread-indicator")
+ end
+ end
end
end
diff --git a/plugins/chat/test/javascripts/unit/services/chat-test.js b/plugins/chat/test/javascripts/unit/services/chat-test.js
index 20b164270a3..cf35d7b44ea 100644
--- a/plugins/chat/test/javascripts/unit/services/chat-test.js
+++ b/plugins/chat/test/javascripts/unit/services/chat-test.js
@@ -20,7 +20,7 @@ acceptance("Discourse Chat | Unit | Service | chat", function (needs) {
);
sinon
.stub(this.chatTrackingStateManager, "allChannelUrgentCount")
- .get(() => 5);
+ .returns(5);
sinon
.stub(this.chatPanePendingManager, "totalPendingMessageCount")
.get(() => 10);