This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/plugins/chat/assets/javascripts/discourse/components/chat-header-icon-unread-indicator.js
Martin Brennan d3a1b09361
FEATURE: Chat header icon indicator preference (#20474)
This commit allows the user to set their preference vis-a-vis
the chat icon in the header of the page. There are three options:

- All New (default) - This maintains the existing behaviour where
  all new messages in the channel show a blue dot on the icon
- Direct Messages and Mentions - Only show the green dot on the
  icon when you are directly messaged or mentioned, the blue dot
  is never shown
- Never - Never show any dot on the chat icon, for those who
  want tractor-beam-laser-focus
2023-03-01 11:01:44 +10:00

45 lines
1.2 KiB
JavaScript

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);
}
}