-
Notifications
You must be signed in to change notification settings - Fork 8.2k
/
preferences-chat.js
105 lines (94 loc) · 2.94 KB
/
preferences-chat.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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",
"chat_separate_sidebar_mode",
];
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 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 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,
},
];
const CHAT_SEPARATE_SIDEBAR_MODE_OPTIONS = [
{
name: I18n.t("admin.site_settings.chat_separate_sidebar_mode.always"),
value: "always",
},
{
name: I18n.t("admin.site_settings.chat_separate_sidebar_mode.fullscreen"),
value: "fullscreen",
},
{
name: I18n.t("admin.site_settings.chat_separate_sidebar_mode.never"),
value: "never",
},
];
export default class PreferencesChatController extends Controller {
@service chatAudioManager;
@service siteSettings;
subpageTitle = I18n.t("chat.admin.title");
emailFrequencyOptions = EMAIL_FREQUENCY_OPTIONS;
headerIndicatorOptions = HEADER_INDICATOR_OPTIONS;
chatSeparateSidebarModeOptions = CHAT_SEPARATE_SIDEBAR_MODE_OPTIONS;
get chatSeparateSidebarMode() {
const mode = this.model.get("user_option.chat_separate_sidebar_mode");
if (mode === "default") {
return this.siteSettings.chat_separate_sidebar_mode;
} else {
return mode;
}
}
@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);
}
}