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/controllers/preferences-chat.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

79 lines
2.2 KiB
JavaScript

import Controller from "@ember/controller";
import { isTesting } from "discourse-common/config/environment";
import discourseComputed from "discourse-common/utils/decorators";
import I18n from "I18n";
import { action } from "@ember/object";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { CHAT_SOUNDS } from "discourse/plugins/chat/discourse/services/chat-audio-manager";
import { inject as service } from "@ember/service";
const CHAT_ATTRS = [
"chat_enabled",
"only_chat_push_notifications",
"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() {
return Object.keys(CHAT_SOUNDS).map((value) => {
return { name: I18n.t(`chat.sounds.${value}`), value };
});
}
@action
onChangeChatSound(sound) {
if (sound) {
this.chatAudioManager.playImmediately(sound);
}
this.model.set("user_option.chat_sound", sound);
}
@action
save() {
this.set("saved", false);
return this.model
.save(CHAT_ATTRS)
.then(() => {
this.set("saved", true);
if (!isTesting()) {
location.reload();
}
})
.catch(popupAjaxError);
}
}