Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions assets/javascripts/discourse/controllers/preferences-chat.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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";
Expand All @@ -22,7 +23,7 @@ export default Controller.extend({

@action
onChangeChatSound(sound) {
if (sound) {
if (sound && !isTesting()) {
const audio = new Audio(CHAT_SOUNDS[sound]);
audio.play();
}
Expand All @@ -36,7 +37,9 @@ export default Controller.extend({
.save(chatAttrs)
.then(() => {
this.set("saved", true);
location.reload();
if (!isTesting()) {
location.reload();
}
})
.catch(popupAjaxError);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export default {

initialize(container) {
withPluginApi("0.11.0", (api) => {
const chatService = container.lookup("service:chat");
if (chatService.userCanChat) {
const siteSettings = container.lookup("site-settings:main");
if (siteSettings.chat_enabled) {
api.addSaveableUserOptionField(CHAT_ENABLED_FIELD);
api.addSaveableUserOptionField(CHAT_ISOLATED_FIELD);
api.addSaveableUserOptionField(ONLY_CHAT_PUSH_NOTI_FIELD);
Expand Down
9 changes: 6 additions & 3 deletions assets/javascripts/discourse/templates/preferences/chat.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<div class="control-group chat-setting">
<label class="controls">
{{input
id="user_chat_enabled"
type="checkbox"
checked=model.user_option.chat_enabled
}}
Expand All @@ -13,6 +14,7 @@
<div class="control-group chat-setting">
<label class="controls">
{{input
id="user_chat_only_push_notifications"
type="checkbox"
checked=model.user_option.only_chat_push_notifications
}}
Expand All @@ -24,6 +26,7 @@
<div class="control-group chat-setting">
<label class="controls">
{{input
id="user_chat_isolated"
type="checkbox"
checked=model.user_option.chat_isolated
}}
Expand All @@ -33,15 +36,15 @@
</div>

<div class="control-group chat-setting controls-dropdown">
<label for="chat-sounds">{{i18n "chat.sound.title"}}</label>
<label for="user_chat_sounds">{{i18n "chat.sound.title"}}</label>
{{combo-box
none="chat.sounds.none"
valueProperty="value"
content=chatSounds
value=model.user_option.chat_sound
id="chat-sounds"
id="user_chat_sounds"
onChange=(action "onChangeChatSound")
}}
</div>

{{save-controls model=model action=(action "save") saved=saved}}
{{save-controls id="user_chat_preference_save" model=model action=(action "save") saved=saved}}
28 changes: 28 additions & 0 deletions test/javascripts/acceptance/chat-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import selectKit from "discourse/tests/helpers/select-kit-helper";
import { next } from "@ember/runloop";
import { Promise } from "rsvp";
import { isLegacyEmber } from "discourse-common/config/environment";
import sinon from "sinon";
import * as ajaxlib from "discourse/lib/ajax";

const chatSettled = async () => {
await settled();
Expand Down Expand Up @@ -1225,6 +1227,32 @@ acceptance("Discourse Chat - chat preferences", function (needs) {
assert.equal(currentURL(), "/u/eviltrout/preferences/chat");
assert.equal(queryAll(".chat-setting").length, 4);
});

test("The user can save the settings", async function (assert) {
updateCurrentUser({ has_chat_enabled: false });
const spy = sinon.spy(ajaxlib, "ajax");
await visit("/u/eviltrout/preferences/chat");
await click("#user_chat_enabled");
await click("#user_chat_only_push_notifications");
await click("#user_chat_isolated");
await selectKit("#user_chat_sounds").expand();
await selectKit("#user_chat_sounds").selectRowByValue("bell");

await click(".save-changes");

assert.ok(
spy.calledWithMatch("/u/eviltrout.json", {
data: {
chat_enabled: true,
chat_isolated: true,
chat_sound: "bell",
only_chat_push_notifications: true,
},
type: "PUT",
}),
"is able to save the chat preferences for the user"
);
});
});

acceptance("Discourse Chat - image uploads", function (needs) {
Expand Down