diff --git a/app/models/user_option.rb b/app/models/user_option.rb index 70d80d80522..06eebd364f7 100644 --- a/app/models/user_option.rb +++ b/app/models/user_option.rb @@ -292,6 +292,7 @@ end # enable_experimental_sidebar :boolean default(FALSE) # seen_popups :integer is an Array # sidebar_list_destination :integer default("none_selected"), not null +# chat_header_indicator_preference :integer default(0), not null # # Indexes # diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-header-icon-unread-indicator.hbs b/plugins/chat/assets/javascripts/discourse/components/chat-header-icon-unread-indicator.hbs index 06da5981c31..93c6e38793a 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-header-icon-unread-indicator.hbs +++ b/plugins/chat/assets/javascripts/discourse/components/chat-header-icon-unread-indicator.hbs @@ -1,9 +1,9 @@ -{{#if (gt this.chatChannelsManager.unreadUrgentCount 0)}} +{{#if this.showUrgentIndicator}}
{{this.chatChannelsManager.unreadUrgentCount}}
-{{else if (gt this.chatChannelsManager.unreadCount 0)}} +{{else if this.showUnreadIndicator}}
{{/if}} \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-header-icon-unread-indicator.js b/plugins/chat/assets/javascripts/discourse/components/chat-header-icon-unread-indicator.js index df39429e489..61410f92562 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-header-icon-unread-indicator.js +++ b/plugins/chat/assets/javascripts/discourse/components/chat-header-icon-unread-indicator.js @@ -1,6 +1,44 @@ import { inject as service } from "@ember/service"; import Component from "@glimmer/component"; +import { + HEADER_INDICATOR_PREFERENCE_ALL_NEW, + HEADER_INDICATOR_PREFERENCE_DM_AND_MENTIONS, + HEADER_INDICATOR_PREFERENCE_NEVER, +} from "../controllers/preferences-chat"; export default class ChatHeaderIconUnreadIndicator extends Component { @service chatChannelsManager; + @service currentUser; + + get showUrgentIndicator() { + return ( + this.chatChannelsManager.unreadUrgentCount > 0 && + this.#hasAnyIndicatorPreference([ + HEADER_INDICATOR_PREFERENCE_ALL_NEW, + HEADER_INDICATOR_PREFERENCE_DM_AND_MENTIONS, + ]) + ); + } + + get showUnreadIndicator() { + return ( + this.chatChannelsManager.unreadCount > 0 && + this.#hasAnyIndicatorPreference([HEADER_INDICATOR_PREFERENCE_ALL_NEW]) + ); + } + + get indicatorPreference() { + return this.currentUser.user_option.chat_header_indicator_preference; + } + + #hasAnyIndicatorPreference(preferences) { + if ( + !this.currentUser || + this.indicatorPreference === HEADER_INDICATOR_PREFERENCE_NEVER + ) { + return false; + } + + return preferences.includes(this.indicatorPreference); + } } diff --git a/plugins/chat/assets/javascripts/discourse/controllers/preferences-chat.js b/plugins/chat/assets/javascripts/discourse/controllers/preferences-chat.js index 5774f44b4b5..b5e346b62c4 100644 --- a/plugins/chat/assets/javascripts/discourse/controllers/preferences-chat.js +++ b/plugins/chat/assets/javascripts/discourse/controllers/preferences-chat.js @@ -13,18 +13,39 @@ const CHAT_ATTRS = [ "ignore_channel_wide_mention", "chat_sound", "chat_email_frequency", + "chat_header_indicator_preference", ]; +export const HEADER_INDICATOR_PREFERENCE_NEVER = "never"; +export const HEADER_INDICATOR_PREFERENCE_DM_AND_MENTIONS = "dm_and_mentions"; +export const HEADER_INDICATOR_PREFERENCE_ALL_NEW = "all_new"; + const EMAIL_FREQUENCY_OPTIONS = [ { name: I18n.t(`chat.email_frequency.never`), value: "never" }, { name: I18n.t(`chat.email_frequency.when_away`), value: "when_away" }, ]; +const HEADER_INDICATOR_OPTIONS = [ + { + name: I18n.t(`chat.header_indicator_preference.all_new`), + value: HEADER_INDICATOR_PREFERENCE_ALL_NEW, + }, + { + name: I18n.t(`chat.header_indicator_preference.dm_and_mentions`), + value: HEADER_INDICATOR_PREFERENCE_DM_AND_MENTIONS, + }, + { + name: I18n.t(`chat.header_indicator_preference.never`), + value: HEADER_INDICATOR_PREFERENCE_NEVER, + }, +]; + export default class PreferencesChatController extends Controller { @service chatAudioManager; subpageTitle = I18n.t("chat.admin.title"); emailFrequencyOptions = EMAIL_FREQUENCY_OPTIONS; + headerIndicatorOptions = HEADER_INDICATOR_OPTIONS; @discourseComputed chatSounds() { diff --git a/plugins/chat/assets/javascripts/discourse/initializers/chat-user-options.js b/plugins/chat/assets/javascripts/discourse/initializers/chat-user-options.js index e7b9af19561..c410763d713 100644 --- a/plugins/chat/assets/javascripts/discourse/initializers/chat-user-options.js +++ b/plugins/chat/assets/javascripts/discourse/initializers/chat-user-options.js @@ -5,6 +5,7 @@ const ONLY_CHAT_PUSH_NOTIFICATIONS_FIELD = "only_chat_push_notifications"; const IGNORE_CHANNEL_WIDE_MENTION = "ignore_channel_wide_mention"; const CHAT_SOUND = "chat_sound"; const CHAT_EMAIL_FREQUENCY = "chat_email_frequency"; +const CHAT_HEADER_INDICATOR_PREFERENCE = "chat_header_indicator_preference"; export default { name: "chat-user-options", @@ -18,6 +19,7 @@ export default { api.addSaveableUserOptionField(IGNORE_CHANNEL_WIDE_MENTION); api.addSaveableUserOptionField(CHAT_SOUND); api.addSaveableUserOptionField(CHAT_EMAIL_FREQUENCY); + api.addSaveableUserOptionField(CHAT_HEADER_INDICATOR_PREFERENCE); } }); }, diff --git a/plugins/chat/assets/javascripts/discourse/templates/preferences/chat.hbs b/plugins/chat/assets/javascripts/discourse/templates/preferences/chat.hbs index a2e2d00cc37..740c22da1f1 100644 --- a/plugins/chat/assets/javascripts/discourse/templates/preferences/chat.hbs +++ b/plugins/chat/assets/javascripts/discourse/templates/preferences/chat.hbs @@ -69,6 +69,21 @@ {{/if}} +
+ + +
+