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
Joffrey JAFFEUX d127d2acdf
FIX: allows to change sound when no sound was ever set (#19136)
It fixes a bug which was only allowing users with a sound to change it. Users with `none` could not change it again after a full page reset.
2022-11-22 08:57:06 +01:00

57 lines
1.5 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",
];
const EMAIL_FREQUENCY_OPTIONS = [
{ name: I18n.t(`chat.email_frequency.never`), value: "never" },
{ name: I18n.t(`chat.email_frequency.when_away`), value: "when_away" },
];
export default class PreferencesChatController extends Controller {
@service chatAudioManager;
emailFrequencyOptions = EMAIL_FREQUENCY_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);
}
}