[build] upgrade eslint to 9.37.0 (#88)
Co-authored-by: tobi <tobi.smethurst@protonmail.com> Reviewed-on: https://codeberg.org/superseriousbusiness/masto-fe-standalone/pulls/88 Co-authored-by: Zoë Bijl <moiety@noreply.codeberg.org> Co-committed-by: Zoë Bijl <moiety@noreply.codeberg.org>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { saveSettings } from './registerer';
|
||||
import { setAlerts } from './setter';
|
||||
import { saveSettings } from "./registerer";
|
||||
import { setAlerts } from "./setter";
|
||||
|
||||
export function changeAlerts(path, value) {
|
||||
return dispatch => {
|
||||
@@ -13,5 +13,5 @@ export {
|
||||
SET_BROWSER_SUPPORT,
|
||||
SET_SUBSCRIPTION,
|
||||
SET_ALERTS,
|
||||
} from './setter';
|
||||
export { register } from './registerer';
|
||||
} from "./setter";
|
||||
export { register } from "./registerer";
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import api from '../../api';
|
||||
import { me } from '../../initial_state';
|
||||
import { pushNotificationsSetting } from '../../settings';
|
||||
import { decode as decodeBase64 } from '../../utils/base64';
|
||||
import api from "../../api";
|
||||
import { me } from "../../initial_state";
|
||||
import { pushNotificationsSetting } from "../../settings";
|
||||
import { decode as decodeBase64 } from "../../utils/base64";
|
||||
|
||||
import { setBrowserSupport, setSubscription, clearSubscription } from './setter';
|
||||
import { setBrowserSupport, setSubscription, clearSubscription } from "./setter";
|
||||
|
||||
// Taken from https://www.npmjs.com/package/web-push
|
||||
const urlBase64ToUint8Array = (base64String) => {
|
||||
const padding = '='.repeat((4 - base64String.length % 4) % 4);
|
||||
const padding = "=".repeat((4 - base64String.length % 4) % 4);
|
||||
const base64 = (base64String + padding)
|
||||
.replace(/-/g, '+')
|
||||
.replace(/_/g, '/');
|
||||
.replace(/-/g, "+")
|
||||
.replace(/_/g, "/");
|
||||
|
||||
return decodeBase64(base64);
|
||||
};
|
||||
|
||||
const getApplicationServerKey = () => document.querySelector('[name="applicationServerKey"]').getAttribute('content');
|
||||
const getApplicationServerKey = () => document.querySelector("[name=\"applicationServerKey\"]").getAttribute("content");
|
||||
|
||||
const getRegistration = () => navigator.serviceWorker.ready;
|
||||
|
||||
@@ -42,11 +42,11 @@ const sendSubscriptionToBackend = (subscription) => {
|
||||
}
|
||||
}
|
||||
|
||||
return api().post('/api/web/push_subscriptions', params).then(response => response.data);
|
||||
return api().post("/api/web/push_subscriptions", params).then(response => response.data);
|
||||
};
|
||||
|
||||
// Last one checks for payload support: https://web-push-book.gauntface.com/chapter-06/01-non-standards-browsers/#no-payload
|
||||
const supportsPushNotifications = ('serviceWorker' in navigator && 'PushManager' in window && 'getKey' in PushSubscription.prototype);
|
||||
const supportsPushNotifications = ("serviceWorker" in navigator && "PushManager" in window && "getKey" in PushSubscription.prototype);
|
||||
|
||||
export function register () {
|
||||
return (dispatch, getState) => {
|
||||
@@ -54,7 +54,7 @@ export function register () {
|
||||
|
||||
if (supportsPushNotifications) {
|
||||
if (!getApplicationServerKey()) {
|
||||
console.error('The VAPID public key is not set. You will not be able to receive Web Push Notifications.');
|
||||
console.error("The VAPID public key is not set. You will not be able to receive Web Push Notifications.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ export function register () {
|
||||
// We have a subscription, check if it is still valid
|
||||
const currentServerKey = (new Uint8Array(subscription.options.applicationServerKey)).toString();
|
||||
const subscriptionServerKey = urlBase64ToUint8Array(getApplicationServerKey()).toString();
|
||||
const serverEndpoint = getState().getIn(['push_notifications', 'subscription', 'endpoint']);
|
||||
const serverEndpoint = getState().getIn(["push_notifications", "subscription", "endpoint"]);
|
||||
|
||||
// If the VAPID public key did not change and the endpoint corresponds
|
||||
// to the endpoint saved in the backend, the subscription is valid
|
||||
@@ -93,10 +93,10 @@ export function register () {
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
if (error.code === 20 && error.name === 'AbortError') {
|
||||
console.warn('Your browser supports Web Push Notifications, but does not seem to implement the VAPID protocol.');
|
||||
} else if (error.code === 5 && error.name === 'InvalidCharacterError') {
|
||||
console.error('The VAPID public key seems to be invalid:', getApplicationServerKey());
|
||||
if (error.code === 20 && error.name === "AbortError") {
|
||||
console.warn("Your browser supports Web Push Notifications, but does not seem to implement the VAPID protocol.");
|
||||
} else if (error.code === 5 && error.name === "InvalidCharacterError") {
|
||||
console.error("The VAPID public key seems to be invalid:", getApplicationServerKey());
|
||||
}
|
||||
|
||||
// Clear alerts and hide UI settings
|
||||
@@ -111,19 +111,19 @@ export function register () {
|
||||
})
|
||||
.catch(console.warn);
|
||||
} else {
|
||||
console.warn('Your browser does not support Web Push Notifications.');
|
||||
console.warn("Your browser does not support Web Push Notifications.");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function saveSettings() {
|
||||
return (_, getState) => {
|
||||
const state = getState().get('push_notifications');
|
||||
const subscription = state.get('subscription');
|
||||
const alerts = state.get('alerts');
|
||||
const state = getState().get("push_notifications");
|
||||
const subscription = state.get("subscription");
|
||||
const alerts = state.get("alerts");
|
||||
const data = { alerts };
|
||||
|
||||
api().put(`/api/web/push_subscriptions/${subscription.get('id')}`, {
|
||||
api().put(`/api/web/push_subscriptions/${subscription.get("id")}`, {
|
||||
data,
|
||||
}).then(() => {
|
||||
if (me) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export const SET_BROWSER_SUPPORT = 'PUSH_NOTIFICATIONS_SET_BROWSER_SUPPORT';
|
||||
export const SET_SUBSCRIPTION = 'PUSH_NOTIFICATIONS_SET_SUBSCRIPTION';
|
||||
export const CLEAR_SUBSCRIPTION = 'PUSH_NOTIFICATIONS_CLEAR_SUBSCRIPTION';
|
||||
export const SET_ALERTS = 'PUSH_NOTIFICATIONS_SET_ALERTS';
|
||||
export const SET_BROWSER_SUPPORT = "PUSH_NOTIFICATIONS_SET_BROWSER_SUPPORT";
|
||||
export const SET_SUBSCRIPTION = "PUSH_NOTIFICATIONS_SET_SUBSCRIPTION";
|
||||
export const CLEAR_SUBSCRIPTION = "PUSH_NOTIFICATIONS_CLEAR_SUBSCRIPTION";
|
||||
export const SET_ALERTS = "PUSH_NOTIFICATIONS_SET_ALERTS";
|
||||
|
||||
export function setBrowserSupport (value) {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user