forked from mirrors/ntfy
1
0
Fork 0

Merge pull request #750 from nimbleghost/web-improvements

Fix suppressed eslint issues
This commit is contained in:
Philipp C. Heckel 2023-05-25 08:03:03 -04:00 committed by GitHub
commit 3101f93d22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 57 additions and 76 deletions

View File

@ -61,9 +61,7 @@ class ConnectionManager {
const { connectionId } = subscription; const { connectionId } = subscription;
const added = !this.connections.get(connectionId); const added = !this.connections.get(connectionId);
if (added) { if (added) {
const { baseUrl } = subscription; const { baseUrl, topic, user } = subscription;
const { topic } = subscription;
const { user } = subscription;
const since = subscription.last; const since = subscription.last;
const connection = new Connection( const connection = new Connection(
connectionId, connectionId,

View File

@ -21,15 +21,16 @@ class Poller {
async pollAll() { async pollAll() {
console.log(`[Poller] Polling all subscriptions`); console.log(`[Poller] Polling all subscriptions`);
const subscriptions = await subscriptionManager.all(); const subscriptions = await subscriptionManager.all();
for (const s of subscriptions) {
try { await Promise.all(
// TODO(eslint): Switch to Promise.all subscriptions.map(async (s) => {
// eslint-disable-next-line no-await-in-loop try {
await this.poll(s); await this.poll(s);
} catch (e) { } catch (e) {
console.log(`[Poller] Error polling ${s.id}`, e); console.log(`[Poller] Error polling ${s.id}`, e);
} }
} })
);
} }
async poll(subscription) { async poll(subscription) {

View File

@ -5,13 +5,12 @@ class SubscriptionManager {
/** All subscriptions, including "new count"; this is a JOIN, see https://dexie.org/docs/API-Reference#joining */ /** All subscriptions, including "new count"; this is a JOIN, see https://dexie.org/docs/API-Reference#joining */
async all() { async all() {
const subscriptions = await db.subscriptions.toArray(); const subscriptions = await db.subscriptions.toArray();
await Promise.all( return Promise.all(
subscriptions.map(async (s) => { subscriptions.map(async (s) => ({
// eslint-disable-next-line no-param-reassign ...s,
s.new = await db.notifications.where({ subscriptionId: s.id, new: 1 }).count(); new: await db.notifications.where({ subscriptionId: s.id, new: 1 }).count(),
}) }))
); );
return subscriptions;
} }
async get(subscriptionId) { async get(subscriptionId) {
@ -40,33 +39,31 @@ class SubscriptionManager {
console.log(`[SubscriptionManager] Syncing subscriptions from remote`, remoteSubscriptions); console.log(`[SubscriptionManager] Syncing subscriptions from remote`, remoteSubscriptions);
// Add remote subscriptions // Add remote subscriptions
const remoteIds = []; // = topicUrl(baseUrl, topic) const remoteIds = await Promise.all(
for (let i = 0; i < remoteSubscriptions.length; i += 1) { remoteSubscriptions.map(async (remote) => {
const remote = remoteSubscriptions[i]; const local = await this.add(remote.base_url, remote.topic, false);
// TODO(eslint): Switch to Promise.all const reservation = remoteReservations?.find((r) => remote.base_url === config.base_url && remote.topic === r.topic) || null;
// eslint-disable-next-line no-await-in-loop
const local = await this.add(remote.base_url, remote.topic, false); await this.update(local.id, {
const reservation = remoteReservations?.find((r) => remote.base_url === config.base_url && remote.topic === r.topic) || null; displayName: remote.display_name, // May be undefined
// TODO(eslint): Switch to Promise.all reservation, // May be null!
// eslint-disable-next-line no-await-in-loop });
await this.update(local.id, {
displayName: remote.display_name, // May be undefined return local.id;
reservation, // May be null! })
}); );
remoteIds.push(local.id);
}
// Remove local subscriptions that do not exist remotely // Remove local subscriptions that do not exist remotely
const localSubscriptions = await db.subscriptions.toArray(); const localSubscriptions = await db.subscriptions.toArray();
for (let i = 0; i < localSubscriptions.length; i += 1) {
const local = localSubscriptions[i]; await Promise.all(
const remoteExists = remoteIds.includes(local.id); localSubscriptions.map(async (local) => {
if (!local.internal && !remoteExists) { const remoteExists = remoteIds.includes(local.id);
// TODO(eslint): Switch to Promise.all if (!local.internal && !remoteExists) {
// eslint-disable-next-line no-await-in-loop await this.remove(local.id);
await this.remove(local.id); }
} })
} );
} }
async updateState(subscriptionId, state) { async updateState(subscriptionId, state) {
@ -108,9 +105,12 @@ class SubscriptionManager {
return false; return false;
} }
try { try {
// eslint-disable-next-line no-param-reassign await db.notifications.add({
notification.new = 1; // New marker (used for bubble indicator); cannot be boolean; Dexie index limitation ...notification,
await db.notifications.add({ ...notification, subscriptionId }); // FIXME consider put() for double tab subscriptionId,
// New marker (used for bubble indicator); cannot be boolean; Dexie index limitation
new: 1,
}); // FIXME consider put() for double tab
await db.subscriptions.update(subscriptionId, { await db.subscriptions.update(subscriptionId, {
last: notification.id, last: notification.id,
}); });

View File

@ -118,10 +118,10 @@ export const maybeWithBearerAuth = (headers, token) => {
export const withBasicAuth = (headers, username, password) => ({ ...headers, Authorization: basicAuth(username, password) }); export const withBasicAuth = (headers, username, password) => ({ ...headers, Authorization: basicAuth(username, password) });
export const maybeWithAuth = (headers, user) => { export const maybeWithAuth = (headers, user) => {
if (user && user.password) { if (user?.password) {
return withBasicAuth(headers, user.username, user.password); return withBasicAuth(headers, user.username, user.password);
} }
if (user && user.token) { if (user?.token) {
return withBearerAuth(headers, user.token); return withBearerAuth(headers, user.token);
} }
return headers; return headers;
@ -139,17 +139,14 @@ export const maybeAppendActionErrors = (message, notification) => {
}; };
export const shuffle = (arr) => { export const shuffle = (arr) => {
let j; const returnArr = [...arr];
let x;
for (let index = arr.length - 1; index > 0; index -= 1) { for (let index = returnArr.length - 1; index > 0; index -= 1) {
j = Math.floor(Math.random() * (index + 1)); const j = Math.floor(Math.random() * (index + 1));
x = arr[index]; [returnArr[index], returnArr[j]] = [returnArr[j], returnArr[index]];
// eslint-disable-next-line no-param-reassign
arr[index] = arr[j];
// eslint-disable-next-line no-param-reassign
arr[j] = x;
} }
return arr;
return returnArr;
}; };
export const splitNoEmpty = (s, delimiter) => export const splitNoEmpty = (s, delimiter) =>

View File

@ -127,17 +127,7 @@ const Category = (props) => {
); );
}; };
const emojiMatches = (emoji, words) => { const emojiMatches = (emoji, words) => words.length === 0 || words.some((word) => emoji.searchBase.includes(word));
if (words.length === 0) {
return true;
}
for (const word of words) {
if (emoji.searchBase.indexOf(word) === -1) {
return false;
}
}
return true;
};
const Emoji = (props) => { const Emoji = (props) => {
const { emoji } = props; const { emoji } = props;

View File

@ -436,15 +436,10 @@ const ACTION_LABEL_SUFFIX = {
}; };
const updateActionStatus = (notification, action, progress, error) => { const updateActionStatus = (notification, action, progress, error) => {
// TODO(eslint): Fix by spreading? Does the code depend on the change, though? subscriptionManager.updateNotification({
// eslint-disable-next-line no-param-reassign ...notification,
notification.actions = notification.actions.map((a) => { actions: notification.actions.map((a) => (a.id === action.id ? { ...a, progress, error } : a)),
if (a.id !== action.id) {
return a;
}
return { ...a, progress, error };
}); });
subscriptionManager.updateNotification(notification);
}; };
const performHttpAction = async (notification, action) => { const performHttpAction = async (notification, action) => {