mirror of
https://github.com/binwiederhier/ntfy.git
synced 2024-11-22 19:33:27 +01:00
Remove webPushDefaultEnabled
This commit is contained in:
parent
46f34ca1e3
commit
03aa67ed68
6 changed files with 8 additions and 80 deletions
|
@ -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.",
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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!
|
||||
});
|
||||
|
|
|
@ -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 = () => {
|
|||
<Sound />
|
||||
<MinPriority />
|
||||
<DeleteAfter />
|
||||
{notifier.pushPossible() && <WebPushDefaultEnabled />}
|
||||
</PrefGroup>
|
||||
</Card>
|
||||
);
|
||||
|
@ -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 (
|
||||
<Pref
|
||||
labelId={labelId}
|
||||
title={t("prefs_notifications_web_push_default_title")}
|
||||
description={t("prefs_notifications_web_push_default_description")}
|
||||
>
|
||||
<FormControl fullWidth variant="standard" sx={{ m: 1 }}>
|
||||
<Select value={defaultEnabled} onChange={handleChange} aria-labelledby={labelId}>
|
||||
{defaultEnabled === "initial" && <MenuItem value="initial">{t("prefs_notifications_web_push_default_initial")}</MenuItem>}
|
||||
<MenuItem value="enabled">{t("prefs_notifications_web_push_default_enabled")}</MenuItem>
|
||||
<MenuItem value="disabled">{t("prefs_notifications_web_push_default_disabled")}</MenuItem>
|
||||
</Select>
|
||||
</FormControl>
|
||||
</Pref>
|
||||
);
|
||||
};
|
||||
|
||||
const Users = () => {
|
||||
const { t } = useTranslation();
|
||||
const [dialogKey, setDialogKey] = useState(0);
|
||||
|
|
|
@ -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 (
|
||||
<Dialog open={props.open} onClose={props.onCancel} fullScreen={fullScreen}>
|
||||
{!showLoginPage && (
|
||||
|
@ -90,7 +75,6 @@ const SubscribeDialog = (props) => {
|
|||
onCancel={props.onCancel}
|
||||
onNeedsLogin={() => setShowLoginPage(true)}
|
||||
onSuccess={handleSuccess}
|
||||
webPushDefaultEnabled={webPushDefaultEnabled}
|
||||
/>
|
||||
)}
|
||||
{showLoginPage && <LoginPage baseUrl={baseUrl} topic={topic} onBack={() => setShowLoginPage(false)} onSuccess={handleSuccess} />}
|
||||
|
@ -115,7 +99,7 @@ const SubscribePage = (props) => {
|
|||
const reserveTopicEnabled =
|
||||
session.exists() && (account?.role === Role.ADMIN || (account?.role === Role.USER && (account?.stats.reservations_remaining || 0) > 0));
|
||||
|
||||
const [backgroundNotificationsEnabled, setBackgroundNotificationsEnabled] = useState(props.webPushDefaultEnabled === "enabled");
|
||||
const [backgroundNotificationsEnabled, setBackgroundNotificationsEnabled] = useState(false);
|
||||
|
||||
const handleBackgroundNotificationsChanged = (e) => {
|
||||
setBackgroundNotificationsEnabled(e.target.checked);
|
||||
|
|
|
@ -169,7 +169,7 @@ export const SubscriptionPopup = (props) => {
|
|||
return (
|
||||
<>
|
||||
<PopupMenu horizontal={placement} anchorEl={props.anchor} open={!!props.anchor} onClose={props.onClose}>
|
||||
<NotificationToggle subscription={subscription} />
|
||||
{notifier.pushPossible() && <NotificationToggle subscription={subscription} />}
|
||||
<Divider />
|
||||
<MenuItem onClick={handleChangeDisplayName}>
|
||||
<ListItemIcon>
|
||||
|
@ -367,18 +367,12 @@ const NotificationToggle = ({ subscription }) => {
|
|||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{notifier.pushPossible() && (
|
||||
<>
|
||||
<MenuItem>
|
||||
{subscription.webPushEnabled === 1 && checkedItem}
|
||||
<ListItemText inset={subscription.webPushEnabled !== 1} onClick={handleToggleBackground}>
|
||||
{t("notification_toggle_background")}
|
||||
</ListItemText>
|
||||
</MenuItem>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue