A platform for community discussion. Free, open, simple.
FEATURE: Chat thread header indicator improvements (#21807)
Martin Brennan6ec6cfccf8b1
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-drawer/header/right-actions.hbs b/plugins/chat/assets/javascripts/discourse/components/chat-drawer/header/right-actions.hbsindex ed1b1934e2e..dd13664d459 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-drawer/header/right-actions.hbs+++ b/plugins/chat/assets/javascripts/discourse/components/chat-drawer/header/right-actions.hbs@@ -1,6 +1,6 @@<div class="chat-drawer-header__right-actions"><div class="chat-drawer-header__top-line">- {{#if this.chat.activeChannel.threadingEnabled}}+ {{#if this.showThreadsListButton}}<Chat::Thread::ThreadsListButton @channel={{this.chat.activeChannel}} />{{/if}}diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-drawer/header/right-actions.js b/plugins/chat/assets/javascripts/discourse/components/chat-drawer/header/right-actions.jsindex fe0826ce799..48e034e6d94 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-drawer/header/right-actions.js+++ b/plugins/chat/assets/javascripts/discourse/components/chat-drawer/header/right-actions.js@@ -3,5 +3,8 @@ import { inject as service } from "@ember/service";export default class ChatDrawerHeaderRightActions extends Component {@service chat;- @service chatStateManager;++ get showThreadsListButton() {+ return this.chat.activeChannel?.threadingEnabled;+ }}diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-full-page-header.hbs b/plugins/chat/assets/javascripts/discourse/components/chat-full-page-header.hbsindex 7dcbb9369a2..e8741914332 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-full-page-header.hbs+++ b/plugins/chat/assets/javascripts/discourse/components/chat-full-page-header.hbs@@ -40,7 +40,7 @@/>{{/if}}- {{#if @channel.threadingEnabled}}+ {{#if this.showThreadsListButton}}<Chat::Thread::ThreadsListButton @channel={{@channel}} />{{/if}}</div>diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-full-page-header.js b/plugins/chat/assets/javascripts/discourse/components/chat-full-page-header.jsindex cb7724a7f4b..055ed2d0368 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-full-page-header.js+++ b/plugins/chat/assets/javascripts/discourse/components/chat-full-page-header.js@@ -4,8 +4,17 @@ import Component from "@glimmer/component";export default class ChatFullPageHeader extends Component {@service site;@service chatStateManager;+ @service router;get displayed() {return this.args.displayed ?? true;}++ get showThreadsListButton() {+ return (+ this.args.channel.threadingEnabled &&+ this.router.currentRoute.name !== "chat.channel.threads" &&+ this.router.currentRoute.name !== "chat.channel.thread"+ );+ }}diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/thread/header-unread-indicator.hbs b/plugins/chat/assets/javascripts/discourse/components/chat/thread/header-unread-indicator.hbsindex 5282ed4a2f8..05283d38870 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat/thread/header-unread-indicator.hbs+++ b/plugins/chat/assets/javascripts/discourse/components/chat/thread/header-unread-indicator.hbs@@ -1,5 +1,9 @@{{#if this.showUnreadIndicator}}- <div class="chat-thread-header-unread-indicator">+ <div+ class="chat-thread-header-unread-indicator"+ aria-label={{i18n "chat.unread_threads_count" count=this.unreadCountLabel}}+ title={{i18n "chat.unread_threads_count" count=this.unreadCountLabel}}+ ><div class="chat-thread-header-unread-indicator__number-wrap"><divclass="chat-thread-header-unread-indicator__number"diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/thread/header-unread-indicator.js b/plugins/chat/assets/javascripts/discourse/components/chat/thread/header-unread-indicator.jsindex 57bde77d9fb..6abaf2f08cb 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat/thread/header-unread-indicator.js+++ b/plugins/chat/assets/javascripts/discourse/components/chat/thread/header-unread-indicator.js@@ -1,12 +1,19 @@import Component from "@glimmer/component";+import { inject as service } from "@ember/service";export default class ChatThreadHeaderUnreadIndicator extends Component {+ @service currentUser;++ get currentUserInDnD() {+ return this.currentUser.isInDoNotDisturb();+ }+get unreadCount() {return this.args.channel.unreadThreadCount;}get showUnreadIndicator() {- return this.unreadCount > 0;+ return !this.currentUserInDnD && this.unreadCount > 0;}get unreadCountLabel() {diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/thread/header.hbs b/plugins/chat/assets/javascripts/discourse/components/chat/thread/header.hbsindex 74fde3c22c6..68425da1056 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat/thread/header.hbs+++ b/plugins/chat/assets/javascripts/discourse/components/chat/thread/header.hbs@@ -1,4 +1,18 @@<div class="chat-thread-header">+ <div class="chat-thread-header__left-buttons">+ {{#if @thread}}+ <LinkTo+ class="chat-thread__back-to-list btn-flat btn btn-icon no-text"+ @route="chat.channel.threads"+ @models={{@channel.routeModels}}+ title={{i18n "chat.return_to_threads_list"}}+ >+ <Chat::Thread::HeaderUnreadIndicator @channel={{@channel}} />+ {{d-icon "chevron-left"}}+ </LinkTo>+ {{/if}}+ </div>+<span class="chat-thread-header__label overflow-ellipsis">{{replace-emoji this.label}}</span>diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/thread/threads-list-button.hbs b/plugins/chat/assets/javascripts/discourse/components/chat/thread/threads-list-button.hbsindex e9cbdd6fd5d..fd0ef325d75 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat/thread/threads-list-button.hbs+++ b/plugins/chat/assets/javascripts/discourse/components/chat/thread/threads-list-button.hbs@@ -9,7 +9,5 @@>{{d-icon "discourse-threads"}}- {{#unless this.currentUserInDnD}}- <Chat::Thread::HeaderUnreadIndicator @channel={{@channel}} />- {{/unless}}+ <Chat::Thread::HeaderUnreadIndicator @channel={{@channel}} /></LinkTo>\ No newline at end of filediff --git a/plugins/chat/assets/javascripts/discourse/components/chat/thread/threads-list-button.js b/plugins/chat/assets/javascripts/discourse/components/chat/thread/threads-list-button.jsindex c468cf54838..c383e020f9d 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat/thread/threads-list-button.js+++ b/plugins/chat/assets/javascripts/discourse/components/chat/thread/threads-list-button.js@@ -1,10 +1,3 @@-import { inject as service } from "@ember/service";import Component from "@glimmer/component";-export default class ChatThreadsListButton extends Component {- @service currentUser;-- get currentUserInDnD() {- return this.currentUser.isInDoNotDisturb();- }-}+export default class ChatThreadsListButton extends Component {}diff --git a/plugins/chat/assets/stylesheets/common/chat-thread-header-button.scss b/plugins/chat/assets/stylesheets/common/chat-thread-header-button.scssindex 7a457684697..89887dcfb64 100644--- a/plugins/chat/assets/stylesheets/common/chat-thread-header-button.scss+++ b/plugins/chat/assets/stylesheets/common/chat-thread-header-button.scss@@ -2,8 +2,8 @@position: relative;display: flex;align-items: center;- border: 1px solid var(--blend-primary-secondary-5);border-radius: 5px;+ padding: 0.5rem 0;@include chat-channel-header-button;@@ -11,6 +11,12 @@.d-icon {color: var(--tertiary-med-or-tertiary);}++ &:hover {+ .d-icon {+ color: var(--tertiary-med-or-tertiary);+ }+ }}.d-icon {diff --git a/plugins/chat/assets/stylesheets/common/chat-thread-header.scss b/plugins/chat/assets/stylesheets/common/chat-thread-header.scssindex 329de6cc489..be7f7698db4 100644--- a/plugins/chat/assets/stylesheets/common/chat-thread-header.scss+++ b/plugins/chat/assets/stylesheets/common/chat-thread-header.scss@@ -6,10 +6,21 @@box-sizing: border-box;display: flex;align-items: center;- justify-content: space-between;- padding-inline: 1rem;+ padding-inline: 0.5rem;++ .chat-thread__back-to-list {+ padding: 0.5rem 0;+ margin-right: 0.5rem;+ }&__buttons {display: flex;+ margin-left: auto;+ }++ &__left-buttons {+ display: flex;+ flex-direction: row;+ align-items: center;}}diff --git a/plugins/chat/assets/stylesheets/common/chat-thread-list-item.scss b/plugins/chat/assets/stylesheets/common/chat-thread-list-item.scssindex 0c2fdf1b83c..4c3a1b250c4 100644--- a/plugins/chat/assets/stylesheets/common/chat-thread-list-item.scss+++ b/plugins/chat/assets/stylesheets/common/chat-thread-list-item.scss@@ -10,7 +10,7 @@.chat-thread-list-item {@include thread-list-item;cursor: pointer;- margin: 0.5rem 0.25rem 0.25rem;+ margin: 0.25rem;& + .chat-thread-list-item {margin-top: 0;diff --git a/plugins/chat/config/locales/client.en.yml b/plugins/chat/config/locales/client.en.ymlindex 2a140ac9d96..780cd098ce8 100644--- a/plugins/chat/config/locales/client.en.yml+++ b/plugins/chat/config/locales/client.en.yml@@ -251,6 +251,9 @@ en:select: "Select"return_to_list: "Return to channels list"return_to_threads_list: "Return to ongoing discussions"+ unread_threads_count:+ one: "You have %{count} unread discussion"+ other: "You have %{count} unread discussions"scroll_to_bottom: "Scroll to bottom"scroll_to_new_messages: "See new messages"sound:diff --git a/plugins/chat/spec/system/page_objects/chat/chat_thread.rb b/plugins/chat/spec/system/page_objects/chat/chat_thread.rbindex 298f6615c25..ab7f396e10e 100644--- a/plugins/chat/spec/system/page_objects/chat/chat_thread.rb+++ b/plugins/chat/spec/system/page_objects/chat/chat_thread.rb@@ -24,6 +24,21 @@ module PageObjectsheader.find(".chat-thread__close").clickend+ def back_to_list+ header.find(".chat-thread__back-to-list").click+ end++ def has_no_unread_list_indicator?+ has_no_css?(".chat-thread__back-to-list .chat-thread-header-unread-indicator")+ end++ def has_unread_list_indicator?(count:)+ has_css?(+ ".chat-thread__back-to-list .chat-thread-header-unread-indicator .chat-thread-header-unread-indicator__number-wrap",+ text: count.to_s,+ )+ end+def has_no_loading_skeleton?has_no_css?(".chat-thread__messages .chat-skeleton")enddiff --git a/plugins/chat/spec/system/thread_tracking/full_page_spec.rb b/plugins/chat/spec/system/thread_tracking/full_page_spec.rbindex a94154b659b..192d26881d3 100644--- a/plugins/chat/spec/system/thread_tracking/full_page_spec.rb+++ b/plugins/chat/spec/system/thread_tracking/full_page_spec.rb@@ -39,28 +39,27 @@ describe "Thread tracking state | full page", type: :system, js: true dochat_page.visit_channel(channel)channel_page.open_thread_listthread_list_page.item_by_id(thread.id).click- expect(channel_page).to have_no_unread_thread_indicator- channel_page.open_thread_list+ expect(thread_page).to have_no_unread_list_indicator+ thread_page.back_to_listexpect(thread_list_page).to have_no_unread_item(thread.id)end- it "shows unread indicators for the header icon and the list when a new unread arrives" do+ it "shows unread indicators for the header of the list when a new unread arrives" domessage_1.trash!chat_page.visit_channel(channel)channel_page.open_thread_list- expect(channel_page).to have_no_unread_thread_indicatorexpect(thread_list_page).to have_no_unread_item(thread.id)Fabricate(:chat_message, chat_channel: channel, thread: thread)- expect(channel_page).to have_unread_thread_indicator(count: 1)expect(thread_list_page).to have_unread_item(thread.id)endit "does not change the unread indicator for the header icon when the user is not a member of the thread" dothread.remove(current_user)chat_page.visit_channel(channel)- channel_page.open_thread_list+ expect(channel_page).to have_no_unread_thread_indicatorFabricate(:chat_message, chat_channel: channel, thread: thread)expect(channel_page).to have_no_unread_thread_indicator+ channel_page.open_thread_listexpect(thread_list_page).to have_no_unread_item(thread.id)endend