From 03aa67ed6851678d47f557314ed49763ece09f2a Mon Sep 17 00:00:00 2001
From: nimbleghost <132819643+nimbleghost@users.noreply.github.com>
Date: Wed, 7 Jun 2023 20:36:20 +0200
Subject: [PATCH] Remove `webPushDefaultEnabled`
---
web/public/static/langs/en.json | 5 ----
web/src/app/Prefs.js | 9 -------
web/src/app/SubscriptionManager.js | 4 ---
web/src/components/Preferences.jsx | 32 ------------------------
web/src/components/SubscribeDialog.jsx | 18 +------------
web/src/components/SubscriptionPopup.jsx | 20 ++++++---------
6 files changed, 8 insertions(+), 80 deletions(-)
diff --git a/web/public/static/langs/en.json b/web/public/static/langs/en.json
index 2d58311a..80994504 100644
--- a/web/public/static/langs/en.json
+++ b/web/public/static/langs/en.json
@@ -369,11 +369,6 @@
"prefs_reservations_dialog_description": "Reserving a topic gives you ownership over the topic, and allows you to define access permissions for other users over the topic.",
"prefs_reservations_dialog_topic_label": "Topic",
"prefs_reservations_dialog_access_label": "Access",
- "prefs_notifications_web_push_default_title": "Enable web push notifications by default",
- "prefs_notifications_web_push_default_description": "This affects the initial state in the subscribe dialog, as well as the default state for synced topics",
- "prefs_notifications_web_push_default_initial": "Unset",
- "prefs_notifications_web_push_default_enabled": "Enabled",
- "prefs_notifications_web_push_default_disabled": "Disabled",
"reservation_delete_dialog_description": "Removing a reservation gives up ownership over the topic, and allows others to reserve it. You can keep, or delete existing messages and attachments.",
"reservation_delete_dialog_action_keep_title": "Keep cached messages and attachments",
"reservation_delete_dialog_action_keep_description": "Messages and attachments that are cached on the server will become publicly visible for people with knowledge of the topic name.",
diff --git a/web/src/app/Prefs.js b/web/src/app/Prefs.js
index 22f767af..75ac3ab5 100644
--- a/web/src/app/Prefs.js
+++ b/web/src/app/Prefs.js
@@ -31,15 +31,6 @@ class Prefs {
const deleteAfter = await this.db.prefs.get("deleteAfter");
return deleteAfter ? Number(deleteAfter.value) : 604800; // Default is one week
}
-
- async webPushDefaultEnabled() {
- const obj = await this.db.prefs.get("webPushDefaultEnabled");
- return obj?.value ?? "initial";
- }
-
- async setWebPushDefaultEnabled(enabled) {
- await this.db.prefs.put({ key: "webPushDefaultEnabled", value: enabled ? "enabled" : "disabled" });
- }
}
const prefs = new Prefs(getDb());
diff --git a/web/src/app/SubscriptionManager.js b/web/src/app/SubscriptionManager.js
index 3cdaa85e..6b82531d 100644
--- a/web/src/app/SubscriptionManager.js
+++ b/web/src/app/SubscriptionManager.js
@@ -78,16 +78,12 @@ class SubscriptionManager {
async syncFromRemote(remoteSubscriptions, remoteReservations) {
console.log(`[SubscriptionManager] Syncing subscriptions from remote`, remoteSubscriptions);
- const webPushEnabled = (await prefs.webPushDefaultEnabled()) === "enabled";
-
// Add remote subscriptions
const remoteIds = await Promise.all(
remoteSubscriptions.map(async (remote) => {
const reservation = remoteReservations?.find((r) => remote.base_url === config.base_url && remote.topic === r.topic) || null;
const local = await this.add(remote.base_url, remote.topic, {
- // only if same-origin subscription
- webPushEnabled: webPushEnabled && remote.base_url === config.base_url,
displayName: remote.display_name, // May be undefined
reservation, // May be null!
});
diff --git a/web/src/components/Preferences.jsx b/web/src/components/Preferences.jsx
index 37f9f772..4afc0f80 100644
--- a/web/src/components/Preferences.jsx
+++ b/web/src/components/Preferences.jsx
@@ -48,7 +48,6 @@ import { PermissionDenyAll, PermissionRead, PermissionReadWrite, PermissionWrite
import { ReserveAddDialog, ReserveDeleteDialog, ReserveEditDialog } from "./ReserveDialogs";
import { UnauthorizedError } from "../app/errors";
import { subscribeTopic } from "./SubscribeDialog";
-import notifier from "../app/Notifier";
const maybeUpdateAccountSettings = async (payload) => {
if (!session.exists()) {
@@ -86,7 +85,6 @@ const Notifications = () => {
- {notifier.pushPossible() && }
);
@@ -234,36 +232,6 @@ const DeleteAfter = () => {
);
};
-const WebPushDefaultEnabled = () => {
- const { t } = useTranslation();
- const labelId = "prefWebPushDefaultEnabled";
- const defaultEnabled = useLiveQuery(async () => prefs.webPushDefaultEnabled());
- const handleChange = async (ev) => {
- await prefs.setWebPushDefaultEnabled(ev.target.value);
- };
-
- // while loading
- if (defaultEnabled == null) {
- return null;
- }
-
- return (
-
-
-
-
-
- );
-};
-
const Users = () => {
const { t } = useTranslation();
const [dialogKey, setDialogKey] = useState(0);
diff --git a/web/src/components/SubscribeDialog.jsx b/web/src/components/SubscribeDialog.jsx
index ad311d5e..8c5d7e45 100644
--- a/web/src/components/SubscribeDialog.jsx
+++ b/web/src/components/SubscribeDialog.jsx
@@ -14,7 +14,6 @@ import {
Switch,
} from "@mui/material";
import { useTranslation } from "react-i18next";
-import { useLiveQuery } from "dexie-react-hooks";
import theme from "./theme";
import api from "../app/Api";
import { randomAlphanumericString, topicUrl, validTopic, validUrl } from "../app/utils";
@@ -30,7 +29,6 @@ import { AccountContext } from "./App";
import { TopicReservedError, UnauthorizedError } from "../app/errors";
import { ReserveLimitChip } from "./SubscriptionPopup";
import notifier from "../app/Notifier";
-import prefs from "../app/Prefs";
const publicBaseUrl = "https://ntfy.sh";
@@ -55,8 +53,6 @@ const SubscribeDialog = (props) => {
const [showLoginPage, setShowLoginPage] = useState(false);
const fullScreen = useMediaQuery(theme.breakpoints.down("sm"));
- const webPushDefaultEnabled = useLiveQuery(async () => prefs.webPushDefaultEnabled());
-
const handleSuccess = async (webPushEnabled) => {
console.log(`[SubscribeDialog] Subscribing to topic ${topic}`);
const actualBaseUrl = baseUrl || config.base_url;
@@ -64,20 +60,9 @@ const SubscribeDialog = (props) => {
webPushEnabled,
});
poller.pollInBackground(subscription); // Dangle!
-
- // if the user hasn't changed the default web push setting yet, set it to enabled
- if (webPushEnabled && webPushDefaultEnabled === "initial") {
- await prefs.setWebPushDefaultEnabled(true);
- }
-
props.onSuccess(subscription);
};
- // wait for liveQuery load
- if (webPushDefaultEnabled === undefined) {
- return <>>;
- }
-
return (