1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2024-11-26 13:19:15 +01:00

Remove webPushDefaultEnabled

This commit is contained in:
nimbleghost 2023-06-07 20:36:20 +02:00
parent 46f34ca1e3
commit 03aa67ed68
6 changed files with 8 additions and 80 deletions

View file

@ -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_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_topic_label": "Topic",
"prefs_reservations_dialog_access_label": "Access", "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_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_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.", "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.",

View file

@ -31,15 +31,6 @@ class Prefs {
const deleteAfter = await this.db.prefs.get("deleteAfter"); const deleteAfter = await this.db.prefs.get("deleteAfter");
return deleteAfter ? Number(deleteAfter.value) : 604800; // Default is one week 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()); const prefs = new Prefs(getDb());

View file

@ -78,16 +78,12 @@ class SubscriptionManager {
async syncFromRemote(remoteSubscriptions, remoteReservations) { async syncFromRemote(remoteSubscriptions, remoteReservations) {
console.log(`[SubscriptionManager] Syncing subscriptions from remote`, remoteSubscriptions); console.log(`[SubscriptionManager] Syncing subscriptions from remote`, remoteSubscriptions);
const webPushEnabled = (await prefs.webPushDefaultEnabled()) === "enabled";
// Add remote subscriptions // Add remote subscriptions
const remoteIds = await Promise.all( const remoteIds = await Promise.all(
remoteSubscriptions.map(async (remote) => { remoteSubscriptions.map(async (remote) => {
const reservation = remoteReservations?.find((r) => remote.base_url === config.base_url && remote.topic === r.topic) || null; 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, { 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 displayName: remote.display_name, // May be undefined
reservation, // May be null! reservation, // May be null!
}); });

View file

@ -48,7 +48,6 @@ import { PermissionDenyAll, PermissionRead, PermissionReadWrite, PermissionWrite
import { ReserveAddDialog, ReserveDeleteDialog, ReserveEditDialog } from "./ReserveDialogs"; import { ReserveAddDialog, ReserveDeleteDialog, ReserveEditDialog } from "./ReserveDialogs";
import { UnauthorizedError } from "../app/errors"; import { UnauthorizedError } from "../app/errors";
import { subscribeTopic } from "./SubscribeDialog"; import { subscribeTopic } from "./SubscribeDialog";
import notifier from "../app/Notifier";
const maybeUpdateAccountSettings = async (payload) => { const maybeUpdateAccountSettings = async (payload) => {
if (!session.exists()) { if (!session.exists()) {
@ -86,7 +85,6 @@ const Notifications = () => {
<Sound /> <Sound />
<MinPriority /> <MinPriority />
<DeleteAfter /> <DeleteAfter />
{notifier.pushPossible() && <WebPushDefaultEnabled />}
</PrefGroup> </PrefGroup>
</Card> </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 Users = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const [dialogKey, setDialogKey] = useState(0); const [dialogKey, setDialogKey] = useState(0);

View file

@ -14,7 +14,6 @@ import {
Switch, Switch,
} from "@mui/material"; } from "@mui/material";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useLiveQuery } from "dexie-react-hooks";
import theme from "./theme"; import theme from "./theme";
import api from "../app/Api"; import api from "../app/Api";
import { randomAlphanumericString, topicUrl, validTopic, validUrl } from "../app/utils"; import { randomAlphanumericString, topicUrl, validTopic, validUrl } from "../app/utils";
@ -30,7 +29,6 @@ import { AccountContext } from "./App";
import { TopicReservedError, UnauthorizedError } from "../app/errors"; import { TopicReservedError, UnauthorizedError } from "../app/errors";
import { ReserveLimitChip } from "./SubscriptionPopup"; import { ReserveLimitChip } from "./SubscriptionPopup";
import notifier from "../app/Notifier"; import notifier from "../app/Notifier";
import prefs from "../app/Prefs";
const publicBaseUrl = "https://ntfy.sh"; const publicBaseUrl = "https://ntfy.sh";
@ -55,8 +53,6 @@ const SubscribeDialog = (props) => {
const [showLoginPage, setShowLoginPage] = useState(false); const [showLoginPage, setShowLoginPage] = useState(false);
const fullScreen = useMediaQuery(theme.breakpoints.down("sm")); const fullScreen = useMediaQuery(theme.breakpoints.down("sm"));
const webPushDefaultEnabled = useLiveQuery(async () => prefs.webPushDefaultEnabled());
const handleSuccess = async (webPushEnabled) => { const handleSuccess = async (webPushEnabled) => {
console.log(`[SubscribeDialog] Subscribing to topic ${topic}`); console.log(`[SubscribeDialog] Subscribing to topic ${topic}`);
const actualBaseUrl = baseUrl || config.base_url; const actualBaseUrl = baseUrl || config.base_url;
@ -64,20 +60,9 @@ const SubscribeDialog = (props) => {
webPushEnabled, webPushEnabled,
}); });
poller.pollInBackground(subscription); // Dangle! 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); props.onSuccess(subscription);
}; };
// wait for liveQuery load
if (webPushDefaultEnabled === undefined) {
return <></>;
}
return ( return (
<Dialog open={props.open} onClose={props.onCancel} fullScreen={fullScreen}> <Dialog open={props.open} onClose={props.onCancel} fullScreen={fullScreen}>
{!showLoginPage && ( {!showLoginPage && (
@ -90,7 +75,6 @@ const SubscribeDialog = (props) => {
onCancel={props.onCancel} onCancel={props.onCancel}
onNeedsLogin={() => setShowLoginPage(true)} onNeedsLogin={() => setShowLoginPage(true)}
onSuccess={handleSuccess} onSuccess={handleSuccess}
webPushDefaultEnabled={webPushDefaultEnabled}
/> />
)} )}
{showLoginPage && <LoginPage baseUrl={baseUrl} topic={topic} onBack={() => setShowLoginPage(false)} onSuccess={handleSuccess} />} {showLoginPage && <LoginPage baseUrl={baseUrl} topic={topic} onBack={() => setShowLoginPage(false)} onSuccess={handleSuccess} />}
@ -115,7 +99,7 @@ const SubscribePage = (props) => {
const reserveTopicEnabled = const reserveTopicEnabled =
session.exists() && (account?.role === Role.ADMIN || (account?.role === Role.USER && (account?.stats.reservations_remaining || 0) > 0)); 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) => { const handleBackgroundNotificationsChanged = (e) => {
setBackgroundNotificationsEnabled(e.target.checked); setBackgroundNotificationsEnabled(e.target.checked);

View file

@ -169,7 +169,7 @@ export const SubscriptionPopup = (props) => {
return ( return (
<> <>
<PopupMenu horizontal={placement} anchorEl={props.anchor} open={!!props.anchor} onClose={props.onClose}> <PopupMenu horizontal={placement} anchorEl={props.anchor} open={!!props.anchor} onClose={props.onClose}>
<NotificationToggle subscription={subscription} /> {notifier.pushPossible() && <NotificationToggle subscription={subscription} />}
<Divider /> <Divider />
<MenuItem onClick={handleChangeDisplayName}> <MenuItem onClick={handleChangeDisplayName}>
<ListItemIcon> <ListItemIcon>
@ -367,18 +367,12 @@ const NotificationToggle = ({ subscription }) => {
} }
return ( return (
<> <MenuItem>
{notifier.pushPossible() && ( {subscription.webPushEnabled === 1 && checkedItem}
<> <ListItemText inset={subscription.webPushEnabled !== 1} onClick={handleToggleBackground}>
<MenuItem> {t("notification_toggle_background")}
{subscription.webPushEnabled === 1 && checkedItem} </ListItemText>
<ListItemText inset={subscription.webPushEnabled !== 1} onClick={handleToggleBackground}> </MenuItem>
{t("notification_toggle_background")}
</ListItemText>
</MenuItem>
</>
)}
</>
); );
}; };