notifications: Split out audible_notifications module.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2023-10-06 15:09:47 -07:00 committed by Tim Abbott
parent 6ef08873d8
commit fcaf1fe7d5
8 changed files with 38 additions and 32 deletions

View File

@ -54,6 +54,7 @@ EXEMPT_FILES = make_set(
"web/src/archive.js",
"web/src/assets.d.ts",
"web/src/attachments_ui.ts",
"web/src/audible_notifications.js",
"web/src/avatar.ts",
"web/src/billing/event_status.ts",
"web/src/billing/helpers.ts",

View File

@ -0,0 +1,24 @@
import $ from "jquery";
import {user_settings} from "./user_settings";
export function initialize() {
update_notification_sound_source($("#user-notification-sound-audio"), user_settings);
}
export function update_notification_sound_source(container_elem, settings_object) {
const notification_sound = settings_object.notification_sound;
const audio_file_without_extension = "/static/audio/notification_sounds/" + notification_sound;
container_elem
.find(".notification-sound-source-ogg")
.attr("src", `${audio_file_without_extension}.ogg`);
container_elem
.find(".notification-sound-source-mp3")
.attr("src", `${audio_file_without_extension}.mp3`);
if (notification_sound !== "none") {
// Load it so that it is ready to be played; without this the old sound
// is played.
container_elem[0].load();
}
}

View File

@ -1,7 +1,5 @@
import $ from "jquery";
import {user_settings} from "./user_settings";
export const notice_memory = new Map();
export let NotificationAPI;
@ -50,25 +48,6 @@ export function initialize() {
}
notice_memory.clear();
});
update_notification_sound_source($("#user-notification-sound-audio"), user_settings);
}
export function update_notification_sound_source(container_elem, settings_object) {
const notification_sound = settings_object.notification_sound;
const audio_file_without_extension = "/static/audio/notification_sounds/" + notification_sound;
container_elem
.find(".notification-sound-source-ogg")
.attr("src", `${audio_file_without_extension}.ogg`);
container_elem
.find(".notification-sound-source-mp3")
.attr("src", `${audio_file_without_extension}.mp3`);
if (notification_sound !== "none") {
// Load it so that it is ready to be played; without this the old sound
// is played.
container_elem[0].load();
}
}
export function permission_state() {

View File

@ -4,6 +4,7 @@ import * as activity_ui from "./activity_ui";
import * as alert_words from "./alert_words";
import * as alert_words_ui from "./alert_words_ui";
import * as attachments_ui from "./attachments_ui";
import * as audible_notifications from "./audible_notifications";
import * as blueslip from "./blueslip";
import * as bot_data from "./bot_data";
import * as browser_history from "./browser_history";
@ -30,7 +31,6 @@ import * as muted_users_ui from "./muted_users_ui";
import * as narrow_state from "./narrow_state";
import * as narrow_title from "./narrow_title";
import * as navbar_alerts from "./navbar_alerts";
import * as notifications from "./notifications";
import * as overlays from "./overlays";
import {page_params} from "./page_params";
import * as peer_data from "./peer_data";
@ -450,7 +450,7 @@ export function dispatch_normal_event(event) {
settings_realm_user_settings_defaults.update_page(event.property);
if (event.property === "notification_sound") {
notifications.update_notification_sound_source(
audible_notifications.update_notification_sound_source(
$("#realm-default-notification-sound-audio"),
realm_user_settings_defaults,
);
@ -673,7 +673,7 @@ export function dispatch_normal_event(event) {
if (notification_name === "notification_sound") {
// Change the sound source with the new page `notification_sound`.
notifications.update_notification_sound_source(
audible_notifications.update_notification_sound_source(
$("#user-notification-sound-audio"),
user_settings,
);

View File

@ -5,6 +5,7 @@ import render_compose_banner from "../templates/compose_banner/compose_banner.hb
import render_settings_deactivate_realm_modal from "../templates/confirm_dialog/confirm_deactivate_realm.hbs";
import render_settings_admin_auth_methods_list from "../templates/settings/admin_auth_methods_list.hbs";
import * as audible_notifications from "./audible_notifications";
import * as blueslip from "./blueslip";
import * as channel from "./channel";
import * as compose_banner from "./compose_banner";
@ -14,7 +15,6 @@ import * as dropdown_widget from "./dropdown_widget";
import {$t, $t_html, get_language_name} from "./i18n";
import * as keydown_util from "./keydown_util";
import * as loading from "./loading";
import * as notifications from "./notifications";
import {page_params} from "./page_params";
import * as realm_icon from "./realm_icon";
import * as realm_logo from "./realm_logo";
@ -717,7 +717,7 @@ export function discard_property_element_changes(elem, for_realm_default_setting
switch (property_name) {
case "notification_sound":
notifications.update_notification_sound_source(
audible_notifications.update_notification_sound_source(
$("#realm-default-notification-sound-audio"),
{
notification_sound: property_value,

View File

@ -1,6 +1,6 @@
import $ from "jquery";
import * as notifications from "./notifications";
import * as audible_notifications from "./audible_notifications";
import * as overlays from "./overlays";
import {page_params} from "./page_params";
import {realm_user_settings_defaults} from "./realm_user_settings_defaults";
@ -59,14 +59,14 @@ export function set_up() {
settings_display.set_up(realm_default_settings_panel);
notifications.update_notification_sound_source(
audible_notifications.update_notification_sound_source(
$notification_sound_elem,
realm_default_settings_panel.settings_object,
);
$notification_sound_dropdown.on("change", () => {
const sound = $notification_sound_dropdown.val().toLowerCase();
notifications.update_notification_sound_source($notification_sound_elem, {
audible_notifications.update_notification_sound_source($notification_sound_elem, {
notification_sound: sound,
});
});

View File

@ -16,6 +16,7 @@ import * as activity from "./activity";
import * as activity_ui from "./activity_ui";
import * as add_stream_options_popover from "./add_stream_options_popover";
import * as alert_words from "./alert_words";
import * as audible_notifications from "./audible_notifications";
import * as blueslip from "./blueslip";
import * as bot_data from "./bot_data";
import * as channel from "./channel";
@ -670,6 +671,7 @@ export function initialize_everything() {
});
tutorial.initialize();
notifications.initialize();
audible_notifications.initialize();
compose_notifications.initialize({
on_click_scroll_to_selected: navigate.scroll_to_selected,
on_narrow_to_recipient(message_id) {

View File

@ -22,6 +22,7 @@ set_global("requestAnimationFrame", (func) => func());
const activity_ui = mock_esm("../src/activity_ui");
const alert_words_ui = mock_esm("../src/alert_words_ui");
const attachments_ui = mock_esm("../src/attachments_ui");
const audible_notifications = mock_esm("../src/audible_notifications");
const bot_data = mock_esm("../src/bot_data");
const compose_pm_pill = mock_esm("../src/compose_pm_pill");
const composebox_typeahead = mock_esm("../src/composebox_typeahead");
@ -35,7 +36,6 @@ const message_lists = mock_esm("../src/message_lists");
const user_topics_ui = mock_esm("../src/user_topics_ui");
const muted_users_ui = mock_esm("../src/muted_users_ui");
const narrow_title = mock_esm("../src/narrow_title");
const notifications = mock_esm("../src/notifications");
const pm_list = mock_esm("../src/pm_list");
const reactions = mock_esm("../src/reactions");
const realm_icon = mock_esm("../src/realm_icon");
@ -1016,7 +1016,7 @@ run_test("user_settings", ({override}) => {
}
event = event_fixtures.user_settings__notification_sound;
override(notifications, "update_notification_sound_source", noop);
override(audible_notifications, "update_notification_sound_source", noop);
dispatch(event);
event = event_fixtures.user_settings__email_address_visibility;
@ -1189,7 +1189,7 @@ run_test("realm_user_settings_defaults", ({override}) => {
event = event_fixtures.realm_user_settings_defaults__notification_sound;
realm_user_settings_defaults.notification_sound = "zulip";
let called = false;
notifications.update_notification_sound_source = () => {
audible_notifications.update_notification_sound_source = () => {
called = true;
};
dispatch(event);